populate-dev-server.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ))
  31. .then(async app => {
  32. console.log('populating customers...');
  33. await populateCustomers(10, populateConfig as any, true);
  34. return app.close();
  35. })
  36. .then(
  37. () => process.exit(0),
  38. err => {
  39. console.log(err);
  40. process.exit(1);
  41. },
  42. );
  43. }