Skip to content

Commit

Permalink
Add CLI debug logging option (#102)
Browse files Browse the repository at this point in the history
This adds a debug option for the CLI commands
to get the build logs from the next build step.
  • Loading branch information
blomqma authored Nov 12, 2023
1 parent d0ce834 commit 7ddec1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
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

2 comments on commit 7ddec1c

@vercel
Copy link

@vercel vercel bot commented on 7ddec1c Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-rest-framework – ./docs

next-rest-framework-blomqma.vercel.app
next-rest-framework.vercel.app
next-rest-framework-git-main-blomqma.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7ddec1c Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-rest-framework-demo – ./apps/example

next-rest-framework-demo.vercel.app
next-rest-framework-demo-blomqma.vercel.app
next-rest-framework-demo-git-main-blomqma.vercel.app

Please sign in to comment.