Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serve.ts 1.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Argv } from 'yargs';
  2. import { resolve } from 'path';
  3. const DEFAULT_PORT = 3000 as const;
  4. const buildApp = async () => {
  5. process.stdout.write('Building app...\n');
  6. const cwd = resolve(__dirname, '..', '..', '..');
  7. const nextBinPath = resolve(__dirname, '..', '..', '..', 'node_modules', '.bin', 'next');
  8. const { execa } = await import('execa');
  9. await execa(nextBinPath, ['build'], {
  10. stdout: 'inherit',
  11. stderr: 'inherit',
  12. cwd,
  13. });
  14. process.stdout.write('done\n');
  15. };
  16. const serveApp = async (port: number) => {
  17. process.stdout.write(`Using port: ${port}...\n`);
  18. process.stdout.write('Serving app...\n');
  19. const cwd = resolve(__dirname, '..', '..', '..');
  20. const nextBinPath = resolve(__dirname, '..', '..', '..', 'node_modules', '.bin', 'next');
  21. const { execa } = await import('execa');
  22. await execa(nextBinPath, ['start', '-p', port.toString()], {
  23. stdout: 'inherit',
  24. stderr: 'inherit',
  25. cwd,
  26. });
  27. };
  28. export const description = 'Start a development server' as const;
  29. export enum ServeReturnCode {
  30. SUCCESS = 0,
  31. }
  32. export interface ServeArgs {
  33. port?: number;
  34. subcommands?: string[];
  35. }
  36. export const builder = (yargs: Argv) => yargs
  37. .option('port', {
  38. type: 'number',
  39. default: DEFAULT_PORT,
  40. alias: 'p',
  41. });
  42. const serve = async (args: ServeArgs) => {
  43. const {
  44. port = DEFAULT_PORT,
  45. } = args;
  46. await buildApp();
  47. await serveApp(port);
  48. return ServeReturnCode.SUCCESS;
  49. };
  50. export default serve;