@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,194 @@
1
+ import _asyncToGenerator from '@babel/runtime-corejs3/helpers/esm/asyncToGenerator';
2
+ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
3
+ import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
4
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
5
+ import fs from 'fs';
6
+ import webpack from 'webpack';
7
+ import WebpackDevServer from 'webpack-dev-server';
8
+ import chalk from 'chalk';
9
+ import clearConsole from 'react-dev-utils/clearConsole';
10
+ import checkRequiredFiles from 'react-dev-utils/checkRequiredFiles';
11
+ import { prepareUrls, createCompiler, choosePort } from 'react-dev-utils/WebpackDevServerUtils';
12
+ import openBrowser from 'react-dev-utils/openBrowser';
13
+ import { p as paths } from './paths-ed23d5a1.esm.js';
14
+ import { processConfig } from '@commercetools-frontend/application-config';
15
+ import { processHeaders } from '@commercetools-frontend/mc-html-template';
16
+ import { createMcDevAuthenticationMiddleware } from '@commercetools-frontend/mc-dev-authentication';
17
+ import { c as createWebpackConfigForDevelopment } from './create-webpack-config-for-development-8a8b84d6.esm.js';
18
+ import '@babel/runtime-corejs3/core-js-stable/instance/find';
19
+ import '@babel/runtime-corejs3/core-js-stable/instance/concat';
20
+ import 'path';
21
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
22
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
23
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
24
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
25
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
26
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
27
+ import '@babel/runtime-corejs3/helpers/defineProperty';
28
+ import '@babel/runtime-corejs3/core-js-stable/instance/map';
29
+ import '@babel/runtime-corejs3/core-js-stable/instance/filter';
30
+ import '@babel/runtime-corejs3/core-js-stable/json/stringify';
31
+ import '@babel/runtime-corejs3/core-js-stable/instance/ends-with';
32
+ import 'webpackbar';
33
+ import 'html-webpack-plugin';
34
+ import 'moment-locales-webpack-plugin';
35
+ import '@pmmmwh/react-refresh-webpack-plugin';
36
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
37
+ import '@babel/runtime-corejs3/helpers/createClass';
38
+ import '@babel/runtime-corejs3/core-js-stable/object/assign';
39
+ import './vendors-to-transpile-68e03526.esm.js';
40
+ import './create-postcss-config-c1aa3525.esm.js';
41
+ import '@babel/runtime-corejs3/helpers/toConsumableArray';
42
+ import '@babel/runtime-corejs3/helpers/slicedToArray';
43
+ import './package-a98de907.esm.js';
44
+ import './has-jsx-runtime-8314226e.esm.js';
45
+
46
+ var host = process.env.HOST || '0.0.0.0'; // We support configuring the sockjs pathname during development.
47
+ // These settings let a developer run multiple simultaneous projects.
48
+ // They are used as the connection `hostname`, `pathname` and `port`
49
+ // in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
50
+ // and `sockPort` options in webpack-dev-server.
51
+
52
+ var sockHost = process.env.WDS_SOCKET_HOST;
53
+ var sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
54
+
55
+ var sockPort = process.env.WDS_SOCKET_PORT;
56
+
57
+ var createWebpackDevServerConfig = function createWebpackDevServerConfig(_ref) {
58
+ var port = _ref.port,
59
+ publicPath = _ref.publicPath;
60
+ var applicationConfig = processConfig();
61
+ var compiledHeaders = processHeaders(applicationConfig);
62
+ return {
63
+ client: {
64
+ overlay: false,
65
+ webSocketURL: {
66
+ hostname: sockHost,
67
+ pathname: sockPath,
68
+ port: sockPort
69
+ }
70
+ },
71
+ // Enable gzip compression of generated files.
72
+ compress: true,
73
+ devMiddleware: {
74
+ // It is important to tell WebpackDevServer to use the same "publicPath" path as
75
+ // we specified in the webpack config. When homepage is '.', default to serving
76
+ // from the root.
77
+ publicPath: publicPath
78
+ },
79
+ headers: compiledHeaders,
80
+ historyApiFallback: {
81
+ // Paths with dots should still use the history fallback.
82
+ // See https://github.com/facebookincubator/create-react-app/issues/387.
83
+ disableDotRule: true,
84
+ index: publicPath
85
+ },
86
+ host: host,
87
+ hot: true,
88
+ https: false,
89
+ port: port,
90
+ setupMiddlewares: function setupMiddlewares(middlewares, devServer) {
91
+ var _devServer$app;
92
+
93
+ if (!devServer) {
94
+ throw new Error('webpack-dev-server is not defined');
95
+ }
96
+
97
+ (_devServer$app = devServer.app) === null || _devServer$app === void 0 ? void 0 : _devServer$app.use(createMcDevAuthenticationMiddleware(applicationConfig));
98
+ return middlewares;
99
+ }
100
+ };
101
+ };
102
+
103
+ function run() {
104
+ return _run.apply(this, arguments);
105
+ }
106
+
107
+ function _run() {
108
+ _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
109
+ var _config$output, _context;
110
+
111
+ var useYarn, isInteractive, hasWebpackConfig, DEFAULT_PORT, HOST, port, protocol, appName, urls, config, compiler, serverConfig, devServer;
112
+ return _regeneratorRuntime.wrap(function _callee$(_context2) {
113
+ while (1) {
114
+ switch (_context2.prev = _context2.next) {
115
+ case 0:
116
+ useYarn = fs.existsSync(paths.yarnLockFile);
117
+ isInteractive = process.stdout.isTTY; // Whether or not `react-refresh` is enabled, `react-refresh` is not 100% stable at this time,
118
+ // which is why it's disabled by default.
119
+
120
+ hasWebpackConfig = fs.existsSync(paths.appWebpackConfig); // Warn and crash if required files are missing
121
+
122
+ if (!checkRequiredFiles([])) {
123
+ process.exit(1);
124
+ } // Tools like Cloud9 rely on this.
125
+
126
+
127
+ DEFAULT_PORT = _parseInt(String(process.env.HTTP_PORT), 10) || 3001;
128
+ HOST = process.env.HOST || '0.0.0.0'; // We attempt to use the default port but if it is busy, we offer the user to
129
+ // run on a different port. `detect()` Promise resolves to the next free port.
130
+
131
+ _context2.next = 8;
132
+ return choosePort(HOST, DEFAULT_PORT);
133
+
134
+ case 8:
135
+ port = _context2.sent;
136
+
137
+ if (!(port == null)) {
138
+ _context2.next = 12;
139
+ break;
140
+ }
141
+
142
+ console.warn('Could not find a free port. Aborting.'); // We have not found a port.
143
+
144
+ return _context2.abrupt("return");
145
+
146
+ case 12:
147
+ protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
148
+ appName = require(paths.appPackageJson).name;
149
+ urls = prepareUrls(protocol, HOST, port); // Get webpack config
150
+
151
+ config = hasWebpackConfig ? require(paths.appWebpackConfig) : createWebpackConfigForDevelopment(); // Create a webpack compiler that is configured with custom messages.
152
+
153
+ compiler = createCompiler({
154
+ appName: appName,
155
+ config: config,
156
+ useYarn: useYarn,
157
+ webpack: webpack,
158
+ urls: urls
159
+ }); // Serve webpack assets generated by the compiler over a web sever.
160
+
161
+ serverConfig = createWebpackDevServerConfig({
162
+ port: port,
163
+ publicPath: (_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.publicPath
164
+ });
165
+ devServer = new WebpackDevServer(serverConfig, compiler);
166
+ _context2.next = 21;
167
+ return devServer.start();
168
+
169
+ case 21:
170
+ if (isInteractive) {
171
+ clearConsole();
172
+ }
173
+
174
+ console.log(chalk.cyan('Starting the development server...\n'));
175
+ openBrowser(urls.localUrlForBrowser);
176
+
177
+ _forEachInstanceProperty(_context = ['SIGINT', 'SIGTERM']).call(_context, function (sig) {
178
+ process.on(sig, function () {
179
+ devServer.close();
180
+ process.exit();
181
+ });
182
+ });
183
+
184
+ case 25:
185
+ case "end":
186
+ return _context2.stop();
187
+ }
188
+ }
189
+ }, _callee);
190
+ }));
191
+ return _run.apply(this, arguments);
192
+ }
193
+
194
+ export { run as default };
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
4
+ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
5
+ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
6
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
7
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
8
+ var fs = require('fs-extra');
9
+ var path = require('path');
10
+ var vite = require('vite');
11
+ var pluginGraphql = require('@rollup/plugin-graphql');
12
+ var pluginReact = require('@vitejs/plugin-react');
13
+ var applicationConfig = require('@commercetools-frontend/application-config');
14
+ var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
15
+ var mcDevAuthentication = require('@commercetools-frontend/mc-dev-authentication');
16
+ var assets = require('@commercetools-frontend/assets');
17
+ var paths = require('./paths-16823f56.cjs.dev.js');
18
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
19
+ require('@babel/runtime-corejs3/core-js-stable/instance/concat');
20
+ require('fs');
21
+
22
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
23
+
24
+ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
25
+ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
26
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
27
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
28
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
29
+ var path__default = /*#__PURE__*/_interopDefault(path);
30
+ var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
31
+ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
32
+
33
+ var pluginCustomApplication = function pluginCustomApplication(applicationConfig) {
34
+ return {
35
+ name: 'custom-application',
36
+ configureServer: function configureServer(server) {
37
+ return function () {
38
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
39
+ // as it's generated and maintained by the Custom Application CLI.
40
+ // Therefore, the generated `index.html` (template) is written into the `/public`
41
+ // folder so that it's gitignored.
42
+ // As a result, we need to make sure to point the URI path to the correct location.
43
+ server.middlewares.use(function (req, _res, next) {
44
+ if (req.url === '/index.html') {
45
+ req.url = '/public/index.html';
46
+ }
47
+
48
+ next();
49
+ }); // Handle auth routes for internal local development.
50
+
51
+ server.middlewares.use(mcDevAuthentication.createMcDevAuthenticationMiddleware(applicationConfig));
52
+ };
53
+ },
54
+
55
+ /**
56
+ * @type {import('vite').IndexHtmlTransformHook}
57
+ */
58
+ transformIndexHtml: function transformIndexHtml(rawHtml, _ctx) {
59
+ var compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig);
60
+
61
+ var enhancedLocalEnv = _Object$assign__default["default"]({}, applicationConfig.env, // Now that the app config is defined as a `env.json`, when we start the FE app
62
+ // to point to the local backend API by passing the `MC_API_URL` env does not
63
+ // work anymore). To make it work again, we can override the `env.json` config
64
+ // with the env variable before injecting the values into the index.html.
65
+ // NOTE: this is only necessary for development.
66
+ process.env.MC_API_URL ? {
67
+ mcApiUrl: process.env.MC_API_URL
68
+ } : {}); // Resolve the placeholders of the `index.html` (template) file, before serving it.
69
+
70
+
71
+ var html = mcHtmlTemplate.replaceHtmlPlaceholders(rawHtml, {
72
+ env: enhancedLocalEnv,
73
+ headers: compiledHeaders
74
+ });
75
+ return html;
76
+ }
77
+ };
78
+ };
79
+
80
+ function run() {
81
+ return _run.apply(this, arguments);
82
+ }
83
+
84
+ function _run() {
85
+ _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
86
+ var DEFAULT_PORT, applicationConfig$1, appEntryPoint, html, server;
87
+ return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
88
+ while (1) {
89
+ switch (_context.prev = _context.next) {
90
+ case 0:
91
+ DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001; // Load the Custom Application config file first.
92
+
93
+ applicationConfig$1 = applicationConfig.processConfig(); // Ensure the `/public` folder exists.
94
+
95
+ fs__default["default"].mkdirSync(paths.paths.appBuild, {
96
+ recursive: true
97
+ }); // Generate `index.html` (template).
98
+
99
+ appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
100
+ html = mcHtmlTemplate.generateTemplate({
101
+ // Define the module entry point (path relative to the `/public` folder).
102
+ // NOTE: that this is different from the production configuration.
103
+ scriptImports: ["<script type=\"module\" src=\"/../".concat(appEntryPoint, "\"></script>")]
104
+ }); // Write `index.html` (template) into the `/public` folder.
105
+
106
+ fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
107
+ encoding: 'utf8'
108
+ });
109
+ _context.next = 8;
110
+ return vite.createServer({
111
+ root: paths.paths.appRoot,
112
+ define: {
113
+ 'process.env.DEBUG': _JSON$stringify__default["default"](false),
114
+ 'process.env.NODE_ENV': _JSON$stringify__default["default"]('development')
115
+ },
116
+ server: {
117
+ port: DEFAULT_PORT
118
+ },
119
+ plugins: [pluginGraphql__default["default"](), pluginReact__default["default"]({
120
+ jsxImportSource: '@emotion/react',
121
+ babel: {
122
+ plugins: ['@emotion/babel-plugin']
123
+ }
124
+ }), pluginCustomApplication(applicationConfig$1)]
125
+ });
126
+
127
+ case 8:
128
+ server = _context.sent;
129
+ _context.next = 11;
130
+ return server.listen();
131
+
132
+ case 11:
133
+ // Copy public assets to `/public` folder (even in development).
134
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
135
+ dereference: true
136
+ });
137
+ server.printUrls();
138
+
139
+ case 13:
140
+ case "end":
141
+ return _context.stop();
142
+ }
143
+ }
144
+ }, _callee);
145
+ }));
146
+ return _run.apply(this, arguments);
147
+ }
148
+
149
+ exports["default"] = run;
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
4
+ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
5
+ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
6
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
7
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
8
+ var fs = require('fs-extra');
9
+ var path = require('path');
10
+ var vite = require('vite');
11
+ var pluginGraphql = require('@rollup/plugin-graphql');
12
+ var pluginReact = require('@vitejs/plugin-react');
13
+ var applicationConfig = require('@commercetools-frontend/application-config');
14
+ var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
15
+ var mcDevAuthentication = require('@commercetools-frontend/mc-dev-authentication');
16
+ var assets = require('@commercetools-frontend/assets');
17
+ var paths = require('./paths-76b66e74.cjs.prod.js');
18
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
19
+ require('@babel/runtime-corejs3/core-js-stable/instance/concat');
20
+ require('fs');
21
+
22
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
23
+
24
+ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
25
+ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
26
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
27
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
28
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
29
+ var path__default = /*#__PURE__*/_interopDefault(path);
30
+ var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
31
+ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
32
+
33
+ var pluginCustomApplication = function pluginCustomApplication(applicationConfig) {
34
+ return {
35
+ name: 'custom-application',
36
+ configureServer: function configureServer(server) {
37
+ return function () {
38
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
39
+ // as it's generated and maintained by the Custom Application CLI.
40
+ // Therefore, the generated `index.html` (template) is written into the `/public`
41
+ // folder so that it's gitignored.
42
+ // As a result, we need to make sure to point the URI path to the correct location.
43
+ server.middlewares.use(function (req, _res, next) {
44
+ if (req.url === '/index.html') {
45
+ req.url = '/public/index.html';
46
+ }
47
+
48
+ next();
49
+ }); // Handle auth routes for internal local development.
50
+
51
+ server.middlewares.use(mcDevAuthentication.createMcDevAuthenticationMiddleware(applicationConfig));
52
+ };
53
+ },
54
+
55
+ /**
56
+ * @type {import('vite').IndexHtmlTransformHook}
57
+ */
58
+ transformIndexHtml: function transformIndexHtml(rawHtml, _ctx) {
59
+ var compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig);
60
+
61
+ var enhancedLocalEnv = _Object$assign__default["default"]({}, applicationConfig.env, // Now that the app config is defined as a `env.json`, when we start the FE app
62
+ // to point to the local backend API by passing the `MC_API_URL` env does not
63
+ // work anymore). To make it work again, we can override the `env.json` config
64
+ // with the env variable before injecting the values into the index.html.
65
+ // NOTE: this is only necessary for development.
66
+ process.env.MC_API_URL ? {
67
+ mcApiUrl: process.env.MC_API_URL
68
+ } : {}); // Resolve the placeholders of the `index.html` (template) file, before serving it.
69
+
70
+
71
+ var html = mcHtmlTemplate.replaceHtmlPlaceholders(rawHtml, {
72
+ env: enhancedLocalEnv,
73
+ headers: compiledHeaders
74
+ });
75
+ return html;
76
+ }
77
+ };
78
+ };
79
+
80
+ function run() {
81
+ return _run.apply(this, arguments);
82
+ }
83
+
84
+ function _run() {
85
+ _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
86
+ var DEFAULT_PORT, applicationConfig$1, appEntryPoint, html, server;
87
+ return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
88
+ while (1) {
89
+ switch (_context.prev = _context.next) {
90
+ case 0:
91
+ DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001; // Load the Custom Application config file first.
92
+
93
+ applicationConfig$1 = applicationConfig.processConfig(); // Ensure the `/public` folder exists.
94
+
95
+ fs__default["default"].mkdirSync(paths.paths.appBuild, {
96
+ recursive: true
97
+ }); // Generate `index.html` (template).
98
+
99
+ appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
100
+ html = mcHtmlTemplate.generateTemplate({
101
+ // Define the module entry point (path relative to the `/public` folder).
102
+ // NOTE: that this is different from the production configuration.
103
+ scriptImports: ["<script type=\"module\" src=\"/../".concat(appEntryPoint, "\"></script>")]
104
+ }); // Write `index.html` (template) into the `/public` folder.
105
+
106
+ fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
107
+ encoding: 'utf8'
108
+ });
109
+ _context.next = 8;
110
+ return vite.createServer({
111
+ root: paths.paths.appRoot,
112
+ define: {
113
+ 'process.env.DEBUG': _JSON$stringify__default["default"](false),
114
+ 'process.env.NODE_ENV': _JSON$stringify__default["default"]('development')
115
+ },
116
+ server: {
117
+ port: DEFAULT_PORT
118
+ },
119
+ plugins: [pluginGraphql__default["default"](), pluginReact__default["default"]({
120
+ jsxImportSource: '@emotion/react',
121
+ babel: {
122
+ plugins: ['@emotion/babel-plugin']
123
+ }
124
+ }), pluginCustomApplication(applicationConfig$1)]
125
+ });
126
+
127
+ case 8:
128
+ server = _context.sent;
129
+ _context.next = 11;
130
+ return server.listen();
131
+
132
+ case 11:
133
+ // Copy public assets to `/public` folder (even in development).
134
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
135
+ dereference: true
136
+ });
137
+ server.printUrls();
138
+
139
+ case 13:
140
+ case "end":
141
+ return _context.stop();
142
+ }
143
+ }
144
+ }, _callee);
145
+ }));
146
+ return _run.apply(this, arguments);
147
+ }
148
+
149
+ exports["default"] = run;
@@ -0,0 +1,136 @@
1
+ import _asyncToGenerator from '@babel/runtime-corejs3/helpers/esm/asyncToGenerator';
2
+ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
3
+ import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign';
4
+ import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
5
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
6
+ import fs from 'fs-extra';
7
+ import path from 'path';
8
+ import { createServer } from 'vite';
9
+ import pluginGraphql from '@rollup/plugin-graphql';
10
+ import pluginReact from '@vitejs/plugin-react';
11
+ import { processConfig } from '@commercetools-frontend/application-config';
12
+ import { generateTemplate, processHeaders, replaceHtmlPlaceholders } from '@commercetools-frontend/mc-html-template';
13
+ import { createMcDevAuthenticationMiddleware } from '@commercetools-frontend/mc-dev-authentication';
14
+ import { packageLocation } from '@commercetools-frontend/assets';
15
+ import { p as paths } from './paths-ed23d5a1.esm.js';
16
+ import '@babel/runtime-corejs3/core-js-stable/instance/find';
17
+ import '@babel/runtime-corejs3/core-js-stable/instance/concat';
18
+ import 'fs';
19
+
20
+ var pluginCustomApplication = function pluginCustomApplication(applicationConfig) {
21
+ return {
22
+ name: 'custom-application',
23
+ configureServer: function configureServer(server) {
24
+ return function () {
25
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
26
+ // as it's generated and maintained by the Custom Application CLI.
27
+ // Therefore, the generated `index.html` (template) is written into the `/public`
28
+ // folder so that it's gitignored.
29
+ // As a result, we need to make sure to point the URI path to the correct location.
30
+ server.middlewares.use(function (req, _res, next) {
31
+ if (req.url === '/index.html') {
32
+ req.url = '/public/index.html';
33
+ }
34
+
35
+ next();
36
+ }); // Handle auth routes for internal local development.
37
+
38
+ server.middlewares.use(createMcDevAuthenticationMiddleware(applicationConfig));
39
+ };
40
+ },
41
+
42
+ /**
43
+ * @type {import('vite').IndexHtmlTransformHook}
44
+ */
45
+ transformIndexHtml: function transformIndexHtml(rawHtml, _ctx) {
46
+ var compiledHeaders = processHeaders(applicationConfig);
47
+
48
+ var enhancedLocalEnv = _Object$assign({}, applicationConfig.env, // Now that the app config is defined as a `env.json`, when we start the FE app
49
+ // to point to the local backend API by passing the `MC_API_URL` env does not
50
+ // work anymore). To make it work again, we can override the `env.json` config
51
+ // with the env variable before injecting the values into the index.html.
52
+ // NOTE: this is only necessary for development.
53
+ process.env.MC_API_URL ? {
54
+ mcApiUrl: process.env.MC_API_URL
55
+ } : {}); // Resolve the placeholders of the `index.html` (template) file, before serving it.
56
+
57
+
58
+ var html = replaceHtmlPlaceholders(rawHtml, {
59
+ env: enhancedLocalEnv,
60
+ headers: compiledHeaders
61
+ });
62
+ return html;
63
+ }
64
+ };
65
+ };
66
+
67
+ function run() {
68
+ return _run.apply(this, arguments);
69
+ }
70
+
71
+ function _run() {
72
+ _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
73
+ var DEFAULT_PORT, applicationConfig, appEntryPoint, html, server;
74
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
75
+ while (1) {
76
+ switch (_context.prev = _context.next) {
77
+ case 0:
78
+ DEFAULT_PORT = _parseInt(String(process.env.HTTP_PORT), 10) || 3001; // Load the Custom Application config file first.
79
+
80
+ applicationConfig = processConfig(); // Ensure the `/public` folder exists.
81
+
82
+ fs.mkdirSync(paths.appBuild, {
83
+ recursive: true
84
+ }); // Generate `index.html` (template).
85
+
86
+ appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
87
+ html = generateTemplate({
88
+ // Define the module entry point (path relative to the `/public` folder).
89
+ // NOTE: that this is different from the production configuration.
90
+ scriptImports: ["<script type=\"module\" src=\"/../".concat(appEntryPoint, "\"></script>")]
91
+ }); // Write `index.html` (template) into the `/public` folder.
92
+
93
+ fs.writeFileSync(paths.appIndexHtml, html, {
94
+ encoding: 'utf8'
95
+ });
96
+ _context.next = 8;
97
+ return createServer({
98
+ root: paths.appRoot,
99
+ define: {
100
+ 'process.env.DEBUG': _JSON$stringify(false),
101
+ 'process.env.NODE_ENV': _JSON$stringify('development')
102
+ },
103
+ server: {
104
+ port: DEFAULT_PORT
105
+ },
106
+ plugins: [pluginGraphql(), pluginReact({
107
+ jsxImportSource: '@emotion/react',
108
+ babel: {
109
+ plugins: ['@emotion/babel-plugin']
110
+ }
111
+ }), pluginCustomApplication(applicationConfig)]
112
+ });
113
+
114
+ case 8:
115
+ server = _context.sent;
116
+ _context.next = 11;
117
+ return server.listen();
118
+
119
+ case 11:
120
+ // Copy public assets to `/public` folder (even in development).
121
+ fs.copySync(path.join(packageLocation, 'html-page'), paths.appBuild, {
122
+ dereference: true
123
+ });
124
+ server.printUrls();
125
+
126
+ case 13:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }
131
+ }, _callee);
132
+ }));
133
+ return _run.apply(this, arguments);
134
+ }
135
+
136
+ export { run as default };