@commercetools-frontend/mc-scripts 25.1.0 → 26.0.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 (56) hide show
  1. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +20 -7
  2. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +20 -7
  3. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +20 -7
  4. package/dist/{build-0a5986d1.cjs.dev.js → build-201624d0.cjs.dev.js} +4 -4
  5. package/dist/{build-dbcd0936.esm.js → build-607506eb.esm.js} +4 -4
  6. package/dist/{build-ec10df64.cjs.prod.js → build-c3b700bd.cjs.prod.js} +4 -4
  7. package/dist/{build-vite-16b1a575.cjs.dev.js → build-vite-837e7c94.cjs.dev.js} +56 -34
  8. package/dist/{build-vite-59e1f185.esm.js → build-vite-8cae71a0.esm.js} +53 -15
  9. package/dist/{build-vite-5d317720.cjs.prod.js → build-vite-b007241b.cjs.prod.js} +56 -34
  10. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
  11. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
  12. package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
  13. package/dist/config-sync-32b19a2a.cjs.dev.js +265 -0
  14. package/dist/config-sync-57743d92.esm.js +255 -0
  15. package/dist/config-sync-c3fb301b.cjs.prod.js +265 -0
  16. package/dist/config-sync-ci-2823fd2e.cjs.prod.js +305 -0
  17. package/dist/config-sync-ci-8a073525.cjs.dev.js +305 -0
  18. package/dist/config-sync-ci-fb0d5c7e.esm.js +294 -0
  19. package/dist/{config-sync-e7f53a98.esm.js → config-sync-helpers-17f05f8f.esm.js} +154 -283
  20. package/dist/{config-sync-ce05c66c.cjs.prod.js → config-sync-helpers-2239c279.cjs.prod.js} +162 -287
  21. package/dist/{config-sync-dbb43993.cjs.dev.js → config-sync-helpers-9bd96619.cjs.dev.js} +162 -287
  22. package/dist/{create-postcss-config-0a86560d.esm.js → create-postcss-config-6c26f1d5.esm.js} +1 -1
  23. package/dist/{create-postcss-config-381b636b.cjs.dev.js → create-postcss-config-73d94525.cjs.dev.js} +1 -1
  24. package/dist/{create-postcss-config-91c09596.cjs.prod.js → create-postcss-config-929430f6.cjs.prod.js} +1 -1
  25. package/dist/{create-webpack-config-for-development-488742b2.cjs.dev.js → create-webpack-config-for-development-3a6f3fac.cjs.dev.js} +2 -2
  26. package/dist/{create-webpack-config-for-development-37677a49.cjs.prod.js → create-webpack-config-for-development-4749aed7.cjs.prod.js} +2 -2
  27. package/dist/{create-webpack-config-for-development-df3f7f7f.esm.js → create-webpack-config-for-development-fb17e299.esm.js} +2 -2
  28. package/dist/{create-webpack-config-for-production-e22f78d2.esm.js → create-webpack-config-for-production-23f194fc.esm.js} +14 -14
  29. package/dist/{create-webpack-config-for-production-46d817cc.cjs.dev.js → create-webpack-config-for-production-b836a125.cjs.dev.js} +15 -15
  30. package/dist/{create-webpack-config-for-production-aad64e2a.cjs.prod.js → create-webpack-config-for-production-ee70e601.cjs.prod.js} +15 -15
  31. package/dist/{credentials-storage-0b89aa0e.cjs.prod.js → credentials-storage-6d592cd6.cjs.prod.js} +20 -2
  32. package/dist/{credentials-storage-cbb5c559.cjs.dev.js → credentials-storage-c4c5980e.cjs.dev.js} +20 -2
  33. package/dist/{credentials-storage-4464313c.esm.js → credentials-storage-fcc77fb6.esm.js} +20 -2
  34. package/dist/declarations/src/types.d.ts +4 -0
  35. package/dist/{deployment-previews-set-636fb1a3.cjs.prod.js → deployment-previews-set-46172936.cjs.prod.js} +3 -3
  36. package/dist/{deployment-previews-set-4edd48db.cjs.dev.js → deployment-previews-set-50752e76.cjs.dev.js} +3 -3
  37. package/dist/{deployment-previews-set-bbef95d2.esm.js → deployment-previews-set-e2c508a2.esm.js} +3 -3
  38. package/dist/{graphql-requests-23f7ddb1.cjs.dev.js → graphql-requests-79116775.cjs.dev.js} +2 -2
  39. package/dist/{graphql-requests-0a6eeb3a.cjs.prod.js → graphql-requests-9d9289e2.cjs.prod.js} +2 -2
  40. package/dist/{graphql-requests-14074b2b.esm.js → graphql-requests-c56947a9.esm.js} +3 -3
  41. package/dist/{login-a6fd5fbf.cjs.dev.js → login-2ae319b6.cjs.dev.js} +130 -11
  42. package/dist/{login-1b222f33.esm.js → login-66cf38b8.esm.js} +127 -10
  43. package/dist/{login-54ebae96.cjs.prod.js → login-fc126950.cjs.prod.js} +130 -11
  44. package/dist/{package-a34835d9.esm.js → package-0974229d.esm.js} +21 -11
  45. package/dist/{package-e1f7242c.cjs.prod.js → package-8d902e4f.cjs.dev.js} +21 -11
  46. package/dist/{package-d8b1f4c0.cjs.dev.js → package-f3555da1.cjs.prod.js} +21 -11
  47. package/dist/{start-0be8a294.cjs.prod.js → start-6233d44d.cjs.prod.js} +3 -3
  48. package/dist/{start-890895df.esm.js → start-6406e20a.esm.js} +3 -3
  49. package/dist/{start-37ec4a7e.cjs.dev.js → start-94c67c51.cjs.dev.js} +3 -3
  50. package/package.json +21 -11
  51. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
  52. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
  53. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
  54. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +4 -4
  55. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +4 -4
  56. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +4 -4
