populate-dev-server.ts 1.6 KB

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