build.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.ReactBuildCLI = exports.ReactBuildRunner = void 0;
  27. const build_1 = require("../../build");
  28. const color_1 = require("../../color");
  29. class ReactBuildRunner extends build_1.BuildRunner {
  30. constructor(e) {
  31. super();
  32. this.e = e;
  33. }
  34. async getCommandMetadata() {
  35. return {
  36. description: `
  37. This command will convert options to the environment variables used by React Scripts. See the ${(0, color_1.input)('create-react-app')} docs[^cra-build-docs] for explanations.
  38. `,
  39. footnotes: [
  40. {
  41. id: 'cra-build-docs',
  42. url: 'https://facebook.github.io/create-react-app/docs/advanced-configuration',
  43. },
  44. ],
  45. options: [
  46. {
  47. name: 'public-url',
  48. summary: 'The URL at which the app will be served',
  49. groups: ['cordova'],
  50. spec: { value: 'url' },
  51. hint: (0, color_1.weak)('[react-scripts]'),
  52. },
  53. {
  54. name: 'ci',
  55. summary: `Treat warnings as build failures, test runner does not watch`,
  56. type: Boolean,
  57. groups: ['cordova'],
  58. hint: (0, color_1.weak)('[react-scripts]'),
  59. },
  60. {
  61. name: 'source-map',
  62. summary: 'Do not generate source maps',
  63. type: Boolean,
  64. groups: ['cordova'],
  65. default: true,
  66. hint: (0, color_1.weak)('[react-scripts]'),
  67. },
  68. {
  69. name: 'inline-runtime-chunk',
  70. summary: `Do not include the runtime script in ${(0, color_1.input)('index.html')} (import instead)`,
  71. type: Boolean,
  72. groups: ['cordova'],
  73. default: true,
  74. hint: (0, color_1.weak)('[react-scripts]'),
  75. },
  76. ],
  77. };
  78. }
  79. createOptionsFromCommandLine(inputs, options) {
  80. const baseOptions = super.createBaseOptionsFromCommandLine(inputs, options);
  81. const publicUrl = options['public-url'] ? String(options['public-url']) : undefined;
  82. const ci = options['ci'] ? Boolean(options['ci']) : undefined;
  83. const sourceMap = options['source-map'] ? Boolean(options['source-map']) : undefined;
  84. const inlineRuntimeChunk = options['inline-runtime-check'] ? Boolean(options['inline-runtime-check']) : undefined;
  85. return {
  86. ...baseOptions,
  87. type: 'react',
  88. publicUrl,
  89. ci,
  90. sourceMap,
  91. inlineRuntimeChunk,
  92. };
  93. }
  94. async buildProject(options) {
  95. const reactScripts = new ReactBuildCLI(this.e);
  96. await reactScripts.build(options);
  97. }
  98. }
  99. exports.ReactBuildRunner = ReactBuildRunner;
  100. class ReactBuildCLI extends build_1.BuildCLI {
  101. constructor() {
  102. super(...arguments);
  103. this.name = 'React Scripts';
  104. this.pkg = 'react-scripts';
  105. this.program = 'react-scripts';
  106. this.prefix = 'react-scripts';
  107. this.script = build_1.BUILD_SCRIPT;
  108. }
  109. async buildArgs(options) {
  110. const { pkgManagerArgs } = await Promise.resolve().then(() => __importStar(require('../../utils/npm')));
  111. if (this.resolvedProgram === this.program) {
  112. return ['build'];
  113. }
  114. else {
  115. const [, ...pkgArgs] = await pkgManagerArgs(this.e.config.get('npmClient'), { command: 'run', script: this.script });
  116. return pkgArgs;
  117. }
  118. }
  119. async buildEnvVars(options) {
  120. const env = {};
  121. if (options.publicUrl) {
  122. env.PUBLIC_URL = options.publicUrl;
  123. }
  124. if (options.ci) {
  125. env.CI = '1';
  126. }
  127. if (!options.sourceMap) {
  128. env.GENERATE_SOURCEMAP = 'false';
  129. }
  130. if (!options.inlineRuntimeChunk) {
  131. env.INLINE_RUNTIME_CHUNK = 'false';
  132. }
  133. return { ...await super.buildEnvVars(options), ...env };
  134. }
  135. }
  136. exports.ReactBuildCLI = ReactBuildCLI;