populate-dev-server.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // tslint:disable-next-line:no-reference
  2. /// <reference path="../core/typings.d.ts" />
  3. import { bootstrap, mergeConfig, VendureConfig } from '@vendure/core';
  4. import { populate } from '@vendure/core/cli/populate';
  5. import { defaultConfig } from '@vendure/core/dist/config/default-config';
  6. import { clearAllTables, populateCustomers } from '@vendure/testing';
  7. import path from 'path';
  8. import { initialData } from '../core/mock-data/data-sources/initial-data';
  9. import { devConfig } from './dev-config';
  10. // tslint:disable:no-console
  11. /**
  12. * A CLI script which populates the dev database with deterministic random data.
  13. */
  14. if (require.main === module) {
  15. // Running from command line
  16. const populateConfig = mergeConfig(
  17. defaultConfig,
  18. mergeConfig(devConfig, {
  19. authOptions: {
  20. tokenMethod: 'bearer',
  21. requireVerification: false,
  22. },
  23. importExportOptions: {
  24. importAssetsDir: path.join(__dirname, '../core/mock-data/assets'),
  25. },
  26. workerOptions: {
  27. runInMainProcess: true,
  28. },
  29. customFields: {},
  30. }),
  31. );
  32. clearAllTables(populateConfig, true)
  33. .then(() =>
  34. populate(
  35. () => bootstrap(populateConfig),
  36. initialData,
  37. path.join(__dirname, '../create/assets/products.csv'),
  38. ),
  39. )
  40. .then(async app => {
  41. console.log('populating customers...');
  42. await populateCustomers(10, populateConfig, true);
  43. return app.close();
  44. })
  45. .then(
  46. () => process.exit(0),
  47. err => {
  48. console.log(err);
  49. process.exit(1);
  50. },
  51. );
  52. }