compile.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { AdminUiExtension } from '@vendure/common/lib/shared-types';
  2. import { spawn } from 'child_process';
  3. import * as path from 'path';
  4. import {
  5. copyExtensionModules,
  6. copyUiDevkit,
  7. createExtensionsModules,
  8. deleteExistingExtensionModules,
  9. isInVendureMonorepo,
  10. restoreOriginalExtensionsModule,
  11. } from './common';
  12. /**
  13. * Builds the admin-ui app using the Angular CLI `ng build --prod` command.
  14. */
  15. export function compileAdminUiApp(outputPath: string, extensions: Array<Required<AdminUiExtension>>) {
  16. const cwd = path.join(__dirname, '..');
  17. const relativeOutputPath = path.relative(cwd, outputPath);
  18. return new Promise((resolve, reject) => {
  19. restoreOriginalExtensionsModule();
  20. deleteExistingExtensionModules();
  21. copyExtensionModules(extensions);
  22. copyUiDevkit();
  23. createExtensionsModules(extensions);
  24. const config = isInVendureMonorepo() ? 'plugin-dev' : 'plugin';
  25. const buildProcess = spawn(
  26. 'yarn',
  27. ['ng', 'build', `-c=${config}`, `--outputPath=${relativeOutputPath}`],
  28. {
  29. cwd,
  30. shell: true,
  31. stdio: 'inherit',
  32. },
  33. );
  34. buildProcess.on('close', code => {
  35. if (code === 0) {
  36. resolve();
  37. } else {
  38. reject(code);
  39. }
  40. });
  41. buildProcess.on('error', err => {
  42. reject(err);
  43. });
  44. }).finally(() => {
  45. restoreOriginalExtensionsModule();
  46. });
  47. }