@commercetools-frontend/mc-scripts 21.7.0 → 21.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -42
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +1 -1
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +354 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +354 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +338 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +7 -1
  17. package/config/create-webpack-config-for-production.js +7 -1
  18. package/config/vendors-to-transpile.js +5 -1
  19. package/dist/build-8582b673.esm.js +209 -0
  20. package/dist/build-9395925a.cjs.prod.js +224 -0
  21. package/dist/build-97278377.cjs.dev.js +224 -0
  22. package/dist/build-vite-6c987a60.cjs.dev.js +109 -0
  23. package/dist/build-vite-76d44332.cjs.prod.js +109 -0
  24. package/dist/build-vite-a9602b19.esm.js +97 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
  30. package/dist/compile-html-0c588a89.cjs.dev.js +93 -0
  31. package/dist/compile-html-4832f8c5.esm.js +83 -0
  32. package/dist/compile-html-7654b5e6.cjs.prod.js +93 -0
  33. package/dist/config-sync-20bc05e8.esm.js +868 -0
  34. package/dist/config-sync-62824317.cjs.prod.js +887 -0
  35. package/dist/config-sync-d52e73f6.cjs.dev.js +892 -0
  36. package/dist/create-postcss-config-4cbe10ab.cjs.dev.js +90 -0
  37. package/dist/create-postcss-config-8ea16440.cjs.prod.js +90 -0
  38. package/{build/config/create-postcss-config.js → dist/create-postcss-config-c1aa3525.esm.js} +27 -25
  39. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-8a8b84d6.esm.js} +92 -56
  40. package/dist/create-webpack-config-for-development-a5e73092.cjs.prod.js +418 -0
  41. package/dist/create-webpack-config-for-development-e2735e02.cjs.dev.js +418 -0
  42. package/dist/create-webpack-config-for-production-4e7b56c0.cjs.prod.js +468 -0
  43. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-7dc669e5.esm.js} +117 -52
  44. package/dist/create-webpack-config-for-production-d9bf281c.cjs.dev.js +468 -0
  45. package/dist/declarations/src/application-runtime.d.ts +1 -0
  46. package/dist/declarations/src/cli.d.ts +4 -0
  47. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  48. package/dist/declarations/src/commands/build.d.ts +2 -0
  49. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  50. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  51. package/dist/declarations/src/commands/login.d.ts +2 -0
  52. package/dist/declarations/src/commands/serve.d.ts +2 -0
  53. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/start.d.ts +2 -0
  55. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  56. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  57. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  58. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  59. package/dist/declarations/src/config/paths.d.ts +12 -0
  60. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  61. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  62. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  63. package/dist/declarations/src/generated/core.d.ts +710 -0
  64. package/dist/declarations/src/generated/settings.d.ts +2383 -0
  65. package/dist/declarations/src/index.d.ts +3 -0
  66. package/dist/declarations/src/postcss.d.ts +1 -0
  67. package/dist/declarations/src/types.d.ts +82 -0
  68. package/dist/declarations/src/utils/auth.d.ts +6 -0
  69. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  70. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  71. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  72. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  73. package/dist/declarations/src/version.d.ts +2 -0
  74. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  75. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  76. package/dist/declarations/src/webpack.d.ts +2 -0
  77. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  78. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  79. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  80. package/dist/login-706ccc9a.cjs.prod.js +165 -0
  81. package/dist/login-779552b7.cjs.dev.js +165 -0
  82. package/dist/login-7d94659e.esm.js +155 -0
  83. package/dist/package-a98de907.esm.js +133 -0
  84. package/dist/package-aaf61bf0.cjs.dev.js +135 -0
  85. package/dist/package-b5c040f3.cjs.prod.js +135 -0
  86. package/dist/paths-16823f56.cjs.dev.js +55 -0
  87. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  88. package/dist/paths-ed23d5a1.esm.js +46 -0
  89. package/dist/serve-12de323b.cjs.dev.js +70 -0
  90. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  91. package/dist/serve-d6b437b1.esm.js +62 -0
  92. package/dist/start-2b953ab0.cjs.dev.js +209 -0
  93. package/dist/start-e3ccd672.cjs.prod.js +209 -0
  94. package/dist/start-e924bd5d.esm.js +194 -0
  95. package/dist/start-vite-737bacca.cjs.dev.js +149 -0
  96. package/dist/start-vite-b0f58ae4.cjs.prod.js +149 -0
  97. package/dist/start-vite-ec5d40b5.esm.js +136 -0
  98. package/dist/user-agent-5da1830b.cjs.dev.js +106 -0
  99. package/dist/user-agent-8044acd6.esm.js +94 -0
  100. package/dist/user-agent-d18809af.cjs.prod.js +106 -0
  101. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  102. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  103. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  104. package/package.json +41 -39
  105. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  106. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  107. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  108. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  109. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  110. package/postcss/package.json +4 -0
  111. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  112. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  113. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  114. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  115. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  116. package/webpack/package.json +4 -0
  117. package/build/bin/cli.js +0 -264
  118. package/build/commands/build-vite.js +0 -91
  119. package/build/commands/build.js +0 -140
  120. package/build/commands/compile-html.js +0 -53
  121. package/build/commands/config-sync.js +0 -176
  122. package/build/commands/login.js +0 -60
  123. package/build/commands/serve.js +0 -37
  124. package/build/commands/start-vite.js +0 -138
  125. package/build/commands/start.js +0 -108
  126. package/build/config/paths.js +0 -38
  127. package/build/config/vendors-to-transpile.js +0 -3
  128. package/build/config/webpack-dev-server.config.js +0 -69
  129. package/build/index.js +0 -16
  130. package/build/utils/auth.js +0 -34
  131. package/build/utils/auth.spec.js +0 -61
  132. package/build/utils/create-custom-application.settings.graphql +0 -8
  133. package/build/utils/credentials-storage.js +0 -72
  134. package/build/utils/credentials-storage.spec.js +0 -69
  135. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  136. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  137. package/build/utils/get-config-diff.js +0 -308
  138. package/build/utils/get-config-diff.spec.js +0 -285
  139. package/build/utils/graphql-requests.js +0 -105
  140. package/build/utils/graphql-requests.spec.js +0 -159
  141. package/build/utils/require-graphql.js +0 -15
  142. package/build/utils/update-custom-application.settings.graphql +0 -13
  143. package/build/utils/user-agent.js +0 -15
  144. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  145. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -0,0 +1,42 @@
