Skip to content

Commit

Permalink
add @routes-gen/solid-start driver (#29)
Browse files Browse the repository at this point in the history
* add @routes-gen/solid-start

* move patch-package dependency to the root

* publish script without solid-start
But notice we need to merge the patch to solid-start or do some patching

* ready to publish under @nirtamir2/routes-gen-solid-start

* use @nirtamir2/solid-start and use publish script without removing solid-start

* 0.0.2

* 0.0.3

* upgrade to solid-start 0.2.10

* v0.0.4

* 0.0.5

* change package name

* remove useless path

* filter * routes

* v0.0.6

* Revert "v0.0.6"

This reverts commit 85bb3ed.

* fix typo

* add solid-start as peer dependency
  • Loading branch information
nirtamir2 authored Jan 17, 2023
1 parent 0b3945b commit 68625dc
Show file tree
Hide file tree
Showing 8 changed files with 1,066 additions and 30 deletions.
1 change: 1 addition & 0 deletions packages/routes-gen-solid-start/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @routes-gen/solid-start
17 changes: 17 additions & 0 deletions packages/routes-gen-solid-start/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @routes-gen/solid-start

This package is a [**routes-gen**](https://github.com/sandulat/routes-gen) driver for [SolidStart](https://github.com/solidjs/solid-start).

## Installation

```
yarn add routes-gen @routes-gen/solid-start
```

## Usage

```
yarn routes-gen -d @routes-gen/solid-start
```

By default, it exports the routes to: `${appDirectory}/routes.d.ts`.
31 changes: 31 additions & 0 deletions packages/routes-gen-solid-start/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@routes-gen/routes-gen-solid-start",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"repository": {
"url": "https://github.com/sandulat/routes-gen",
"directory": "packages/routes-gen-solid-start"
},
"scripts": {
"build": "rollup -c",
"dev": "rollup -c --watch",
"test": "jest"
},
"files": [
"dist/**",
"package.json",
"README.md"
],
"dependencies": {
"routes-gen": "*",
"solid-start": "^0.2.10"
},
"devDependencies": {
"config": "*"
},
"peerDependencies": {
"solid-start": "^0.2.10"
}
}
3 changes: 3 additions & 0 deletions packages/routes-gen-solid-start/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = require("config/rollup")({
input: "src/index.ts",
});
49 changes: 49 additions & 0 deletions packages/routes-gen-solid-start/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { exec } from "child_process";
import { Driver } from "routes-gen/src";

const appDirectory = "./src";
export const defaultOutputPath: Driver["defaultOutputPath"] = `${appDirectory}/routes.d.ts`;
export const watchPaths: Driver["watchPaths"] = async () => [
`${appDirectory}/routes/**/*.{ts,tsx,js,jsx}`,
];

type SolidStartRouteData = {
id: string;
path: string;
componentPath: string;
dataPath: string;
};
export const routes: Driver["routes"] = async () => {
const parsedRoutes = await new Promise<Array<SolidStartRouteData>>(
async (resolve) => {
exec(`npx solid-start routes`, (error, stdout) => {
try {
if (error != null) {
console.error("error", error);
resolve([]);
} else {
const routes = JSON.parse(stdout) as Array<SolidStartRouteData>;
const filteredRoutes = routes.filter((route) => {
return !route.path.includes("*");
});
resolve(filteredRoutes);
}
} catch (error) {
resolve([]);
}
});
}
);
if (parsedRoutes.length === 0) {
throw new Error(
'Couldn\'t parse routes. This may be due to breaking changes in "solid-start".'
);
}
return parsedRoutes;
};

module.exports = {
defaultOutputPath,
watchPaths,
routes,
};
5 changes: 5 additions & 0 deletions packages/routes-gen-solid-start/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "config/tsconfig.json",
"include": ["./src"],
"exclude": ["dist", "node_modules"]
}
21 changes: 21 additions & 0 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const routesGenJson = fs.readJSONSync(routesGenJsonPath);
const remixDriverJsonPath = "packages/routes-gen-remix/package.json";
const remixDriverJson = fs.readJSONSync(remixDriverJsonPath);

const solidStartDriverJsonPath = "packages/routes-gen-solid-start/package.json";
const solidStartDriverJson = fs.readJSONSync(solidStartDriverJsonPath);

const configJson = fs.readJSONSync("packages/config/package.json");

const removeDependencies = (sourceDependencies, removeDependencies) =>
Expand Down Expand Up @@ -49,10 +52,28 @@ fs.writeJSONSync(
{ spaces: 2 }
);

fs.writeJSONSync(
solidStartDriverJsonPath,
{
...solidStartDriverJson,
devDependencies: removeDependencies(solidStartDriverJson.devDependencies, [
configJson.name,
"solid-start",
]),
dependencies: {
...solidStartDriverJson.dependencies,
"routes-gen": `^${routesGenJson.version}`,
},
},
{ spaces: 2 }
);

execSync("yarn changeset publish");

fs.writeJSONSync(routesGenJsonPath, routesGenJson, { spaces: 2 });

fs.writeJSONSync(remixDriverJsonPath, remixDriverJson, { spaces: 2 });

fs.writeJSONSync(solidStartDriverJsonPath, solidStartDriverJson, { spaces: 2 });

execSync("rimraf packages/routes-gen/README.MD");
Loading

0 comments on commit 68625dc

Please sign in to comment.