build.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.AngularBuildCLI = exports.AngularBuildRunner = void 0;
  27. const cli_framework_1 = require("@ionic/cli-framework");
  28. const build_1 = require("../../build");
  29. const color_1 = require("../../color");
  30. const NG_BUILD_OPTIONS = [
  31. {
  32. name: 'configuration',
  33. aliases: ['c'],
  34. summary: 'Specify the configuration to use.',
  35. type: String,
  36. groups: ["advanced" /* MetadataGroup.ADVANCED */, 'cordova'],
  37. hint: (0, color_1.weak)('[ng]'),
  38. spec: { value: 'conf' },
  39. },
  40. {
  41. name: 'source-map',
  42. summary: 'Output source maps',
  43. type: Boolean,
  44. groups: ["advanced" /* MetadataGroup.ADVANCED */, 'cordova'],
  45. hint: (0, color_1.weak)('[ng]'),
  46. },
  47. {
  48. name: 'watch',
  49. summary: 'Rebuild when files change',
  50. type: Boolean,
  51. groups: ["advanced" /* MetadataGroup.ADVANCED */],
  52. hint: (0, color_1.weak)('[ng]'),
  53. },
  54. ];
  55. class AngularBuildRunner extends build_1.BuildRunner {
  56. constructor(e) {
  57. super();
  58. this.e = e;
  59. }
  60. async getCommandMetadata() {
  61. return {
  62. description: `
  63. ${(0, color_1.input)('ionic build')} uses the Angular CLI. Use ${(0, color_1.input)('ng build --help')} to list all Angular CLI options for building your app. See the ${(0, color_1.input)('ng build')} docs[^ng-build-docs] for explanations. Options not listed below are considered advanced and can be passed to the ${(0, color_1.input)('ng')} CLI using the ${(0, color_1.input)('--')} separator after the Ionic CLI arguments. See the examples.
  64. `,
  65. footnotes: [
  66. {
  67. id: 'ng-build-docs',
  68. url: 'https://angular.io/cli/build',
  69. },
  70. ],
  71. options: [
  72. {
  73. name: 'prod',
  74. summary: `Flag to use the ${(0, color_1.input)('production')} configuration`,
  75. type: Boolean,
  76. hint: (0, color_1.weak)('[ng]'),
  77. groups: ['cordova'],
  78. },
  79. ...NG_BUILD_OPTIONS,
  80. {
  81. name: 'cordova-assets',
  82. summary: 'Do not bundle Cordova assets during Cordova build',
  83. type: Boolean,
  84. groups: ["hidden" /* MetadataGroup.HIDDEN */, 'cordova'],
  85. default: true,
  86. },
  87. ],
  88. exampleCommands: [
  89. '--prod',
  90. '--watch',
  91. ],
  92. };
  93. }
  94. createOptionsFromCommandLine(inputs, options) {
  95. const baseOptions = super.createBaseOptionsFromCommandLine(inputs, options);
  96. const prod = options['prod'] ? Boolean(options['prod']) : undefined;
  97. const configuration = options['configuration'] ? String(options['configuration']) : (prod ? 'production' : undefined);
  98. const project = options['project'] ? String(options['project']) : 'app';
  99. const sourcemaps = typeof options['source-map'] === 'boolean' ? Boolean(options['source-map']) : undefined;
  100. const cordovaAssets = typeof options['cordova-assets'] === 'boolean' ? Boolean(options['cordova-assets']) : undefined;
  101. const watch = typeof options['watch'] === 'boolean' ? Boolean(options['watch']) : undefined;
  102. return {
  103. ...baseOptions,
  104. configuration,
  105. project,
  106. sourcemaps,
  107. cordovaAssets,
  108. watch,
  109. type: 'angular',
  110. };
  111. }
  112. async buildProject(options) {
  113. const ng = new AngularBuildCLI(this.e);
  114. await ng.build(options);
  115. }
  116. }
  117. exports.AngularBuildRunner = AngularBuildRunner;
  118. class AngularBuildCLI extends build_1.BuildCLI {
  119. constructor() {
  120. super(...arguments);
  121. this.name = 'Angular CLI';
  122. this.pkg = '@angular/cli';
  123. this.program = 'ng';
  124. this.prefix = 'ng';
  125. this.script = build_1.BUILD_SCRIPT;
  126. }
  127. async buildArgs(options) {
  128. const { pkgManagerArgs } = await Promise.resolve().then(() => __importStar(require('../../utils/npm')));
  129. const args = await this.buildOptionsToNgArgs(options);
  130. if (this.resolvedProgram === this.program) {
  131. return [...this.buildArchitectCommand(options), ...args];
  132. }
  133. else {
  134. const [, ...pkgArgs] = await pkgManagerArgs(this.e.config.get('npmClient'), { command: 'run', script: this.script, scriptArgs: [...args] });
  135. return pkgArgs;
  136. }
  137. }
  138. async buildOptionsToNgArgs(options) {
  139. const args = {
  140. _: [],
  141. 'source-map': options.sourcemaps !== false ? options.sourcemaps : 'false',
  142. 'cordova-assets': options.cordovaAssets !== false ? undefined : 'false',
  143. 'watch': options.watch !== false ? options.watch : 'false',
  144. };
  145. const projectArgs = [];
  146. let separatedArgs = options['--'];
  147. if (options.engine === 'cordova') {
  148. const integration = this.e.project.requireIntegration('cordova');
  149. args.platform = options.platform;
  150. if (this.e.project.rootDirectory !== integration.root) {
  151. args.cordovaBasePath = integration.root;
  152. }
  153. separatedArgs = [];
  154. }
  155. if (this.resolvedProgram !== this.program) {
  156. if (options.configuration) {
  157. projectArgs.push(`--configuration=${options.configuration}`);
  158. }
  159. if (options.project) {
  160. projectArgs.push(`--project=${options.project}`);
  161. }
  162. }
  163. if (options.verbose) {
  164. projectArgs.push('--verbose');
  165. }
  166. return [...(0, cli_framework_1.unparseArgs)(args), ...projectArgs, ...separatedArgs];
  167. }
  168. buildArchitectCommand(options) {
  169. const cmd = options.engine === 'cordova' ? 'ionic-cordova-build' : 'build';
  170. return ['run', `${options.project}:${cmd}${options.configuration ? `:${options.configuration}` : ''}`];
  171. }
  172. }
  173. exports.AngularBuildCLI = AngularBuildCLI;