1
0

populate-dev-server.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // eslint-disable-next-line @typescript-eslint/triple-slash-reference
  2. /// <reference path="../core/typings.d.ts" />
  3. import { bootstrap, defaultConfig, JobQueueService, Logger, 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. /* eslint-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. customFields: {},
  26. }),
  27. );
  28. clearAllTables(populateConfig, true)
  29. .then(() =>
  30. populate(
  31. () =>
  32. bootstrap(populateConfig).then(async app => {
  33. await app.get(JobQueueService).start();
  34. return app;
  35. }),
  36. initialData,
  37. path.join(__dirname, '../create/assets/products.csv'),
  38. ),
  39. )
  40. .then(async app => {
  41. console.log('populating customers...');
  42. await populateCustomers(app, 10, message => Logger.error(message));
  43. return app.close();
  44. })
  45. .then(
  46. () => process.exit(0),
  47. err => {
  48. console.log(err);
  49. process.exit(1);
  50. },
  51. );
  52. }