build.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BuildCommand = void 0;
  4. const build_1 = require("../lib/build");
  5. const color_1 = require("../lib/color");
  6. const command_1 = require("../lib/command");
  7. const errors_1 = require("../lib/errors");
  8. class BuildCommand extends command_1.Command {
  9. async getMetadata() {
  10. const groups = [];
  11. const options = [];
  12. const footnotes = [];
  13. const exampleCommands = [''];
  14. let description = `${(0, color_1.input)('ionic build')} will perform an Ionic build, which compiles web assets and prepares them for deployment.`;
  15. const runner = this.project && await this.project.getBuildRunner();
  16. if (runner) {
  17. const libmetadata = await runner.getCommandMetadata();
  18. groups.push(...libmetadata.groups || []);
  19. options.push(...libmetadata.options || []);
  20. description += libmetadata.description ? `\n\n${libmetadata.description.trim()}` : '';
  21. footnotes.push(...libmetadata.footnotes || []);
  22. exampleCommands.push(...libmetadata.exampleCommands || []);
  23. }
  24. options.push(...build_1.COMMON_BUILD_COMMAND_OPTIONS);
  25. return {
  26. name: 'build',
  27. type: 'project',
  28. summary: 'Build web assets and prepare your app for any platform targets',
  29. description,
  30. footnotes,
  31. groups,
  32. exampleCommands,
  33. options,
  34. };
  35. }
  36. async preRun(inputs, options) {
  37. if (inputs.length > 0 && ['android', 'ios', 'wp8', 'windows', 'browser'].includes(inputs[0])) {
  38. this.env.log.warn(`${(0, color_1.input)('ionic build')} is for building web assets and takes no arguments. See ${(0, color_1.input)('ionic build --help')}.\n` +
  39. `Ignoring argument ${(0, color_1.input)(inputs[0])}. Perhaps you meant ${(0, color_1.input)('ionic cordova build ' + inputs[0])}?\n`);
  40. inputs.splice(0);
  41. }
  42. }
  43. async run(inputs, options, runinfo) {
  44. if (!this.project) {
  45. throw new errors_1.FatalException(`Cannot run ${(0, color_1.input)('ionic build')} outside a project directory.`);
  46. }
  47. try {
  48. const runner = await this.project.requireBuildRunner();
  49. const runnerOpts = runner.createOptionsFromCommandLine(inputs, options);
  50. await runner.run(runnerOpts);
  51. }
  52. catch (e) {
  53. if (e instanceof errors_1.RunnerException) {
  54. throw new errors_1.FatalException(e.message);
  55. }
  56. throw e;
  57. }
  58. }
  59. }
  60. exports.BuildCommand = BuildCommand;