@@ -1,10 +1,10 @@
1
1
  import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
2
2
  import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
3
3
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
- import path from 'path';
4
+ import path$1 from 'path';
5
5
  import pluginGraphql from '@rollup/plugin-graphql';
6
6
  import pluginReact from '@vitejs/plugin-react';
7
- import fs from 'fs-extra';
7
+ import fs$1 from 'fs-extra';
8
8
  import { visualizer } from 'rollup-plugin-visualizer';
9
9
  import { build } from 'vite';
10
10
  import { analyzer } from 'vite-bundle-analyzer';
@@ -15,6 +15,9 @@ import { p as paths } from './paths-39f22b8b.esm.js';
15
15
  import { compile } from '@formatjs/cli-lib';
16
16
  import { createFilter } from '@rollup/pluginutils';
17
17
  import { g as getI18nMessageFormat, h as handleMessageCompilationError } from './i18n-message-complilation-21d3b0aa.esm.js';
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+ import { globSync } from 'glob';
18
21
  import { v as vitePluginSvgr } from './vite-plugin-svgr-de6ee7da.esm.js';
19
22
  import '@babel/runtime-corejs3/helpers/defineProperty';
20
23
  import '@babel/runtime-corejs3/helpers/slicedToArray';
@@ -32,7 +35,6 @@ import 'chalk';
32
35
  import '@babel/runtime-corejs3/core-js-stable/instance/find';
33
36
  import 'fs';
34
37
  import './does-file-exist-32618334.esm.js';
35
- import 'node:fs';
36
38
  import '@babel/runtime-corejs3/core-js-stable/object/values';
37
39
  import 'crypto';
38
40
  import '@babel/runtime-corejs3/core-js/instance/match-all';
@@ -91,25 +93,62 @@ function vitePluginI18nMessageCompilation() {
91
93
  };
92
94
  }
93
95
 
