next-rest-framework
Version:
Next REST Framework - write type-safe, self-documenting REST APIs in Next.js
39 lines (38 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const wait_on_1 = __importDefault(require("wait-on"));
const child_process_1 = require("child_process");
const program = new commander_1.Command();
program
.command('generate')
.option('--port <string>', 'The port in which you want to run your Next.js server during the generation. Defaults to 3000.')
.option('--path <string>', 'Path to the API endpoint that triggers the OpenAPI generation. Defaults to `/api`.')
.option('--timeout <string>', 'The timeout for waiting on the Next.js server to start. Defaults to 10000ms.')
.description('Run the OpenAPI generation from your Next REST Framework client.')
.action(async (options) => {
const port = options.port ?? '3000';
const path = options.path ?? '/api';
const timeout = options.timeout ?? 10000;
const server = (0, child_process_1.spawn)('npx', ['next', 'dev', '-p', port], {
stdio: 'inherit'
});
try {
await (0, wait_on_1.default)({
resources: [`http-get://localhost:${port}${path}`],
timeout
});
server.kill();
}
catch (e) {
console.error(chalk_1.default.red(`Error while generating the API spec: ${e}`));
server.kill();
process.exit(1);
}
});
program.parse(process.argv);