implement watch command
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
*.md
|
||||
*.mustache
|
||||
apis/baseapi.ts
|
||||
apis/exception.ts
|
||||
auth/*
|
||||
http/*
|
||||
middleware.ts
|
||||
servers.ts
|
||||
util.ts
|
||||
configuration.ts
|
||||
rxjsStub.ts
|
||||
.gitignore
|
||||
apis/*.ts
|
||||
!apis/*.client.ts
|
||||
models/*.ts
|
||||
!models/*.model.ts
|
||||
!index.ts
|
||||
!**/index.ts
|
||||
types/ObjectParamAPI.ts
|
||||
types/ObservableAPI.ts
|
||||
types/PromiseAPI.ts
|
||||
git_push.sh
|
||||
package.json
|
||||
tsconfig.json
|
||||
@@ -62,7 +62,7 @@
|
||||
"@stoplight/types": "^14.0.0",
|
||||
"@useoptic/openapi-utilities": "^0.55.0",
|
||||
"chalk": "^4.0.0",
|
||||
"chokidar": "^3.6.0",
|
||||
"chokidar": "^3.5.3",
|
||||
"codeowners-utils": "^1.0.2",
|
||||
"command-exists": "^1.2.9",
|
||||
"commander": "^12.0.0",
|
||||
|
||||
@@ -29,29 +29,43 @@ export async function command(opts: OptionValues) {
|
||||
}
|
||||
|
||||
const sharedCommand = async (abortSignal?: AbortController) => {
|
||||
const promises = [];
|
||||
if (opts.clientPackage) {
|
||||
await generateClient(
|
||||
opts.clientPackage,
|
||||
opts.clientAdditionalProperties,
|
||||
abortSignal,
|
||||
promises.push(
|
||||
generateClient(
|
||||
opts.clientPackage,
|
||||
opts.clientAdditionalProperties,
|
||||
abortSignal,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (opts.server) {
|
||||
await generateServer(abortSignal);
|
||||
promises.push(generateServer(abortSignal));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
};
|
||||
|
||||
if (opts.watch) {
|
||||
try {
|
||||
const resolvedOpenapiPath = await getPathToCurrentOpenApiSpec();
|
||||
let abortController = new AbortController();
|
||||
chokidar.watch(resolvedOpenapiPath).on('change', async () => {
|
||||
console.log('detected changes');
|
||||
const watcher = chokidar.watch(resolvedOpenapiPath);
|
||||
watcher.on('change', () => {
|
||||
console.log('Detected changes! Regenerating...');
|
||||
abortController.abort();
|
||||
await sharedCommand(abortController);
|
||||
abortController = new AbortController();
|
||||
sharedCommand(abortController);
|
||||
});
|
||||
watcher.on('error', error => {
|
||||
console.error('Error happened', error);
|
||||
});
|
||||
|
||||
watcher.on('ready', async () => {
|
||||
console.log(
|
||||
'Watching for changes in OpenAPI spec. Press Ctrl+C to stop.',
|
||||
);
|
||||
await sharedCommand();
|
||||
});
|
||||
await sharedCommand();
|
||||
await new Promise(() => {});
|
||||
} catch (err) {
|
||||
console.error(chalk.red('Error: ', err));
|
||||
|
||||
Reference in New Issue
Block a user