96
+ /**
97
+ * A simple Vite plugin to clean up files matching glob patterns after build.
98
+ * Replaces `vite-plugin-post-cleanup` to avoid the `inflight` vulnerability
99
+ * in its transitive dependencies.
100
+ */
101
+ function pluginPostCleanup(options) {
102
+ return {
103
+ name: 'vite-plugin-post-cleanup',
104
+ apply: 'build',
105
+ closeBundle() {
106
+ const outputDir = options.outputDir,
107
+ patterns = options.patterns,
108
+ verbose = options.verbose;
109
+ let totalFilesDeleted = 0;
110
+ for (const pattern of patterns) {
111
+ const files = globSync(pattern, {
112
+ cwd: outputDir
113
+ });
114
+ for (const file of files) {
115
+ const filePath = path.join(outputDir, file);
116
+ try {
117
+ fs.unlinkSync(filePath);
118
+ totalFilesDeleted++;
119
+ if (verbose) {
120
+ console.log(`[post-cleanup] Deleted: ${file}`);
121
+ }
122
+ } catch (error) {
123
+ console.warn(`[post-cleanup] Failed to delete ${file}:`, error);
124
+ }
125
+ }
126
+ }
127
+ if (verbose && patterns.length > 0 && totalFilesDeleted === 0) {
128
+ console.log('[post-cleanup] No files matched the patterns');
129
+ }
130
+ }
131
+ };
132
+ }
133
+
94
134
  async function run() {
95
135
  var _context;
96
- const CleanBuild = (await import('vite-plugin-clean-build')).default;
97
136
  const DEFAULT_PORT = _parseInt(String(process.env.HTTP_PORT), 10) || 3001;
98
137
 
99
138
  // Ensure the `/public` folder exists.
100
- fs.mkdirSync(paths.appBuild, {
139
+ fs$1.mkdirSync(paths.appBuild, {
101
140
  recursive: true
102
141
  });
103
142
 
104
143
  // Generate `index.html` (template).
105
- const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
144
+ const appEntryPoint = path$1.relative(paths.appRoot, paths.entryPoint);
106
145
  const html = generateTemplate({
107
146
  // Define the module entry point (path relative from the `/public` folder).
108
147
  // NOTE: that this is different from the development configuration.
109
148
  scriptImports: [`<script type="module" src="/${appEntryPoint}" defer></script>`]
110
149
  });
111
150
  // Write `index.html` (template) into the `/public` folder.
112
- fs.writeFileSync(paths.appIndexHtml, html, {
151
+ fs$1.writeFileSync(paths.appIndexHtml, html, {
113
152
  encoding: 'utf8'
114
153
  });
115
154
  const appDependencies = require(paths.appPackageJson).dependencies;
@@ -171,12 +210,11 @@ async function run() {
171
210
  // Enable pre-parse default `formatjs` messages into AST.
172
211
  // TODO: make it a CLI option when Vite support becomes stable.
173
212
  process.env.ENABLE_I18N_AST === 'true'
174
- }] : undefined]).call(_context, nonNullable)
213
+ }] : undefined, process.env.ENABLE_BABEL_REACT_COMPILER === 'true' ? 'babel-plugin-react-compiler' : undefined]).call(_context, nonNullable)
175
214
  }
176
215
  }),
