@commercetools-frontend/application-cli 1.7.4 → 1.8.1

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.
@@ -9,9 +9,9 @@ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object
9
9
  import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
10
10
  import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
11
11
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
12
- import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
13
12
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
14
13
  import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
14
+ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
15
15
  import fs from 'fs';
16
16
  import path from 'path';
17
17
  import { Listr } from 'listr2';
@@ -41,29 +41,104 @@ function isCI() {
41
41
  }
42
42
 
43
43
  function createApplicationIndexUploadScript(_ref) {
44
- var _context, _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
45
44
  let packageManagerName = _ref.packageManagerName,
46
45
  bucketUrl = _ref.bucketUrl,
47
46
  cdnUrl = _ref.cdnUrl,
48
- cloudEnvironment = _ref.cloudEnvironment,
47
+ bucketEnvironment = _ref.bucketEnvironment,
49
48
  buildRevision = _ref.buildRevision,
50
49
  buildNumber = _ref.buildNumber,
51
50
  applicationIndexOutFile = _ref.applicationIndexOutFile;
52
- const uploadScriptContent = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = _concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = _concatInstanceProperty(_context9 = _concatInstanceProperty(_context10 = "#!/usr/bin/env bash\n\nset -e\n\necho \"Uploading compiled ".concat(applicationIndexOutFile, " to bucket ")).call(_context10, bucketUrl, "\"\ngcloud storage cp \\\n \"$(dirname \"$0\")/")).call(_context9, applicationIndexOutFile, "\" \\\n \"")).call(_context8, bucketUrl, "/\" \\\n -z html \\\n --content-type=\"text/html\" \\\n --cache-control=\"public,max-age=0,no-transform\"\n\necho \"Creating version.json and uploading it to bucket ")).call(_context7, bucketUrl, "\"\n\nNODE_ENV=production ")).call(_context6, packageManagerName, " application-cli create-version \\\n --version-url=")).call(_context5, cdnUrl, "/")).call(_context4, cloudEnvironment, "/version.json \\\n --build-revision=")).call(_context3, buildRevision, " \\\n --build-number=")).call(_context2, buildNumber, " \\\n --out-file=$(dirname \"$0\")/version.json\n\ngcloud storage cp \\\n \"$(dirname \"$0\")/version.json\" \\\n \"")).call(_context, bucketUrl, "/\" \\\n -z json \\\n --content-type=\"application/json\" \\\n --cache-control=\"public,max-age=0,no-transform\"\n");
51
+ const uploadScriptContent = `#!/usr/bin/env bash
52
+
53
+ set -e
54
+
55
+ echo "Uploading compiled ${applicationIndexOutFile} to bucket ${bucketUrl}"
56
+ gcloud storage cp \\
57
+ "$(dirname "$0")/${applicationIndexOutFile}" \\
58
+ "${bucketUrl}/" \\
59
+ -z html \\
60
+ --content-type="text/html" \\
61
+ --cache-control="public,max-age=0,no-transform"
62
+
63
+ echo "Creating version.json and uploading it to bucket ${bucketUrl}"
64
+
65
+ NODE_ENV=production ${packageManagerName} application-cli create-version \\
66
+ --version-url=${cdnUrl}/${bucketEnvironment}/version.json \\
67
+ --build-revision=${buildRevision} \\
68
+ --build-number=${buildNumber} \\
69
+ --out-file=$(dirname "$0")/version.json
70
+
71
+ gcloud storage cp \\
72
+ "$(dirname "$0")/version.json" \\
73
+ "${bucketUrl}/" \\
74
+ -z json \\
75
+ --content-type="application/json" \\
76
+ --cache-control="public,max-age=0,no-transform"
77
+ `;
53
78
  return uploadScriptContent;
54
79
  }
55
80
 
