populate-dev-server.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // tslint:disable-next-line:no-reference
  2. /// <reference path="../core/typings.d.ts" />
  3. import { bootstrap, defaultConfig, mergeConfig } from '@vendure/core';
  4. import { populate } from '@vendure/core/cli';
  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 = mergeConfig(
  16. defaultConfig,
  17. mergeConfig(devConfig, {
  18. authOptions: {
  19. tokenMethod: 'bearer',
  20. requireVerification: false,
  21. },
  22. importExportOptions: {
  23. importAssetsDir: path.join(__dirname, '../core/mock-data/assets'),
  24. },
  25. workerOptions: {
  26. runInMainProcess: true,
  27. },
  28. customFields: {},
  29. }),
  30. );
  31. clearAllTables(populateConfig, true)
  32. .then(() =>
  33. populate(
  34. () => bootstrap(populateConfig),
  35. initialData,
  36. path.join(__dirname, '../create/assets/products.csv'),
  37. ),
  38. )
  39. .then(async app => {
  40. console.log('populating customers...');
  41. await populateCustomers(10, populateConfig, true);
  42. return app.close();
  43. })
  44. .then(
  45. () => process.exit(0),
  46. err => {
  47. console.log(err);
  48. process.exit(1);
  49. },
  50. );
  51. }