177
- // cleanbuild is needed to remove large svg assets
178
- // that are not used after the build.
179
- CleanBuild({
216
+ // Clean up large SVG assets that are not used after the build.
217
+ pluginPostCleanup({
180
218
  outputDir: paths.appBuild,
181
219
  patterns: ['*.react-*.svg'],
182
220
  verbose: true // logs the files that are removed
@@ -190,17 +228,17 @@ async function run() {
190
228
  });
191
229
 
192
230
  // Rename `/public/public/index.html` to `/public/index.html.template`
193
- fs.renameSync(
231
+ fs$1.renameSync(
194
232
  // Because of our custom entry point path (`/public/index.html`),
195
233
  // Vite will write the `index.html` to `/public/public/index.html`.
196
234
  // We need to move this file to the `/public` folder and rename it
197
235
  // to `index.html.template` (as expected by the `compile-html` command).
198
- path.join(paths.appBuild, 'public/index.html'), paths.appIndexHtmlTemplate);
236
+ path$1.join(paths.appBuild, 'public/index.html'), paths.appIndexHtmlTemplate);
199
237
  // Clean up nested folder
200
- fs.rmdirSync(path.join(paths.appBuild, 'public'));
238
+ fs$1.rmdirSync(path$1.join(paths.appBuild, 'public'));
201
239
 
202
240
  // Copy public assets
203
- fs.copySync(path.join(packageLocation, 'html-page'), paths.appBuild, {
241
+ fs$1.copySync(path$1.join(packageLocation, 'html-page'), paths.appBuild, {
204
242
  dereference: true
205
243
  });
206
244
  }
@@ -3,10 +3,10 @@
3
3
  var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
4
4
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
5
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
- var path = require('path');
6
+ var path$1 = require('path');
7
7
  var pluginGraphql = require('@rollup/plugin-graphql');
8
8
  var pluginReact = require('@vitejs/plugin-react');
9
- var fs = require('fs-extra');
9
+ var fs$1 = require('fs-extra');
10
10
  var rollupPluginVisualizer = require('rollup-plugin-visualizer');
11
11
  var vite = require('vite');
12
12
  var viteBundleAnalyzer = require('vite-bundle-analyzer');
@@ -17,6 +17,9 @@ var paths = require('./paths-7768b440.cjs.prod.js');
17
17
  var cliLib = require('@formatjs/cli-lib');
18
18
  var pluginutils = require('@rollup/pluginutils');
19
19
  var i18nMessageComplilation = require('./i18n-message-complilation-7762da61.cjs.prod.js');
20
+ var fs = require('node:fs');
21
+ var path = require('node:path');
22
+ var glob = require('glob');
20
23
  var vitePluginSvgr = require('./vite-plugin-svgr-4034a834.cjs.prod.js');
21
24
  require('@babel/runtime-corejs3/helpers/defineProperty');
22
25
  require('@babel/runtime-corejs3/helpers/slicedToArray');
@@ -34,38 +37,21 @@ require('chalk');
34
37
  require('@babel/runtime-corejs3/core-js-stable/instance/find');
35
38
  require('fs');
36
39
  require('./does-file-exist-be53305d.cjs.prod.js');
37
- require('node:fs');
38
40
  require('@babel/runtime-corejs3/core-js-stable/object/values');
39
41
  require('crypto');
40
42
  require('@babel/runtime-corejs3/core-js/instance/match-all');
41
43
 
42
44
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
43
45
 
44
- function _interopNamespace(e) {
45
- if (e && e.__esModule) return e;
46
- var n = Object.create(null);
47
- if (e) {
48
- Object.keys(e).forEach(function (k) {
49
- if (k !== 'default') {
50
- var d = Object.getOwnPropertyDescriptor(e, k);
51
- Object.defineProperty(n, k, d.get ? d : {
52
- enumerable: true,
53
- get: function () { return e[k]; }
54
- });
55
- }
56
- });
57
- }
58
- n["default"] = e;
59
- return Object.freeze(n);
60
- }
61
-
62
46
  var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
63
47
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
64
48
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
65
- var path__default = /*#__PURE__*/_interopDefault(path);
49
+ var path__default$1 = /*#__PURE__*/_interopDefault(path$1);
66
50
  var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
67
51
  var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
52
+ var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
68
53
  var fs__default = /*#__PURE__*/_interopDefault(fs);
54
+ var path__default = /*#__PURE__*/_interopDefault(path);
69
55
 
70
56
  // Type guard to help with filtering arrays for nullish elements.
71
57
  function nonNullable(value) {
@@ -121,25 +107,62 @@ function vitePluginI18nMessageCompilation() {
121
107
  };
122
108
  }
123
109
 
110
+ /**
111
+ * A simple Vite plugin to clean up files matching glob patterns after build.
112
+ * Replaces `vite-plugin-post-cleanup` to avoid the `inflight` vulnerability
113
+ * in its transitive dependencies.
114
+ */
115
+ function pluginPostCleanup(options) {
116
+ return {
117
+ name: 'vite-plugin-post-cleanup',
118
+ apply: 'build',
119
+ closeBundle() {
120
+ const outputDir = options.outputDir,
121
+ patterns = options.patterns,
122
+ verbose = options.verbose;
123
+ let totalFilesDeleted = 0;
124
+ for (const pattern of patterns) {
125
+ const files = glob.globSync(pattern, {
126
+ cwd: outputDir
127
+ });
128
+ for (const file of files) {
129
+ const filePath = path__default["default"].join(outputDir, file);
130
+ try {
131
+ fs__default["default"].unlinkSync(filePath);
132
+ totalFilesDeleted++;
133
+ if (verbose) {
134
+ console.log(`[post-cleanup] Deleted: ${file}`);
135
+ }
136
+ } catch (error) {
137
+ console.warn(`[post-cleanup] Failed to delete ${file}:`, error);
138
+ }
139
+ }
140
+ }
141
+ if (verbose && patterns.length > 0 && totalFilesDeleted === 0) {
142
+ console.log('[post-cleanup] No files matched the patterns');
143
+ }
144
+ }
145
+ };
146
+ }
147
+
124
148
  async function run() {
125
149
  var _context;
126
- const CleanBuild = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('vite-plugin-clean-build')); })).default;
127
150
  const DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001;
128
151
 
129
152
  // Ensure the `/public` folder exists.
130
- fs__default["default"].mkdirSync(paths.paths.appBuild, {
153
+ fs__default$1["default"].mkdirSync(paths.paths.appBuild, {
131
154
  recursive: true
132
155
  });
133
156
 
134
157
  // Generate `index.html` (template).
135
- const appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
158
+ const appEntryPoint = path__default$1["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
136
159
  const html = mcHtmlTemplate.generateTemplate({
137
160
  // Define the module entry point (path relative from the `/public` folder).
138
161
  // NOTE: that this is different from the development configuration.
139
162
  scriptImports: [`<script type="module" src="/${appEntryPoint}" defer></script>`]
140
163
  });
141
164
  // Write `index.html` (template) into the `/public` folder.
142
- fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
165
+ fs__default$1["default"].writeFileSync(paths.paths.appIndexHtml, html, {
143
166
  encoding: 'utf8'
144
167
  });
145
168
  const appDependencies = require(paths.paths.appPackageJson).dependencies;
@@ -201,12 +224,11 @@ async function run() {
201
224
  // Enable pre-parse default `formatjs` messages into AST.
202
225
  // TODO: make it a CLI option when Vite support becomes stable.
203
226
  process.env.ENABLE_I18N_AST === 'true'
204
- }] : undefined]).call(_context, nonNullable)
227
+ }] : undefined, process.env.ENABLE_BABEL_REACT_COMPILER === 'true' ? 'babel-plugin-react-compiler' : undefined]).call(_context, nonNullable)
205
228
  }
