Skip to content

Commit 8e5f629

Browse files
authored
feat: implemented post-export hook in routes-gen (#18)
* feat: implemented post-export hook in routes-gen * chore: added post-export to changelog
1 parent c41ff6d commit 8e5f629

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ export default function Product() {
8282

8383
## CLI Options
8484

85-
| Option | Alias | Description |
86-
|-----------|-------|---------------------------------------|
87-
| --help | | Print the help message and exit |
88-
| --version | -v | Print the CLI version and exit |
89-
| --output | -o | The path for routes export |
90-
| --driver | -d | The driver of handling routes parsing |
91-
| --watch | -w | Watch for changes |
85+
| Option | Alias | Description |
86+
|-----------------|-------|---------------------------------------|
87+
| --help | | Print the help message and exit |
88+
| --version | -v | Print the CLI version and exit |
89+
| --output | -o | The path for routes export |
90+
| --driver | -d | The driver of handling routes parsing |
91+
| --watch | -w | Watch for changes |
92+
| --post-export | | Execute a command after routes export |
9293

9394
## Writing Your Driver
9495

@@ -113,7 +114,7 @@ module.exports = {
113114

114115
// The paths to be watched for changes. Must return and array of relative paths.
115116
watchPaths: async () => {
116-
return ["/my-routes"];
117+
return ["/my-routes/**/*.{ts,tsx,js,jsx}"];
117118
},
118119
}
119120
```

packages/routes-gen/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# routes-gen
22

3+
## 0.5.0
4+
5+
### Minor Changes
6+
7+
- Implemented post-export hook.
8+
39
## 0.4.0
410

511
### Minor Changes

packages/routes-gen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "routes-gen",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"license": "MIT",

packages/routes-gen/src/cli.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from "child_process";
12
import chokidar from "chokidar";
23
import meow from "meow";
34
import * as path from "path";
@@ -21,6 +22,7 @@ Options
2122
--output, -o The path for routes export
2223
--driver, -d The driver of handling routes parsing
2324
--watch, -w Watch for changes
25+
--post-export Execute a command after routes export
2426
2527
Official Drivers
2628
${driversHelpText}
@@ -46,6 +48,9 @@ const cli = meow(helpText, {
4648
type: "boolean",
4749
alias: "w",
4850
},
51+
postExport: {
52+
type: "string",
53+
},
4954
},
5055
});
5156

@@ -65,6 +70,18 @@ const markAsFailed = (message: string) => {
6570
process.exit(1);
6671
};
6772

73+
const processRoutes: typeof exportRoutes = (...args) => {
74+
const result = exportRoutes(...args);
75+
76+
if (typeof cli.flags.postExport === "undefined") {
77+
return;
78+
}
79+
80+
execSync(cli.flags.postExport, { stdio: "inherit" });
81+
82+
return result;
83+
};
84+
6885
const getRoutes = async (driver: Driver) => {
6986
const routes = await driver.routes();
7087

@@ -121,7 +138,7 @@ const bootstrap = async () => {
121138

122139
const outputPath = cli.flags.output ?? driver.defaultOutputPath;
123140

124-
exportRoutes({
141+
processRoutes({
125142
routes: await getRoutes(driver),
126143
outputPath,
127144
});
@@ -160,7 +177,7 @@ const bootstrap = async () => {
160177
}
161178
)
162179
.on("all", async () =>
163-
exportRoutes({
180+
processRoutes({
164181
routes: await getRoutes(driver!),
165182
outputPath,
166183
})

0 commit comments

Comments
 (0)