populate-dev-server.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { bootstrap, VendureConfig } from '@vendure/core';
  2. import { populate } from '@vendure/core/cli/populate';
  3. import path from 'path';
  4. import { clearAllTables } from '../core/mock-data/clear-all-tables';
  5. import { populateCustomers } from '../core/mock-data/populate-customers';
  6. import { devConfig } from './dev-config';
  7. // tslint:disable:no-console
  8. /**
  9. * A CLI script which populates the dev database with deterministic random data.
  10. */
  11. if (require.main === module) {
  12. // Running from command line
  13. const populateConfig: VendureConfig = {
  14. ...devConfig as any,
  15. authOptions: {
  16. tokenMethod: 'bearer',
  17. },
  18. importExportOptions: {
  19. importAssetsDir: path.join(__dirname, '../core/mock-data/assets'),
  20. },
  21. customFields: {},
  22. };
  23. clearAllTables(populateConfig.dbConnectionOptions, true)
  24. .then(() => populate(() => bootstrap(populateConfig),
  25. path.join(__dirname, '../core/dist/cli/assets/initial-data.json'),
  26. path.join(__dirname, '../core/dist/cli/assets/products.csv'),
  27. path.join(__dirname, '../core/mock-data/assets'),
  28. ))
  29. .then(async app => {
  30. console.log('populating customers...');
  31. await populateCustomers(10, populateConfig as any, true);
  32. return app.close();
  33. })
  34. .then(
  35. () => process.exit(0),
  36. err => {
  37. console.log(err);
  38. process.exit(1);
  39. },
  40. );
  41. }