populate-dev-server.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. workerOptions: {
  25. runInMainProcess: true,
  26. },
  27. customFields: {},
  28. };
  29. clearAllTables(populateConfig, true)
  30. .then(() => populate(() => bootstrap(populateConfig),
  31. path.join(__dirname, '../create/assets/initial-data.json'),
  32. path.join(__dirname, '../create/assets/products.csv'),
  33. ))
  34. .then(async app => {
  35. console.log('populating customers...');
  36. await populateCustomers(10, populateConfig as any, true);
  37. return app.close();
  38. })
  39. .then(
  40. () => process.exit(0),
  41. err => {
  42. console.log(err);
  43. process.exit(1);
  44. },
  45. );
  46. }