populate-dev-server.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 { clearAllTables, populateCustomers } from '@vendure/testing';
  6. import path from 'path';
  7. import { initialData } from '../core/mock-data/data-sources/initial-data';
  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 as any, true)
  30. .then(() =>
  31. populate(
  32. () => bootstrap(populateConfig),
  33. initialData,
  34. path.join(__dirname, '../create/assets/products.csv'),
  35. ),
  36. )
  37. .then(async app => {
  38. console.log('populating customers...');
  39. await populateCustomers(10, populateConfig as any, true);
  40. return app.close();
  41. })
  42. .then(
  43. () => process.exit(0),
  44. err => {
  45. console.log(err);
  46. process.exit(1);
  47. },
  48. );
  49. }