206
229
  }),
207
- // cleanbuild is needed to remove large svg assets
208
- // that are not used after the build.
209
- CleanBuild({
230
+ // Clean up large SVG assets that are not used after the build.
231
+ pluginPostCleanup({
210
232
  outputDir: paths.paths.appBuild,
211
233
  patterns: ['*.react-*.svg'],
212
234
  verbose: true // logs the files that are removed
@@ -220,17 +242,17 @@ async function run() {
220
242
  });
221
243
 
222
244
  // Rename `/public/public/index.html` to `/public/index.html.template`
223
- fs__default["default"].renameSync(
245
+ fs__default$1["default"].renameSync(
224
246
  // Because of our custom entry point path (`/public/index.html`),
225
247
  // Vite will write the `index.html` to `/public/public/index.html`.
226
248
  // We need to move this file to the `/public` folder and rename it
227
249
  // to `index.html.template` (as expected by the `compile-html` command).
228
- path__default["default"].join(paths.paths.appBuild, 'public/index.html'), paths.paths.appIndexHtmlTemplate);
250
+ path__default$1["default"].join(paths.paths.appBuild, 'public/index.html'), paths.paths.appIndexHtmlTemplate);
229
251
  // Clean up nested folder
230
- fs__default["default"].rmdirSync(path__default["default"].join(paths.paths.appBuild, 'public'));
252
+ fs__default$1["default"].rmdirSync(path__default$1["default"].join(paths.paths.appBuild, 'public'));
231
253
 
232
254
  // Copy public assets
233
- fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
255
+ fs__default$1["default"].copySync(path__default$1["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
234
256
  dereference: true
235
257
  });
236
258
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var vendorsToTranspile = require('./vendors-to-transpile-6ab4ea06.cjs.dev.js');
6
6
 
7
7
  // NOTE: This string will be replaced on build time with the package version.
8
- var version = "25.1.0";
8
+ var version = "26.0.0";
9
9
 
10
10
  // These exports are deprecated.
11
11
 
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var vendorsToTranspile = require('./vendors-to-transpile-04a49d40.cjs.prod.js');
6
6
 
7
7
  // NOTE: This string will be replaced on build time with the package version.
8
- var version = "25.1.0";
8
+ var version = "26.0.0";
9
9
 
10
10
  // These exports are deprecated.
11
11
 
@@ -1,7 +1,7 @@
1
1
  export { v as vendorsToTranspile } from './vendors-to-transpile-7dc84a72.esm.js';
2
2
 
3
3
  // NOTE: This string will be replaced on build time with the package version.
4
- var version = "25.1.0";
4
+ var version = "26.0.0";
5
5
 
6
6
  // These exports are deprecated.
7
7
 
@@ -0,0 +1,265 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
4
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
5
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
6
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
7
+ var chalk = require('chalk');
8
+ var prompts = require('prompts');
9
+ var applicationConfig = require('@commercetools-frontend/application-config');
10
+ var configSyncHelpers = require('./config-sync-helpers-9bd96619.cjs.dev.js');
11
+ var credentialsStorage$1 = require('./credentials-storage-c4c5980e.cjs.dev.js');
12
+ var graphqlRequests = require('./graphql-requests-79116775.cjs.dev.js');
13
+ require('@babel/runtime-corejs3/core-js-stable/json/stringify');
14
+ require('lodash/omit');
15
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
16
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
17
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
18
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
19
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
20
+ require('@babel/runtime-corejs3/helpers/defineProperty');
21
+ require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
22
+ require('@babel/runtime-corejs3/core-js-stable/set');
23
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
24
+ require('@babel/runtime-corejs3/core-js-stable/instance/bind');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
26
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
27
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
28
+ require('@babel/runtime-corejs3/helpers/createClass');
29
+ require('@babel/runtime-corejs3/core-js-stable/date/now');
30
+ require('node:fs');
31
+ require('node:os');
32
+ require('node:path');
33
+ require('./does-file-exist-eb86baca.cjs.dev.js');
34
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
35
+ require('graphql');
36
+ require('graphql-request');
37
+ require('@commercetools-frontend/constants');
38
+ require('@commercetools/http-user-agent');
39
+ require('./package-8d902e4f.cjs.dev.js');
40
+
41
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
42
+
43
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
44
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
45
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
46
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
47
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
48
+
49
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
50
+ async function promptForOrganization(_ref) {
51
+ var _context;
52
+ let mcApiUrl = _ref.mcApiUrl,
53
+ applicationIdentifier = _ref.applicationIdentifier,
54
+ customViewId = _ref.customViewId,
55
+ entityType = _ref.entityType;
56
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
57
+ mcApiUrl,
58
+ applicationIdentifier,
59
+ customViewId
60
+ });
61
+ if (userOrganizations.total === 0) {
62
+ throw new Error(`It seems you are not an admin of any Organization. Please make sure to be part of the Administrators team of the Organization you want the ${entityType} to be configured to.`);
63
+ }
64
+ if (userOrganizations.total === 1) {
65
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
66
+ organization = _userOrganizations$re[0];
67
+ return {
68
+ id: organization.id,
69
+ name: organization.name
70
+ };
71
+ }
72
+ const organizationChoices = _mapInstanceProperty__default["default"](_context = userOrganizations.results).call(_context, organization => ({
73
+ title: organization.name,
74
+ value: organization.id
75
+ }));
76
+ const _await$prompts = await prompts__default["default"]({
77
+ type: 'select',
78
+ name: 'organizationId',
79
+ message: 'Select an Organization',
80
+ choices: organizationChoices,
81
+ initial: 0
82
+ }),
83
+ selectedOrganizationId = _await$prompts.organizationId;
84
+ if (!selectedOrganizationId) {
85
+ throw new Error(`No Organization selected, aborting.`);
86
+ }
87
+ const organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref2 => {
88
+ let value = _ref2.value;
89
+ return value === selectedOrganizationId;
90
+ }).title;
91
+ return {
92
+ id: selectedOrganizationId,
93
+ name: organizationName
94
+ };
95
+ }
96
+ async function confirmAction(_ref3) {
97
+ var _context2;
98
+ let message = _ref3.message,
99
+ dryRun = _ref3.dryRun,
100
+ dryRunMessage = _ref3.dryRunMessage;
101
+ const _await$prompts2 = await prompts__default["default"]({
102
+ type: 'text',
103
+ name: 'confirmation',
104
+ message: _filterInstanceProperty__default["default"](_context2 = [message, dryRun && chalk__default["default"].gray(dryRunMessage)]).call(_context2, Boolean).join('\n'),
105
+ initial: 'yes'
106
+ }),
107
+ confirmation = _await$prompts2.confirmation;
108
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
109
+ console.log(chalk__default["default"].red('Aborted.'));
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+ async function createOrUpdateCustomApplication(_ref4) {
115
+ let mcApiUrl = _ref4.mcApiUrl,
116
+ localCustomEntityData = _ref4.localCustomEntityData,
117
+ applicationIdentifier = _ref4.applicationIdentifier,
118
+ options = _ref4.options;
119
+ const status = await configSyncHelpers.checkCustomApplicationStatus({
120
+ mcApiUrl,
121
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
122
+ applicationIdentifier,
123
+ localCustomEntityData
124
+ });
125
+ if (!status.exists) {
126
+ // Create new Custom Application
127
+ const organization = await promptForOrganization({
128
+ mcApiUrl,
129
+ applicationIdentifier,
130
+ entityType: 'Custom Application'
131
+ });
132
+ const confirmed = await confirmAction({
133
+ message: `You are about to create a new Custom Application in the "${chalk__default["default"].green(organization.name)}" organization. Are you sure you want to proceed?`,
134
+ dryRun: options.dryRun,
135
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
136
+ });
137
+ if (!confirmed) return;
138
+ await configSyncHelpers.performCreateCustomApplication({
139
+ mcApiUrl,
140
+ organizationId: organization.id,
141
+ organizationName: organization.name,
142
+ localCustomEntityData,
143
+ applicationIdentifier,
144
+ dryRun: options.dryRun
145
+ });
146
+ return;
147
+ }
148
+
149
+ // Check for changes
150
+ if (!status.configDiff) {
151
+ console.log(chalk__default["default"].green(`Custom Application up-to-date.`));
152
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(status.link)}".`);
153
+ return;
154
+ }
155
+ console.log('Changes detected:');
156
+ console.log(status.configDiff);
157
+ console.log();
158
+ const confirmed = await confirmAction({
159
+ message: `You are about to update the Custom Application "${chalk__default["default"].green(localCustomEntityData.entryPointUriPath)}" with the changes above. Are you sure you want to proceed?`,
160
+ dryRun: options.dryRun,
161
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
162
+ });
163
+ if (!confirmed) return;
164
+ await configSyncHelpers.performUpdateCustomApplication({
165
+ mcApiUrl,
166
+ organizationId: status.organizationId,
167
+ applicationId: status.applicationId,
168
+ localCustomEntityData,
169
+ applicationIdentifier,
170
+ dryRun: options.dryRun
171
+ });
172
+ }
173
+ async function createOrUpdateCustomView(_ref5) {
174
+ let mcApiUrl = _ref5.mcApiUrl,
175
+ localCustomEntityData = _ref5.localCustomEntityData,
176
+ customViewId = _ref5.customViewId,
177
+ options = _ref5.options,
178
+ applicationIdentifier = _ref5.applicationIdentifier;
179
+ const status = await configSyncHelpers.checkCustomViewStatus({
180
+ mcApiUrl,
181
+ customViewId,
182
+ applicationIdentifier,
183
+ localCustomEntityData
184
+ });
185
+ if (!status.exists) {
186
+ // Create new Custom View
187
+ const organization = await promptForOrganization({
188
+ mcApiUrl,
189
+ applicationIdentifier,
190
+ customViewId,
191
+ entityType: 'Custom View'
192
+ });
193
+ const confirmed = await confirmAction({
194
+ message: `You are about to create a new Custom View in the "${chalk__default["default"].green(organization.name)}" organization. Are you sure you want to proceed?`,
195
+ dryRun: options.dryRun,
196
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
197
+ });
198
+ if (!confirmed) return;
199
+ await configSyncHelpers.performCreateCustomView({
200
+ mcApiUrl,
201
+ organizationId: organization.id,
202
+ organizationName: organization.name,
203
+ localCustomEntityData,
204
+ applicationIdentifier,
205
+ dryRun: options.dryRun
206
+ });
207
+ return;
208
+ }
209
+
210
+ // Check for changes
211
+ if (!status.configDiff) {
212
+ console.log(chalk__default["default"].green(`Custom View up-to-date.`));
213
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(status.link)}".`);
214
+ return;
215
+ }
216
+ console.log('Changes detected:');
217
+ console.log(status.configDiff);
218
+ console.log();
219
+ const confirmed = await confirmAction({
220
+ message: `You are about to update the Custom View "${chalk__default["default"].green(localCustomEntityData.defaultLabel)}" with the changes above. Are you sure you want to proceed?`,
221
+ dryRun: options.dryRun,
222
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
223
+ });
224
+ if (!confirmed) return;
225
+ await configSyncHelpers.performUpdateCustomView({
226
+ mcApiUrl,
227
+ organizationId: status.organizationId,
228
+ customViewId: status.customViewId,
229
+ localCustomEntityData,
230
+ applicationIdentifier,
231
+ dryRun: options.dryRun
232
+ });
233
+ }
234
+ async function run(options) {
235
+ const applicationConfig$1 = await applicationConfig.processConfig();
236
+ const localCustomEntityData = applicationConfig$1.data;
237
+ const _applicationConfig$en = applicationConfig$1.env,
238
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
239
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
240
+ customViewId = _applicationConfig$en.customViewId;
241
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
242
+ console.log();
243
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
244
+ if (!isSessionValid) {
245
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
246
+ }
247
+ if (configSyncHelpers.isCustomViewData(localCustomEntityData)) {
248
+ await createOrUpdateCustomView({
249
+ mcApiUrl,
250
+ localCustomEntityData,
251
+ applicationIdentifier,
252
+ customViewId: customViewId || localCustomEntityData.id,
253
+ options
254
+ });
255
+ } else {
256
+ await createOrUpdateCustomApplication({
257
+ mcApiUrl,
258
+ localCustomEntityData,
259
+ applicationIdentifier,
260
+ options
261
+ });
262
+ }
263
+ }
264
+
265
+ exports["default"] = run;