vendure-cli.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. import program from 'commander';
  3. import path from 'path';
  4. import prompts from 'prompts';
  5. import { logColored } from './cli-utils';
  6. import { init } from './init';
  7. import { importProducts, populate } from './populate';
  8. // tslint:disable-next-line:no-var-requires
  9. const version = require('../../package.json').version;
  10. // tslint:disable:no-console
  11. logColored(`
  12. _
  13. | |
  14. __ _____ _ __ __| |_ _ _ __ ___
  15. \\ \\ / / _ \\ '_ \\ / _\` | | | | '__/ _ \\
  16. \\ V / __/ | | | (_| | |_| | | | __/
  17. \\_/ \\___|_| |_|\\__,_|\\__,_|_| \\___|
  18. `);
  19. program.version(`Vendure CLI v${version}`, '-v --version').name('vendure');
  20. program
  21. .command('init')
  22. .description('Initialize a new Vendure server application')
  23. .action(async (command: any) => {
  24. const indexFile = await init();
  25. const answer = await prompts({
  26. type: 'toggle',
  27. name: 'populate',
  28. message: 'Populate the database with some data to get you started (recommended)?',
  29. active: 'yes',
  30. inactive: 'no',
  31. initial: true as any,
  32. });
  33. if (answer.populate) {
  34. await populate();
  35. }
  36. logColored(`\nAll done! Run "${indexFile}" to start the server.`);
  37. });
  38. program
  39. .command('populate')
  40. .description('Populate a new Vendure server instance with some initial data')
  41. .action(async () => {
  42. await populate();
  43. });
  44. program
  45. .command('import-products <csvFile>')
  46. .option('-l, --language', 'Specify ISO 639-1 language code, e.g. "de", "es". Defaults to "en"')
  47. .description('Import product data from the specified csv file')
  48. .action(async (csvPath, command) => {
  49. const filePath = path.join(process.cwd(), csvPath);
  50. await importProducts(filePath, command.language);
  51. });
  52. program.parse(process.argv);
  53. if (!process.argv.slice(2).length) {
  54. program.help();
  55. }