56
81
  function createApplicationAssetsUploadScript(_ref) {
57
- var _context, _context2, _context3, _context4, _context5, _context6;
58
82
  let bucketUrl = _ref.bucketUrl,
59
83
  assetsPath = _ref.assetsPath,
60
84
  skipMenu = _ref.skipMenu;
61
- const uploadScriptContent = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = _concatInstanceProperty(_context6 = "#!/usr/bin/env bash\n\nset -e\n\n# NOTES:\n# https://cloud.google.com/sdk/gcloud/reference/storage/cp\n# 1. The '-z' option triggers compressing the assets before\n# uploading them and sets the 'Content-Encoding' to 'gzip'.\n# 2. The 'Accept-encoding: gzip' is set automatically by the 'gcloud storage'.\n# 3. The 'max-age' is set to 1 year which is considered the maximum\n# \"valid\" lifetime of an asset to be cached.\n# 4. The '-n' will skip uploading existing files and prevents them to\n# be overwritten\necho \"Uploading static assets to bucket ".concat(bucketUrl, "\"\n\ngcloud storage cp \\\n ")).call(_context6, assetsPath, "/public/{*.css,*.js,*.js.map,*.png,*.html,robots.txt} \\\n \"")).call(_context5, bucketUrl, "\" \\\n -n \\\n -z js,css \\\n --cache-control=\"public,max-age=31536000,no-transform\"\n\nif ")).call(_context4, skipMenu, "; then\n echo \"Skipping menu.json upload\"\nelse\n echo \"Uploading menu.json to bucket ")).call(_context3, bucketUrl, "\"\n # NOTE: somehow the 'cache-control:private' doesn't work.\n # I mean, the file is uploaded with the correct metadata but when I fetch\n # the file the response contains the header\n # 'cache-control: public,max-age=31536000,no-transform', even though the\n # documentation clearly states that by marking the header as 'private' will\n # disable the cache (for publicly readable objects).\n # https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#cache-control\n # However, I found out that, by requesting the file with any RANDOM\n # query parameter, will instruct the storage to return a 'fresh' object\n # (without any cache control).\n # Unofficial source: https://stackoverflow.com/a/49052895\n # This seems to be the 'easiest' option to 'disable' the cache for public\n # objects. Other alternative approaces are:\n # * make the object private with some simple ACL (private objects are not cached)\n # * suffix the file name with e.g. the git SHA, so we have different files\n # for each upload ('index.html.template-${CIRCLE_SHA1}'). The server knows\n # the git SHA on runtime and can get the correct file when it starts.\n # * find out why the 'private' cache control does not work\n gcloud storage cp \\\n ")).call(_context2, assetsPath, "/menu.json \\\n ")).call(_context, bucketUrl, " \\\n -z json \\\n --content-type=\"application/json\" \\\n --cache-control=\"public,max-age=0,no-transform\"\nfi\n");
85
+ const uploadScriptContent = `#!/usr/bin/env bash
86
+
87
+ set -e
88
+
89
+ # NOTES:
90
+ # https://cloud.google.com/sdk/gcloud/reference/storage/cp
91
+ # 1. The '-z' option triggers compressing the assets before
92
+ # uploading them and sets the 'Content-Encoding' to 'gzip'.
93
+ # 2. The 'Accept-encoding: gzip' is set automatically by the 'gcloud storage'.
94
+ # 3. The 'max-age' is set to 1 year which is considered the maximum
95
+ # "valid" lifetime of an asset to be cached.
96
+ # 4. The '-n' will skip uploading existing files and prevents them to
97
+ # be overwritten
98
+ echo "Uploading static assets to bucket ${bucketUrl}"
99
+
100
+ gcloud storage cp \\
101
+ ${assetsPath}/public/{*.css,*.js,*.js.map,*.png,*.html,robots.txt} \\
102
+ "${bucketUrl}" \\
103
+ -n \\
104
+ -z js,css \\
105
+ --cache-control="public,max-age=31536000,no-transform"
106
+
107
+ if ${skipMenu}; then
108
+ echo "Skipping menu.json upload"
109
+ else
110
+ echo "Uploading menu.json to bucket ${bucketUrl}"
111
+ # NOTE: somehow the 'cache-control:private' doesn't work.
112
+ # I mean, the file is uploaded with the correct metadata but when I fetch
113
+ # the file the response contains the header
114
+ # 'cache-control: public,max-age=31536000,no-transform', even though the
115
+ # documentation clearly states that by marking the header as 'private' will
116
+ # disable the cache (for publicly readable objects).
117
+ # https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#cache-control
118
+ # However, I found out that, by requesting the file with any RANDOM
119
+ # query parameter, will instruct the storage to return a 'fresh' object
120
+ # (without any cache control).
121
+ # Unofficial source: https://stackoverflow.com/a/49052895
122
+ # This seems to be the 'easiest' option to 'disable' the cache for public
123
+ # objects. Other alternative approaces are:
124
+ # * make the object private with some simple ACL (private objects are not cached)
125
+ # * suffix the file name with e.g. the git SHA, so we have different files
126
+ # for each upload ('index.html.template-\${CIRCLE_SHA1}'). The server knows
127
+ # the git SHA on runtime and can get the correct file when it starts.
128
+ # * find out why the 'private' cache control does not work
129
+ gcloud storage cp \\
130
+ ${assetsPath}/menu.json \\
131
+ ${bucketUrl} \\
132
+ -z json \\
133
+ --content-type="application/json" \\
134
+ --cache-control="public,max-age=0,no-transform"
135
+ fi
136
+ `;
62
137
  return uploadScriptContent;
63
138
  }
64
139
 