1
+ export { c as createWebpackConfigForDevelopment } from '../../dist/create-webpack-config-for-development-8a8b84d6.esm.js';
2
+ export { c as createWebpackConfigForProduction } from '../../dist/create-webpack-config-for-production-7dc669e5.esm.js';
3
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
4
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
5
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
6
+ import '@babel/runtime-corejs3/core-js-stable/instance/for-each';
7
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
8
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
9
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
10
+ import '@babel/runtime-corejs3/helpers/defineProperty';
11
+ import '@babel/runtime-corejs3/core-js-stable/instance/map';
12
+ import '@babel/runtime-corejs3/core-js-stable/instance/filter';
13
+ import '@babel/runtime-corejs3/core-js-stable/json/stringify';
14
+ import '@babel/runtime-corejs3/core-js-stable/instance/ends-with';
15
+ import '@babel/runtime-corejs3/core-js-stable/instance/concat';
16
+ import 'path';
17
+ import 'webpack';
18
+ import 'webpackbar';
19
+ import 'html-webpack-plugin';
20
+ import 'moment-locales-webpack-plugin';
21
+ import '@pmmmwh/react-refresh-webpack-plugin';
22
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
23
+ import '@babel/runtime-corejs3/helpers/createClass';
24
+ import '@babel/runtime-corejs3/core-js-stable/object/assign';
25
+ import '@commercetools-frontend/application-config';
26
+ import '@commercetools-frontend/mc-html-template';
27
+ import '../../dist/paths-ed23d5a1.esm.js';
28
+ import '@babel/runtime-corejs3/core-js-stable/instance/find';
29
+ import 'fs';
30
+ import '../../dist/vendors-to-transpile-68e03526.esm.js';
31
+ import '../../dist/create-postcss-config-c1aa3525.esm.js';
32
+ import '@babel/runtime-corejs3/helpers/toConsumableArray';
33
+ import '@babel/runtime-corejs3/helpers/slicedToArray';
34
+ import '../../dist/package-a98de907.esm.js';
35
+ import '../../dist/has-jsx-runtime-8314226e.esm.js';
36
+ import '@babel/runtime-corejs3/core-js-stable/number/is-integer';
37
+ import 'webpack-bundle-analyzer';
38
+ import 'css-minimizer-webpack-plugin';
39
+ import 'mini-css-extract-plugin';
40
+ import 'terser-webpack-plugin';
41
+ import '@babel/runtime-corejs3/core-js-stable/instance/bind';
42
+ import '@babel/runtime-corejs3/core-js-stable/instance/reduce';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/commercetools-frontend-mc-scripts-webpack.cjs.js",
3
+ "module": "dist/commercetools-frontend-mc-scripts-webpack.esm.js"
4
+ }
package/build/bin/cli.js DELETED
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
6
-
7
- // Makes the script crash on unhandled rejections instead of silently
8
- // ignoring them. In the future, promise rejections that are not handled will
9
- // terminate the Node.js process with a non-zero exit code.
10
- process.on('unhandledRejection', err => {
11
- throw err;
12
- });
13
-
14
- const fs = require('fs');
15
-
16
- const path = require('path');
17
-
18
- const mri = require('mri');
19
-
20
- const dotenv = require('dotenv');
21
-
22
- const dotenvExpand = require('dotenv-expand');
23
-
24
- const spawn = require('react-dev-utils/crossSpawn');
25
-
26
- const pkg = require('../../package.json');
27
-
28
- const flags = mri(process.argv.slice(2), {
29
- alias: {
30
- help: ['h']
31
- },
32
- boolean: ['build-only']
33
- });
34
- const commands = flags._;
35
-
36
- if (commands.length === 0 || flags.help && commands.length === 0) {
37
- console.log(`
38
- Usage: mc-scripts [global-options] [command] [options]
39
-
40
- https://docs.commercetools.com/custom-applications/api-reference/cli.
41
-
42
- Global options:
43
-
44
- --env <path> (optional) Parses the file path as a dotenv file and adds the variables to the environment. Multiple flags are allowed.
45
-
46
- Commands:
47
-
48
- build Bundles the application in production mode. Outputs a "public" folder.
49
- --build-only (optional) If defined, the command only creates the production bundles without compiling the "index.html".
50
-
51
- compile-html Compiles "index.html.template" file into a "index.html" with all the required runtime configuration. Additionally, the security headers are also compiled and printed to stdout, unless you use a "transformer".
52
- --transformer <path> (optional) The path to a JS module that can be used to generate a configuration for a specific cloud provider (e.g. Vercel, Netlify).
53
- --print-security-headers (optional) The path to a JS module that can be used to generate a configuration for a specific cloud provider (e.g. Vercel, Netlify).
54
-
55
- start Starts the application in development mode using Webpack Dev Server.
56
-
57
- serve Serves previously built and compiled application from the "public" folder.
58
-
59
- login Log in to your Merchant Center account through the CLI, using the cloud environment information from the Custom Application config file. An API token is generated and stored in a configuration file for the related cloud environment, and valid for 36 hours.
60
-
61
- config:sync Synchronizes the local Custom Application config with the Merchant Center. A new Custom Application will be created if none existed, otherwise it will be updated.
62
- --dry-run (optional) Executes the command but does not send any mutation request.
63
- `);
64
- process.exit(0);
65
- }
66
-
67
- const command = commands[0];
68
- console.log('');
69
- console.log(`mc-scripts: v${pkg.version}`);
70
- console.log(''); // Get the current directory where the CLI is executed from. Usually this is the application folder.
71
-
72
- const applicationDirectory = fs.realpathSync(process.cwd());
73
-
74
- (async () => {
75
- try {
76
- // Load dotenv files into the process environment.
77
- // This is essentially what `dotenv-cli` does, but it's now built into this CLI.
78
- loadDotEnvFiles(flags);
79
-
80
- switch (command) {
81
- case 'build':
82
- {
83
- // Do this as the first thing so that any code reading it knows the right env.
84
- process.env.BABEL_ENV = 'production';
85
- process.env.NODE_ENV = 'production';
86
- const shouldAlsoCompile = !flags['build-only'];
87
- const shouldUseExperimentalBundler = process.env.ENABLE_EXPERIMENTAL_VITE_BUNDLER === 'true';
88
-
89
- if (shouldUseExperimentalBundler) {
90
- console.log('Experimental Vite bundler enabled! 🚀');
91
- console.warn('NOTE that the "cdnURL" value is not supported at the moment when using Vite.');
92
- console.log('');
93
- }
94
-
95
- proxyCommand(command, {
96
- noExit: shouldAlsoCompile,
97
- fileName: shouldUseExperimentalBundler ? 'build-vite' : 'build'
98
- });
99
-
100
- if (shouldAlsoCompile) {
101
- console.log('');
102
- proxyCommand('compile-html');
103
- }
104
-
105
- break;
106
- }
107
-
108
- case 'serve':
109
- {
110
- // Do this as the first thing so that any code reading it knows the right env.
111
- process.env.NODE_ENV = 'production';
112
- proxyCommand(command);
113
- break;
114
- }
115
-
116
- case 'compile-html':
117
- {
118
- // Do this as the first thing so that any code reading it knows the right env.
119
- process.env.NODE_ENV = 'production'; // Get specific flag for this command.
120
-
121
- const commandArgs = getArgsForCommand(['transformer', 'print-security-headers']);
122
- proxyCommand(command, {
123
- commandArgs
124
- });
125
- break;
126
- }
127
-
128
- case 'start':
129
- {
130
- // Do this as the first thing so that any code reading it knows the right env.
131
- process.env.BABEL_ENV = 'development';
132
- process.env.NODE_ENV = 'development';
133
- const shouldUseExperimentalBundler = process.env.ENABLE_EXPERIMENTAL_VITE_BUNDLER === 'true';
134
-
135
- if (shouldUseExperimentalBundler) {
136
- console.log('Experimental Vite bundler enabled');
137
- console.log('');
138
- }
139
-
140
- proxyCommand(command, {
141
- fileName: shouldUseExperimentalBundler ? 'start-vite' : 'start'
142
- });
143
- break;
144
- }
145
-
146
- case 'login':
147
- {
148
- // Do this as the first thing so that any code reading it knows the right env.
149
- process.env.NODE_ENV = 'production';
150
- proxyCommand(command);
151
- break;
152
- }
153
-
154
- case 'config:sync':
155
- {
156
- // Do this as the first thing so that any code reading it knows the right env.
157
- process.env.NODE_ENV = 'production'; // Get specific flag for this command.
158
-
159
- const commandArgs = getArgsForCommand(['dry-run']);
160
- proxyCommand(command, {
161
- commandArgs,
162
- // File names with `:` cause issues in Windows, therefore the file name is
163
- // different from the command name.
164
- fileName: 'config-sync'
165
- });
166
- break;
167
- }
168
-
169
- default:
170
- console.log(`Unknown script "${command}".`);
171
- console.log('Perhaps you need to update mc-scripts?');
172
- console.log('See: https://www.npmjs.com/package/@commercetools-frontend/mc-scripts');
173
- break;
174
- }
175
- } catch (error) {
176
- console.error(error);
177
- process.exit(1);
178
- }
179
- })();
180
-
181
- function getArgsForCommand(allowedFlags = []) {
182
- return Object.keys(flags).reduce((allArgs, flagKey) => {
183
- if ((0, _includes.default)(allowedFlags).call(allowedFlags, flagKey)) {
184
- return allArgs.concat([`--${flagKey}`, flags[flagKey]]);
185
- }
186
-
187
- return allArgs;
188
- }, []);
189
- }
190
-
191
- function proxyCommand(commandName, {
192
- commandArgs,
193
- fileName,
194
- noExit
195
- } = {}) {
196
- // Spawn the actual command.
197
- const result = spawn.sync('node', [require.resolve(`../commands/${fileName || commandName}`)].concat(commandArgs), {
198
- stdio: 'inherit'
199
- }); // Handle exit signals.
200
-
201
- if (result.signal) {
202
- switch (result.signal) {
203
- case 'SIGKILL':
204
- {
205
- console.log(`The command ${commandName} failed because the process exited too early. This probably means the system ran out of memory or someone called "kill -9" on the process.`);
206
- break;
207
- }
208
-
209
- case 'SIGTERM':
210
- {
211
- console.log(`The command ${commandName} failed because the process exited too early. Someone might have called "kill" or "killall", or the system could be shutting down.`);
212
- break;
213
- }
214
-
215
- default:
216
- break;
217
- }
218
-
219
- process.exit(1);
220
- }
221
-
222
- if (result.status > 0) {
223
- process.exit(result.status);
224
- } else {
225
- if (!noExit) {
226
- process.exit(result.status);
227
- }
228
- }
229
- } // Load dotenv files into the process environment.
230
- // This is essentially what `dotenv-cli` does, but it's now built into this CLI.
231
- // Inspired also by https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used
232
-
233
-
234
- function loadDotEnvFiles(flags) {
235
- const environment = process.env.MC_APP_ENV || process.env.NODE_ENV;
236
- const dotenvFiles = []; // Custom dotenv files specified by the `--env` option takes precedence.
237
-
238
- if (typeof flags.env === 'string') {
239
- dotenvFiles.push(flags.env);
240
- } else if (Array.isArray(flags.env)) {
241
- // Multiple `--env` options are allowed.
242
- dotenvFiles.push(...flags.env);
243
- } // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
244
-
245
-
246
- dotenvFiles.push(...[`.env.${environment}.local`, // Don't include `.env.local` for `test` environment
247
- // since normally you expect tests to produce the same
248
- // results for everyone
249
- process.NODE_ENV !== 'test' && `.env.local`, `.env.${environment}`, '.env'].filter(Boolean)); // Load environment variables from .env* files. Suppress warnings using silent
250
- // if this file is missing. dotenv will never modify any environment variables
251
- // that have already been set. Variable expansion is supported in .env files.
252
- // https://github.com/motdotla/dotenv
253
- // https://github.com/motdotla/dotenv-expand
254
-
255
- dotenvFiles.forEach(dotenvFile => {
256
- const dotenvFilePath = path.resolve(path.join(applicationDirectory, dotenvFile));
257
-
258
- if (fs.existsSync(dotenvFilePath)) {
259
- dotenvExpand.expand(dotenv.config({
260
- path: dotenvFilePath
261
- }));
262
- }
263
- });
264
- }
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable react-hooks/rules-of-hooks */
4
- const fs = require('fs-extra');
5
-
6
- const path = require('path');
7
-
8
- const {
9
- build
10
- } = require('vite');
11
-
12
- const pluginGraphql = require('@rollup/plugin-graphql');
13
-
14
- const pluginReact = require('@vitejs/plugin-react').default;
15
-
16
- const {
17
- generateTemplate
18
- } = require('@commercetools-frontend/mc-html-template');
19
-
20
- const {
21
- packageLocation: applicationStaticAssetsPath
22
- } = require('@commercetools-frontend/assets');
23
-
24
- const paths = require('../config/paths');
25
-
26
- const DEFAULT_PORT = parseInt(process.env.HTTP_PORT, 10) || 3001;
27
-
28
- const execute = async () => {
29
- // Ensure the `/public` folder exists.
30
- fs.mkdirSync(paths.appBuild, {
31
- recursive: true
32
- }); // Generate `index.html` (template).
33
-
34
- const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
35
- const html = generateTemplate({
36
- // Define the module entry point (path relative from the `/public` folder).
37
- // NOTE: that this is different from the development configuration.
38
- scriptImports: [`<script type="module" src="/${appEntryPoint}"></script>`]
39
- }); // Write `index.html` (template) into the `/public` folder.
40
-
41
- fs.writeFileSync(paths.appIndexHtml, html, {
42
- encoding: 'utf8'
43
- });
44
- await build({
45
- root: paths.appRoot,
46
- define: {
47
- 'process.env.DEBUG': JSON.stringify(false),
48
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
49
- },
50
- build: {
51
- outDir: 'public',
52
- assetsDir: '.',
53
- rollupOptions: {
54
- // This is necessary to instruct Vite that the `index.html` (template)
55
- // is located in the `/public` folder.
56
- // NOTE that after the build, Vite will write the `index.html` (template)
57
- // at the `/public/public/index.html` location. See `fs.renameSync` below.
58
- input: paths.appIndexHtml
59
- }
60
- },
61
- server: {
62
- port: DEFAULT_PORT
63
- },
64
- plugins: [pluginGraphql(), pluginReact({
65
- jsxImportSource: '@emotion/react',
66
- babel: {
67
- plugins: ['@emotion/babel-plugin']
68
- }
69
- })]
70
- }); // Rename `/public/public/index.html` to `/public/index.html.template`
71
-
72
- fs.renameSync( // Because of our custom entry point path (`/public/index.html`),
73
- // Vite will write the `index.html` to `/public/public/index.html`.
74
- // We need to move this file to the `/public` folder and rename it
75
- // to `index.html.template` (as expected by the `compile-html` command).
76
- path.join(paths.appBuild, 'public/index.html'), paths.appIndexHtmlTemplate); // Clean up nested folder
77
-
78
- fs.rmdirSync(path.join(paths.appBuild, 'public')); // Copy public assets
79
-
80
- fs.copySync(path.join(applicationStaticAssetsPath, 'html-page'), paths.appBuild, {
81
- dereference: true
82
- });
83
- };
84
-
85
- execute().catch(error => {
86
- if (error && error.message) {
87
- console.error(error.message);
88
- }
89
-
90
- process.exit(1);
91
- });
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console,global-require,import/no-dynamic-require */
4
- // NOTE: `react-dev-utils` does not currently fully support Webpack v5.
5
- // Most of the imports work, however we might bump into some edge cases.
6
- // In any case, once they release a compatible version, we should't have problems.
7
- const path = require('path');
8
-
9
- const fs = require('fs-extra');
10
-
11
- const webpack = require('webpack');
12
-
13
- const chalk = require('react-dev-utils/chalk');
14
-
15
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
16
-
17
- const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
18
-
19
- const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
20
-
21
- const printBuildError = require('react-dev-utils/printBuildError');
22
-
23
- const {
24
- packageLocation: applicationStaticAssetsPath
25
- } = require('@commercetools-frontend/assets');
26
-
27
- const paths = require('../config/paths');
28
-
29
- const createWebpackConfigForProduction = require('../config/create-webpack-config-for-production');
30
-
31
- const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild;
32
- const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; // These sizes are pretty large. We'll warn for bundles exceeding them.
33
-
34
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
35
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
36
- const hasWebpackConfig = fs.existsSync(paths.appWebpackConfig); // Warn and crash if required files are missing
37
-
38
- if (!checkRequiredFiles([])) {
39
- process.exit(1);
40
- } // First, read the current file sizes in build directory.
41
- // This lets us display how much they changed later.
42
-
43
-
44
- measureFileSizesBeforeBuild(paths.appBuild).then(previousFileSizes => {
45
- // Remove all content but keep the directory so that
46
- // if you're in it, you don't end up in Trash
47
- fs.emptyDirSync(paths.appBuild); // Copy default files
48
-
49
- copyDefaultFiles(); // Start the webpack build
50
-
51
- return build(previousFileSizes);
52
- }).then(({
53
- stats,
54
- previousFileSizes,
55
- warnings
56
- }) => {
57
- if (warnings.length) {
58
- console.log(chalk.yellow('Compiled with warnings.\n'));
59
- console.log(warnings.join('\n\n'));
60
- console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
61
- console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
62
- } else {
63
- console.log(chalk.green('Compiled successfully.\n'));
64
- }
65
-
66
- console.log('File sizes after gzip:\n');
67
- printFileSizesAfterBuild(stats, previousFileSizes, paths.appBuild, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
68
- console.log();
69
- }, err => {
70
- console.log(chalk.red('Failed to compile.\n'));
71
- printBuildError(err);
72
- process.exit(1);
73
- }).catch(err => {
74
- if (err && err.message) {
75
- console.error(err.message);
76
- }
77
-
78
- process.exit(1);
79
- }); // Create the production build and print the deployment instructions.
80
-
81
- function build(previousFileSizes) {
82
- console.log('Creating an optimized production build...');
83
- const config = hasWebpackConfig ? require(paths.appWebpackConfig) : createWebpackConfigForProduction();
84
- const compiler = webpack(config);
85
- return new Promise((resolve, reject) => {
86
- compiler.run((err, stats) => {
87
- let messages;
88
-
89
- if (err) {
90
- if (!err.message) {
91
- return reject(err);
92
- }
93
-
94
- let errMessage = err.message; // Add additional information for postcss errors
95
-
96
- if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
97
- errMessage += '\nCompileError: Begins at CSS selector ' + err['postcssNode'].selector;
98
- }
99
-
100
- messages = formatWebpackMessages({
101
- errors: [errMessage],
102
- warnings: []
103
- });
104
- } else {
105
- messages = formatWebpackMessages(stats.toJson({
106
- all: false,
107
- warnings: true,
108
- errors: true
109
- }));
110
- }
111
-
112
- if (messages.errors.length) {
113
- // Only keep the first error. Others are often indicative
114
- // of the same problem, but confuse the reader with noise.
115
- if (messages.errors.length > 1) {
116
- messages.errors.length = 1;
117
- }
118
-
119
- return reject(new Error(messages.errors.join('\n\n')));
120
- }
121
-
122
- if (process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length) {
123
- console.log(chalk.yellow('\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n'));
124
- return reject(new Error(messages.warnings.join('\n\n')));
125
- }
126
-
127
- return resolve({
128
- stats,
129
- previousFileSizes,
130
- warnings: messages.warnings
131
- });
132
- });
133
- });
134
- }
135
-
136
- function copyDefaultFiles() {
137
- fs.copySync(path.join(applicationStaticAssetsPath, 'html-page'), paths.appBuild, {
138
- dereference: true
139
- });
140
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console,global-require,import/no-dynamic-require */
4
- const fs = require('fs');
5
-
6
- const mri = require('mri');
7
-
8
- const chalk = require('react-dev-utils/chalk');
9
-
10
- const {
11
- compileHtml
12
- } = require('@commercetools-frontend/mc-html-template');
13
-
14
- const paths = require('../config/paths');
15
-
16
- const flags = mri(process.argv.slice(2), {
17
- boolean: ['print-security-headers']
18
- });
19
- const appDirectory = fs.realpathSync(process.cwd());
20
-
21
- const generateStatic = async () => {
22
- console.log('Compiling index.html...');
23
- const compiled = await compileHtml(paths.appIndexHtmlTemplate);
24
- fs.writeFileSync(paths.appIndexHtml, compiled.indexHtmlContent, {
25
- encoding: 'utf8'
26
- });
27
-
28
- if (flags.transformer) {
29
- try {
30
- const transformerPath = require.resolve(flags.transformer, {
31
- paths: [appDirectory]
32
- });
33
-
34
- const transformerFn = require(transformerPath);
35
-
36
- transformerFn(compiled);
37
- } catch (error) {
38
- throw new Error(`Could not load transformer module "${flags.transformer}"\n${error.stack}`);
39
- }
40
- } else if (flags['print-security-headers']) {
41
- console.log(JSON.stringify(compiled.headers));
42
- }
43
-
44
- console.log(chalk.green('Compiled successfully.\n'));
45
- };
46
-
47
- generateStatic().catch(error => {
48
- if (error && error.message) {
49
- console.error(error.message);
50
- }
51
-
52
- process.exit(1);
53
- });