vendure-cli.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env node
  2. import * as program from 'commander';
  3. import * as prompts from 'prompts';
  4. import { logColored } from './cli-utils';
  5. import { init } from './init';
  6. import { populate } from './populate';
  7. // tslint:disable-next-line:no-var-requires
  8. const version = require('../../package.json').version;
  9. // tslint:disable:no-console
  10. logColored(`
  11. _
  12. | |
  13. __ _____ _ __ __| |_ _ _ __ ___
  14. \\ \\ / / _ \\ '_ \\ / _\` | | | | '__/ _ \\
  15. \\ V / __/ | | | (_| | |_| | | | __/
  16. \\_/ \\___|_| |_|\\__,_|\\__,_|_| \\___|
  17. `);
  18. program.version(`Vendure CLI v${version}`, '-v --version').name('vendure');
  19. program
  20. .command('init')
  21. .description('Initialize a new Vendure server application')
  22. .action(async (command: any) => {
  23. const indexFile = await init();
  24. const answer = await prompts({
  25. type: 'toggle',
  26. name: 'populate',
  27. message: 'Populate the database with some data to get you started (recommended)?',
  28. active: 'yes',
  29. inactive: 'no',
  30. initial: true as any,
  31. });
  32. if (answer.populate) {
  33. await populate();
  34. }
  35. logColored(`\nAll done! Run "${indexFile}" to start the server.`);
  36. });
  37. program
  38. .command('populate')
  39. .description('Populate a new Vendure server instance with some initial data')
  40. .action(async () => {
  41. await populate();
  42. });
  43. program.parse(process.argv);
  44. if (!process.argv.slice(2).length) {
  45. program.help();
  46. }