Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI debug logging option #102

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"prebuild": "cd ../.. && pnpm build && cd apps/example",
"dev": "pnpm prebuild && next dev",
"build": "pnpm prebuild && next build",
"generate": "pnpm prebuild && next-rest-framework generate",
"validate": "pnpm prebuild && next-rest-framework validate",
"generate": "pnpm prebuild && next-rest-framework generate --debug=true",
"validate": "pnpm prebuild && next-rest-framework validate --debug=true",
"start": "next start",
"type-check": "tsc --noEmit"
},
Expand Down
20 changes: 17 additions & 3 deletions packages/next-rest-framework/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,24 @@ program
'--configPath <string>',
'In case you have multiple docs handlers with different configurations, you can specify which configuration you want to use by providing the path to the API. Example: `/api/my-configuration`.'
)
.option(
'--debug <boolean>',
'Inherit and display logs from the `next build` command. Defaults to `false`.'
)
.description('Generate an OpenAPI spec with Next REST Framework.')
.action(async (options) => {
const skipBuild: boolean = options.skipBuild ?? false;
const distDir: string = options.distDir ?? '.next';
const timeout: number = options.timeout ?? 60000;
const configPath: string = options.configPath ?? '';
const debug: boolean = options.debug ?? false;

console.log(chalk.yellowBright('Generating OpenAPI spec...'));

if (!skipBuild) {
const server = spawn('npx', ['next', 'build']);
const server = spawn('npx', ['next', 'build'], {
stdio: debug ? 'inherit' : 'ignore'
});

try {
await waitOn({
Expand Down Expand Up @@ -409,17 +416,25 @@ program
'--configPath <string>',
'In case you have multiple docs handlers with different configurations, you can specify which configuration you want to use by providing the path to the API. Example: `/api/my-configuration`.'
)
.option(
'--debug <boolean>',
'Inherit and display logs from the `next build` command. Defaults to `false`.'
)
.description('Validate an OpenAPI spec with Next REST Framework.')
.action(async (options) => {
const skipBuild: boolean = options.skipBuild ?? false;
const distDir: string = options.distDir ?? '.next';
const timeout: number = options.timeout ?? 60000;
const server = spawn('npx', ['next', 'build']);
const configPath: string = options.configPath ?? '';
const debug: boolean = options.debug ?? false;

console.log(chalk.yellowBright('Validating OpenAPI spec...'));

if (!skipBuild) {
const server = spawn('npx', ['next', 'build'], {
stdio: debug ? 'inherit' : 'ignore'
});

try {
await waitOn({
resources: [join(process.cwd(), distDir, 'BUILD_ID')],
Expand Down Expand Up @@ -453,7 +468,6 @@ program
}
} catch (e) {
console.error(e);
server.kill();
process.exit(1);
}
}
Expand Down