65
140
  function ownKeys$3(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
66
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys$3(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys$3(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
141
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$3(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$3(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
67
142
  function loadDotenvFiles(_ref) {
68
143
  let dotenvPath = _ref.dotenvPath,
69
144
  cloudEnvironment = _ref.cloudEnvironment;
@@ -74,12 +149,12 @@ function loadDotenvFiles(_ref) {
74
149
 
75
150
  // Check if the given path exists.
76
151
  if (!fs.existsSync(dotenvPath)) {
77
- throw new Error("The dotenv folder path does not exist: \"".concat(dotenvPath, "\"."));
152
+ throw new Error(`The dotenv folder path does not exist: "${dotenvPath}".`);
78
153
  }
79
154
 
80
155
  // Load the environment values
81
156
  const sharedDotenvFile = '.env.production';
82
- const cloudDotenvFile = ".env.".concat(cloudEnvironment);
157
+ const cloudDotenvFile = `.env.${cloudEnvironment}`;
83
158
 
84
159
  // The shared dotenv file across environments is optional
85
160
  const sharedProductionEnvironment = dotenv.config({
@@ -91,19 +166,23 @@ function loadDotenvFiles(_ref) {
91
166
  path: path.join(dotenvPath, cloudDotenvFile)
92
167
  });
93
168
  if (cloudSpecificProductionEnvironment.error) {
94
- var _context;
95
- throw new Error(_concatInstanceProperty(_context = "Failed loading '".concat(cloudDotenvFile, "' in '")).call(_context, dotenvPath, "'. Make sure it exists."));
169
+ throw new Error(`Failed loading '${cloudDotenvFile}' in '${dotenvPath}'. Make sure it exists.`);
96
170
  }
97
171
  if (sharedProductionEnvironment.error) {
98
- var _context2;
99
- throw new Error(_concatInstanceProperty(_context2 = "Failed loading '".concat(sharedDotenvFile, "' in '")).call(_context2, dotenvPath, "'. Make sure it exists."));
172
+ throw new Error(`Failed loading '${sharedDotenvFile}' in '${dotenvPath}'. Make sure it exists.`);
100
173
  }
101
174
  return _objectSpread$3(_objectSpread$3({}, sharedProductionEnvironment.parsed), cloudSpecificProductionEnvironment.parsed);
102
175
  }
103
176
 
104
177
  function ownKeys$2(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
105
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context8 = ownKeys$2(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context9 = ownKeys$2(Object(t))).call(_context9, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
178
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context5, _context6; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context5 = ownKeys$2(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context6 = ownKeys$2(Object(t))).call(_context6, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
106
179
  const buckedConfigExplorer = cosmiconfig('google-storage-buckets');
180
+ function assertCollapsedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment) {
181
+ return typeof bucketEnvironmentConfigOrBucketEnvironment == 'string';
182
+ }
183
+ function assertExpandedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment) {
184
+ return typeof bucketEnvironmentConfigOrBucketEnvironment == 'object' && typeof bucketEnvironmentConfigOrBucketEnvironment.cloudEnvironment == 'string' && typeof bucketEnvironmentConfigOrBucketEnvironment.bucketEnvironment == 'string';
185
+ }
107
186
  function writeUploadScriptFile(_ref) {
108
187
  let fileName = _ref.fileName,
109
188
  fileContent = _ref.fileContent,
@@ -117,7 +196,7 @@ function writeUploadScriptFile(_ref) {
117
196
  function getBucketNamespace(prNumber) {
118
197
  if (!prNumber) return;
119
198
  if (prNumber === 'merchant-center-preview') return prNumber;
120
- return "mc-".concat(prNumber);
199
+ return `mc-${prNumber}`;
121
200
  }
122
201
 
123
202
  /**
@@ -135,32 +214,30 @@ function getApplicationAssetsBucketUrl(_ref2) {
135
214
  let bucketRegion = _ref2.bucketRegion,
136
215
  prNumber = _ref2.prNumber,
137
216
  applicationName = _ref2.applicationName;
138
- const applicationAssetsBucketUrl = _filterInstanceProperty(_context = ["gs://".concat(bucketRegion), getBucketNamespace(prNumber), applicationName]).call(_context, Boolean);
217
+ const applicationAssetsBucketUrl = _filterInstanceProperty(_context = [`gs://${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context, Boolean);
139
218
  return applicationAssetsBucketUrl.join('/');
140
219
  }
141
220
  function getApplicationIndexBucketUrl(_ref3) {
142
- var _context2;
143
221
  let bucketRegion = _ref3.bucketRegion,
144
222
  prNumber = _ref3.prNumber,
145
223
  applicationName = _ref3.applicationName,
146
- cloudEnvironment = _ref3.cloudEnvironment;
224
+ bucketEnvironment = _ref3.bucketEnvironment;
147
225
  const applicationAssetsBucketUrl = getApplicationAssetsBucketUrl({
148
226
  bucketRegion,
149
227
  prNumber,
150
228
  applicationName
151
229
  });
152
- const applicationIndexBucketUrl = _concatInstanceProperty(_context2 = "".concat(applicationAssetsBucketUrl, "/")).call(_context2, cloudEnvironment);
230
+ const applicationIndexBucketUrl = `${applicationAssetsBucketUrl}/${bucketEnvironment}`;
153
231
  return applicationIndexBucketUrl;
154
232
  }
155
233
  function getCdnUrl(_ref4) {
156
- var _context3;
234
+ var _context2;
157
235
  let bucketRegion = _ref4.bucketRegion,
158
236
  prNumber = _ref4.prNumber,
159
237
  applicationName = _ref4.applicationName;
160
- return _filterInstanceProperty(_context3 = ["https://storage.googleapis.com/".concat(bucketRegion), getBucketNamespace(prNumber), applicationName]).call(_context3, Boolean).join('/');
238
+ return _filterInstanceProperty(_context2 = [`https://storage.googleapis.com/${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context2, Boolean).join('/');
161
239
  }
162
240
  async function compileApplicationAssets(_ref5) {
163
- var _context4, _context5;
164
241
  let cliFlags = _ref5.cliFlags,
165
242
  bucketRegion = _ref5.bucketRegion,
166
243
  paths = _ref5.paths;
@@ -174,7 +251,7 @@ async function compileApplicationAssets(_ref5) {
174
251
  skipMenu: cliFlags.skipMenu
175
252
  });
176
253
  const parsedApplicationAssetsUploadScriptFile = path.parse(cliFlags.applicationAssetsUploadScriptOutFile);
177
- const applicationAssetsUploadScriptFileName = _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(parsedApplicationAssetsUploadScriptFile.name, "-")).call(_context5, bucketRegion)).call(_context4, parsedApplicationAssetsUploadScriptFile.ext);
254
+ const applicationAssetsUploadScriptFileName = `${parsedApplicationAssetsUploadScriptFile.name}-${bucketRegion}${parsedApplicationAssetsUploadScriptFile.ext}`;
178
255
  writeUploadScriptFile({
179
256
  fileName: applicationAssetsUploadScriptFileName,
180
257
  fileContent: applicationAssetsUploadScriptContent,
@@ -185,7 +262,8 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
185
262
  let cliFlags = _ref6.cliFlags,
186
263
  paths = _ref6.paths,
187
264
  bucketRegion = _ref6.bucketRegion,
188
- cloudEnvironment = _ref6.cloudEnvironment;
265
+ cloudEnvironment = _ref6.cloudEnvironment,
266
+ bucketEnvironment = _ref6.bucketEnvironment;
189
267
  const cloudEnvironmentDeploymentPath = path.join(paths.deploymentsPath, cloudEnvironment);
190
268
  // Ensure the folder exists
191
269
  const createDeploymentsFolderResult = await execa('mkdir', ['-p', cloudEnvironmentDeploymentPath], {
@@ -207,7 +285,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
207
285
  })), {}, {
208
286
  // The trailing slash is important to indicate to the CSP directive that all the resources
209
287
  // under that path should be allowed.
210
- MC_CDN_URL: "".concat(cdnUrl, "/")
288
+ MC_CDN_URL: `${cdnUrl}/`
211
289
  }, cliFlags.mcUrl ? {
212
290
  MC_URL: cliFlags.mcUrl
213
291
  } : {}), cliFlags.mcApiUrl ? {
@@ -245,10 +323,10 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
245
323
  bucketRegion,
246
324
  prNumber: cliFlags.prNumber,
247
325
  applicationName: cliFlags.applicationName,
248
- cloudEnvironment
326
+ bucketEnvironment
249
327
  }),
250
328
  cdnUrl,
251
- cloudEnvironment,
329
+ bucketEnvironment,
252
330
  buildRevision: cliFlags.buildRevision,
253
331
  buildNumber: cliFlags.buildNumber,
254
332
  applicationIndexOutFile: cliFlags.applicationIndexOutFile
@@ -269,7 +347,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
269
347
  }
270
348
  }
271
349
  async function command$3(cliFlags, cwd) {
272
- var _context6;
350
+ var _context3;
273
351
  let cloudEnvironmentsGroupedByBucketRegions;
274
352
  try {
275
353
  // This is the list of the supported cloud environments and their related bucket location.
@@ -294,24 +372,36 @@ async function command$3(cliFlags, cwd) {
294
372
  dotenvPath: cliFlags.dotenvFolder && path.join(monorepoRoot.rootDir, cliFlags.dotenvFolder),
295
373
  assetsPath
296
374
  };
297
- const taskList = new Listr(_mapInstanceProperty(_context6 = _Object$entries(cloudEnvironmentsGroupedByBucketRegions.config)).call(_context6, _ref7 => {
375
+ const taskList = new Listr(_mapInstanceProperty(_context3 = _Object$entries(cloudEnvironmentsGroupedByBucketRegions.config)).call(_context3, _ref7 => {
298
376
  let _ref8 = _slicedToArray(_ref7, 2),
299
377
  bucketRegion = _ref8[0],
300
- cloudEnvironments = _ref8[1];
378
+ bucketEnvironmentConfigs = _ref8[1];
301
379
  return {
302
- title: "Compiling application for bucket ".concat(bucketRegion),
380
+ title: `Compiling for bucket region ${bucketRegion}`,
303
381
  task: () => {
304
- var _context7;
305
- return new Listr(_concatInstanceProperty(_context7 = _mapInstanceProperty(cloudEnvironments).call(cloudEnvironments, cloudEnvironment => ({
306
- title: "Compiling ".concat(cloudEnvironment, " application index"),
307
- task: () => compileEnvironmentApplicationIndexes({
308
- cliFlags,
309
- paths,
310
- bucketRegion,
311
- cloudEnvironment
312
- })
313
- }))).call(_context7, {
314
- title: "Compiling application assets",
382
+ var _context4;
383
+ return new Listr(_concatInstanceProperty(_context4 = _mapInstanceProperty(bucketEnvironmentConfigs).call(bucketEnvironmentConfigs, bucketEnvironmentConfigOrBucketEnvironment => {
384
+ let cloudEnvironment = '';
385
+ let bucketEnvironment = '';
386
+ if (assertExpandedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment)) {
387
+ cloudEnvironment = bucketEnvironmentConfigOrBucketEnvironment.cloudEnvironment;
388
+ bucketEnvironment = bucketEnvironmentConfigOrBucketEnvironment.bucketEnvironment;
389
+ } else if (assertCollapsedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment)) {
390
+ cloudEnvironment = bucketEnvironmentConfigOrBucketEnvironment;
391
+ bucketEnvironment = bucketEnvironmentConfigOrBucketEnvironment;
392
+ }
393
+ return {
394
+ title: `Compiling application index for environment ${cloudEnvironment} and bucket ${bucketEnvironment}`,
395
+ task: () => compileEnvironmentApplicationIndexes({
396
+ cliFlags,
397
+ paths,
398
+ bucketRegion,
399
+ cloudEnvironment,
400
+ bucketEnvironment
401
+ })
402
+ };
403
+ })).call(_context4, {
404
+ title: `Compiling application assets`,
315
405
  task: () => compileApplicationAssets({
316
406
  cliFlags,
317
407
  bucketRegion,
@@ -356,60 +446,63 @@ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
356
446
  */
357
447
 
358
448
  const mapApplicationMenuConfigToGraqhQLMenuJson = config => {
359
- var _ref, _config$env$__DEVELOP, _config$env$__DEVELOP2, _menuLinks$featureTog, _menuLinks$menuVisibi, _menuLinks$actionRigh, _menuLinks$dataFences, _context2, _menuLinks$shouldRend;
449
+ var _context2;
360
450
  const entryPointUriPath = config.env.entryPointUriPath;
361
451
 
362
452
  // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
363
- const accountLinks = (_ref = (_config$env$__DEVELOP = config.env.__DEVELOPMENT__) === null || _config$env$__DEVELOP === void 0 ? void 0 : _config$env$__DEVELOP.accountLinks) !== null && _ref !== void 0 ? _ref : [];
453
+ const accountLinks = config.env.__DEVELOPMENT__?.accountLinks ?? [];
364
454
  if (accountLinks.length > 0) {
365
- return _mapInstanceProperty(accountLinks).call(accountLinks, menuLink => {
366
- var _menuLink$permissions, _menuLink$featureTogg;
367
- return {
368
- key: menuLink.uriPath,
369
- uriPath: menuLink.uriPath,
370
- labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
371
- permissions: (_menuLink$permissions = menuLink.permissions) !== null && _menuLink$permissions !== void 0 ? _menuLink$permissions : [],
372
- // @ts-ignore: not defined in schema, as it's only used internally.
373
- featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
374
- };
375
- });
455
+ return _mapInstanceProperty(accountLinks).call(accountLinks, menuLink => ({
456
+ key: menuLink.uriPath,
457
+ uriPath: menuLink.uriPath,
458
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
459
+ permissions: menuLink.permissions ?? [],
460
+ // @ts-ignore: not defined in schema, as it's only used internally.
461
+ featureToggle: menuLink.featureToggle ?? null
462
+ }));
376
463
  }
377
- const menuLinks = (_config$env$__DEVELOP2 = config.env.__DEVELOPMENT__) === null || _config$env$__DEVELOP2 === void 0 ? void 0 : _config$env$__DEVELOP2.menuLinks;
464
+ const menuLinks = config.env.__DEVELOPMENT__?.menuLinks;
378
465
  return {
379
466
  key: entryPointUriPath,
380
467
  uriPath: entryPointUriPath,
381
468
  icon: menuLinks.icon,
382
- labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks === null || menuLinks === void 0 ? void 0 : menuLinks.labelAllLocales, menuLinks === null || menuLinks === void 0 ? void 0 : menuLinks.defaultLabel),
469
+ labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks?.labelAllLocales, menuLinks?.defaultLabel),
383
470
  permissions: menuLinks.permissions,
384
471
  // @ts-ignore: not defined in schema, as it's only used internally.
385
- featureToggle: (_menuLinks$featureTog = menuLinks.featureToggle) !== null && _menuLinks$featureTog !== void 0 ? _menuLinks$featureTog : null,
472
+ featureToggle: menuLinks.featureToggle ?? null,
386
473
  // @ts-ignore: not defined in schema, as it's only used internally.
387
- menuVisibility: (_menuLinks$menuVisibi = menuLinks.menuVisibility) !== null && _menuLinks$menuVisibi !== void 0 ? _menuLinks$menuVisibi : null,
474
+ menuVisibility: menuLinks.menuVisibility ?? null,
388
475
  // @ts-ignore: not defined in schema, as it's only used internally.
389
- actionRights: (_menuLinks$actionRigh = menuLinks.actionRights) !== null && _menuLinks$actionRigh !== void 0 ? _menuLinks$actionRigh : null,
476
+ actionRights: menuLinks.actionRights ?? null,
390
477
  // @ts-ignore: not defined in schema, as it's only used internally.
391
- dataFences: (_menuLinks$dataFences = menuLinks.dataFences) !== null && _menuLinks$dataFences !== void 0 ? _menuLinks$dataFences : null,
392
- submenu: _mapInstanceProperty(_context2 = menuLinks.submenuLinks).call(_context2, submenuLink => {
393
- var _submenuLink$featureT, _submenuLink$menuVisi, _submenuLink$actionRi, _submenuLink$dataFenc;
394
- return {
395
- key: submenuLink.uriPath.replace('/', '-'),
396
- uriPath: submenuLink.uriPath,
397
- labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
398
- permissions: submenuLink.permissions,
399
- // @ts-ignore: not defined in schema, as it's only used internally.
400
- featureToggle: (_submenuLink$featureT = submenuLink.featureToggle) !== null && _submenuLink$featureT !== void 0 ? _submenuLink$featureT : null,
401
- // @ts-ignore: not defined in schema, as it's only used internally.
402
- menuVisibility: (_submenuLink$menuVisi = submenuLink.menuVisibility) !== null && _submenuLink$menuVisi !== void 0 ? _submenuLink$menuVisi : null,
403
- // @ts-ignore: not defined in schema, as it's only used internally.
404
- actionRights: (_submenuLink$actionRi = submenuLink.actionRights) !== null && _submenuLink$actionRi !== void 0 ? _submenuLink$actionRi : null,
405
- // @ts-ignore: not defined in schema, as it's only used internally.
406
- dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
407
- };
408
- }),
478
+ dataFences: menuLinks.dataFences ?? null,
479
+ submenu: _mapInstanceProperty(_context2 = menuLinks.submenuLinks).call(_context2, submenuLink => ({
480
+ key: submenuLink.uriPath.replace('/', '-'),
481
+ uriPath: submenuLink.uriPath,
482
+ labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
483
+ permissions: submenuLink.permissions,
484
+ // @ts-ignore: not defined in schema, as it's only used internally.
485
+ featureToggle: submenuLink.featureToggle ?? null,
486
+ // @ts-ignore: not defined in schema, as it's only used internally.
487
+ menuVisibility: submenuLink.menuVisibility ?? null,
488
+ // @ts-ignore: not defined in schema, as it's only used internally.
489
+ actionRights: submenuLink.actionRights ?? null,
490
+ // @ts-ignore: not defined in schema, as it's only used internally.
491
+ dataFences: submenuLink.dataFences ?? null
492
+ })),
409
493
  // @ts-ignore: not defined in schema, as it's only used internally.
410
- shouldRenderDivider: (_menuLinks$shouldRend = menuLinks.shouldRenderDivider) !== null && _menuLinks$shouldRend !== void 0 ? _menuLinks$shouldRend : false
494
+ shouldRenderDivider: menuLinks.shouldRenderDivider ?? false
411
495
  };
412
496
  };
497
+
498
+ // During the migration to the Naming Convention Record for Cloud Environments
499
+ // we need to gracefully use the non-compliant and compliant environment names
500
+ // for staging to avoid a breaking release of the CLI.
501
+ const doesCloudEnvironmentExist = _ref => {
502
+ let dotenvPath = _ref.dotenvPath,
503
+ cloudEnvironment = _ref.cloudEnvironment;
504
+ return fs.existsSync(path.join(dotenvPath ?? '', cloudEnvironment));
505
+ };
413
506
  async function command$2(cliFlags, cwd) {
414
507
  const applicationDirectory = getApplicationDirectory(cwd);
415
508
  const monorepoRoot = findRootSync(cwd);
@@ -418,7 +511,11 @@ async function command$2(cliFlags, cwd) {
418
511
  dotenvPath,
419
512
  // The env itself is not important for the menu. However, the application config
420
513
  // uses environment placeholders and therefore we need to provide the variables for it.
421
- cloudEnvironment: 'ctp-gcp-staging'
514
+ // TODO: Remove after all repositories migrated to NCR.
515
+ cloudEnvironment: doesCloudEnvironmentExist({
516
+ dotenvPath,
517
+ cloudEnvironment: '.env.ctp_staging_gcp_europe-west1_v1'
518
+ }) ? 'ctp_staging_gcp_europe-west1_v1' : 'ctp-gcp-staging'
422
519
  })), {}, {
423
520
  // Again, make sure that the environment is "development", otherwise
424
521
  // the menu config won't be available.
@@ -587,15 +684,15 @@ function validateMenu(menuJson) {
587
684
  async function command(cliFlags) {
588
685
  const menuJsonPath = cliFlags.inputFile;
589
686
  const isAppbarMenu = cliFlags.navigation === 'top';
590
- if (!menuJsonPath) throw new Error("--input-file cannot be empty. please provide the path of compiled menu.json");
591
- if (!fs.existsSync(menuJsonPath)) throw new Error("The menu.json file doesn't exist: ".concat(menuJsonPath));
687
+ if (!menuJsonPath) throw new Error(`--input-file cannot be empty. please provide the path of compiled menu.json`);
688
+ if (!fs.existsSync(menuJsonPath)) throw new Error(`The menu.json file doesn't exist: ${menuJsonPath}`);
592
689
  const menuJson = fs.readFileSync(menuJsonPath, 'utf-8');
593
690
  return validateMenu(JSON.parse(menuJson), isAppbarMenu ? appbarMenuSchema : navbarMenuSchema);
594
691
  }
595
692
 
596
693
  var pkgJson = {
597
694
  name: "@commercetools-frontend/application-cli",
598
- version: "1.7.4",
695
+ version: "1.8.1",
599
696
  description: "Internal CLI to manage Merchant Center application deployments across various environments.",
600
697
  keywords: [
601
698
  "commercetools",
@@ -620,9 +717,9 @@ var pkgJson = {
620
717
  "@babel/core": "^7.22.11",
621
718
  "@babel/runtime": "^7.21.0",
622
719
  "@babel/runtime-corejs3": "^7.21.0",
623
- "@commercetools-frontend/application-config": "22.9.1",
624
- "@commercetools-frontend/constants": "22.9.1",
625
- "@commercetools-frontend/l10n": "22.9.1",
720
+ "@commercetools-frontend/application-config": "22.11.0",
721
+ "@commercetools-frontend/constants": "22.11.0",
722
+ "@commercetools-frontend/l10n": "22.11.0",
626
723
  "@manypkg/find-root": "2.2.1",
627
724
  cac: "^6.7.14",
628
725
  cosmiconfig: "8.3.6",
@@ -647,7 +744,8 @@ var pkgJson = {
647
744
  },
648
745
  preconstruct: {
649
746
  entrypoints: [
650
- "./cli.ts"
747
+ "./cli.ts",
748
+ "./index.ts"
651
749
  ]
652
750
  }
653
751
  };
@@ -666,7 +764,7 @@ const run = async () => {
666
764
  // Default command
667
765
  cli.command('').usage('\n\n Compile deployments and menus and create versions for MC applications').action(cli.outputHelp);
668
766
  const usageCompileDeployment = 'Compile the deployments for an application for all environments.';
669
- cli.command('compile-deployments', usageCompileDeployment).usage("compile-deployments \n\n ".concat(usageCompileDeployment)).option('--application-name <string>', '(required) The name of the application being compiled for example application-products.').option('--dotenv-folder [string]', '(optional) The path to a folder containing a dotenv file ".env.production" and a cloud-environment specific dotenv file (for example ".env.gcp-production-eu"). Those values are parsed and merged together to be used by the `mc-scripts compile-html` command.').option('--pr-number [string]', '(optional) A pull request number determining a scoped storage bucket for the deployment. Please use it carefully.').option('--mc-url [string]', '(optional) The MC URL of the deployment. This is usually inferred from the env file and overwrites the value. Please use it carefully.').option('--mc-api-url [string]', '(optional) The MC API URL of the deployment. This is usually inferred from the env file and overwrites the value. Please use it carefully.').option('--application-index-out-file [path]', '(optional) The name of the application index file.', {
767
+ cli.command('compile-deployments', usageCompileDeployment).usage(`compile-deployments \n\n ${usageCompileDeployment}`).option('--application-name <string>', '(required) The name of the application being compiled for example application-products.').option('--dotenv-folder [string]', '(optional) The path to a folder containing a dotenv file ".env.production" and a cloud-environment specific dotenv file (for example ".env.gcp-production-eu"). Those values are parsed and merged together to be used by the `mc-scripts compile-html` command.').option('--pr-number [string]', '(optional) A pull request number determining a scoped storage bucket for the deployment. Please use it carefully.').option('--mc-url [string]', '(optional) The MC URL of the deployment. This is usually inferred from the env file and overwrites the value. Please use it carefully.').option('--mc-api-url [string]', '(optional) The MC API URL of the deployment. This is usually inferred from the env file and overwrites the value. Please use it carefully.').option('--application-index-out-file [path]', '(optional) The name of the application index file.', {
670
768
  default: 'application.html'
671
769
  }).option('--application-index-upload-script-out-file [path]', '(optional) The name of the the application index upload script file.', {
672
770
  default: 'upload-index.sh'
@@ -678,15 +776,15 @@ const run = async () => {
678
776
  await command$3(options, cwd);
679
777
  });
680
778
  const usageCompileMenu = 'Compile the menu links of an application into a `menu.json`. This is only required for internal applications';
681
- cli.command('compile-menu', usageCompileMenu).usage("compile-menu \n\n ".concat(usageCompileMenu)).option('--dotenv-folder [string]', '(optional) The path to a folder containing a dotenv file `.env.production` and a cloud-environment specific dotenv file (for example `.env.gcp-production-eu`). Those values are parsed and merged together to be used by the application config.').action(async options => {
779
+ cli.command('compile-menu', usageCompileMenu).usage(`compile-menu \n\n ${usageCompileMenu}`).option('--dotenv-folder [string]', '(optional) The path to a folder containing a dotenv file `.env.production` and a cloud-environment specific dotenv file (for example `.env.gcp-production-eu`). Those values are parsed and merged together to be used by the application config.').action(async options => {
682
780
  await command$2(options, cwd);
683
781
  });
684
782
  const usageValidateMenu = 'Validate compiled `menu.json` file';
685
- cli.command('validate-menu', usageValidateMenu).usage("validate-menu \n\n ".concat(usageValidateMenu)).option('--input-file <path>', '(required) The path to the `menu.json` file to be validated.').option('--navigation [string]', '(optional) Location of the menu navigation. Possible values are `top`.').action(async options => {
783
+ cli.command('validate-menu', usageValidateMenu).usage(`validate-menu \n\n ${usageValidateMenu}`).option('--input-file <path>', '(required) The path to the `menu.json` file to be validated.').option('--navigation [string]', '(optional) Location of the menu navigation. Possible values are `top`.').action(async options => {
686
784
  await command(options);
687
785
  });
688
786
  const usageCreateVersion = 'Output a JSON string about the information in the `version.json` for a deployment, including the updated list of rollbacks.';
689
- cli.command('create-version', usageCreateVersion).usage("create-version \n\n ".concat(usageCreateVersion)).option('--version-url <url>', "(required) The path of an application's current `version.json` within the storage bucket.").option('--rollbacks [int]', '(optional) The number of max rollbacks to keep', {
787
+ cli.command('create-version', usageCreateVersion).usage(`create-version \n\n ${usageCreateVersion}`).option('--version-url <url>', "(required) The path of an application's current `version.json` within the storage bucket.").option('--rollbacks [int]', '(optional) The number of max rollbacks to keep', {
690
788
  default: 15
691
789
  }).option('--out-file [path]', '(optional) The path to the file where to write the JSON. If not specified, the JSON is printed to stdout.').action(async options => {
692
790
  await command$1(options);
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index";
2
+ //# sourceMappingURL=commercetools-frontend-application-cli.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commercetools-frontend-application-cli.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-frontend-application-cli.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-frontend-application-cli.cjs.dev.js");
7
+ }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+ export type { TGoogleStorageBucketsConfig } from "./types.js";
@@ -0,0 +1,100 @@
1
+ export type TApplicationAssetsBucketConfig = {
2
+ bucketRegion: string;
3
+ prNumber?: string;
4
+ applicationName: string;
5
+ };
6
+ export type TApplicationIndexBucketConfig = {
7
+ bucketRegion: string;
8
+ prNumber?: string;
9
+ applicationName: string;
10
+ bucketEnvironment: string;
11
+ };
12
+ export type TUploadScriptFile = {
13
+ fileName: string;
14
+ fileContent: string;
15
+ filePath: string;
16
+ };
17
+ type TPaths = {
18
+ publicAssetsPath: string;
19
+ deploymentsPath: string;
20
+ dotenvPath?: string;
21
+ assetsPath: string;
22
+ };
23
+ export type TCompileEnvApplicationIndexes = {
24
+ cliFlags: TCompileDeploymentsFlags;
25
+ paths: TPaths;
26
+ bucketRegion: string;
27
+ cloudEnvironment: string;
28
+ bucketEnvironment: string;
29
+ };
30
+ export type TCompileApplicationAssets = {
31
+ cliFlags: TCompileDeploymentsFlags;
32
+ paths: TPaths;
33
+ bucketRegion: string;
34
+ };
35
+ type TBucketRegion = string;
36
+ export type TCollapsedBucketEnvironmentConfig = string;
37
+ export type TExpandedBucketEnvironmentConfig = {
38
+ cloudEnvironment: string;
39
+ bucketEnvironment: string;
40
+ };
41
+ export type TBucketEnvironmentConfig = TCollapsedBucketEnvironmentConfig | TExpandedBucketEnvironmentConfig;
42
+ export type TGoogleStorageBucketsConfig = {
43
+ [key: TBucketRegion]: TBucketEnvironmentConfig[];
44
+ };
45
+ export type TCosmiconfigResult = {
46
+ config: TGoogleStorageBucketsConfig;
47
+ };
48
+ export type TCreateApplicationIndexUploadScript = {
49
+ packageManagerName: string;
50
+ bucketUrl: string;
51
+ cdnUrl: string;
52
+ bucketEnvironment: string;
53
+ buildRevision: string;
54
+ buildNumber: number;
55
+ applicationIndexOutFile: string;
56
+ };
57
+ export type TCreateApplicationAssetsUploadScript = {
58
+ bucketUrl: string;
59
+ assetsPath: string;
60
+ skipMenu: boolean;
61
+ };
62
+ export type TLoadDotDev = {
63
+ dotenvPath?: string;
64
+ cloudEnvironment: string;
65
+ };
66
+ export type TLocalizedField = {
67
+ locale: string;
68
+ value: string;
69
+ };
70
+ export type TCompileDeploymentsFlags = {
71
+ applicationName: string;
72
+ buildRevision: string;
73
+ buildNumber: number;
74
+ dotenvFolder?: string;
75
+ prNumber?: string;
76
+ mcUrl?: string;
77
+ mcApiUrl?: string;
78
+ applicationIndexOutFile: string;
79
+ applicationIndexUploadScriptOutFile: string;
80
+ applicationAssetsUploadScriptOutFile: string;
81
+ ciAssetsRootPath?: string;
82
+ packageManagerName: string;
83
+ skipMenu: boolean;
84
+ };
85
+ export type TCompileMenuFlags = {
86
+ dotenvFolder?: string;
87
+ };
88
+ export type TCreateVersionFlags = {
89
+ versionUrl: string;
90
+ buildRevision: string;
91
+ buildNumber: number;
92
+ rollbacks: number;
93
+ outFile?: string;
94
+ packageManagerName: string;
95
+ };
96
+ export type TValidateMenuFlags = {
97
+ inputFile: string;
98
+ navigation?: string;
99
+ };
100
+ export {};