@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.
- package/README.md +23 -0
- package/cli/dist/commercetools-frontend-application-cli-cli.cjs.dev.js +190 -92
- package/cli/dist/commercetools-frontend-application-cli-cli.cjs.prod.js +190 -92
- package/cli/dist/commercetools-frontend-application-cli-cli.esm.js +189 -91
- package/dist/commercetools-frontend-application-cli.cjs.d.ts +2 -0
- package/dist/commercetools-frontend-application-cli.cjs.d.ts.map +1 -0
- package/dist/commercetools-frontend-application-cli.cjs.dev.js +2 -0
- package/dist/commercetools-frontend-application-cli.cjs.js +7 -0
- package/dist/commercetools-frontend-application-cli.cjs.prod.js +2 -0
- package/dist/commercetools-frontend-application-cli.esm.js +1 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +100 -0
- package/package.json +6 -5
|
@@ -13,9 +13,9 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
|
|
|
13
13
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
14
14
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
15
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
16
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
17
16
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
17
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
18
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
19
19
|
var fs = require('fs');
|
|
20
20
|
var path = require('path');
|
|
21
21
|
var listr2 = require('listr2');
|
|
@@ -41,9 +41,9 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
41
41
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
42
42
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
43
43
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
44
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
45
44
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
46
45
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
46
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
47
47
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
48
48
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
49
49
|
var execa__default = /*#__PURE__*/_interopDefault(execa);
|
|
@@ -67,29 +67,104 @@ function isCI() {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
function createApplicationIndexUploadScript(_ref) {
|
|
70
|
-
var _context, _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
|
|
71
70
|
let packageManagerName = _ref.packageManagerName,
|
|
72
71
|
bucketUrl = _ref.bucketUrl,
|
|
73
72
|
cdnUrl = _ref.cdnUrl,
|
|
74
|
-
|
|
73
|
+
bucketEnvironment = _ref.bucketEnvironment,
|
|
75
74
|
buildRevision = _ref.buildRevision,
|
|
76
75
|
buildNumber = _ref.buildNumber,
|
|
77
76
|
applicationIndexOutFile = _ref.applicationIndexOutFile;
|
|
78
|
-
const uploadScriptContent =
|
|
77
|
+
const uploadScriptContent = `#!/usr/bin/env bash
|
|
78
|
+
|
|
79
|
+
set -e
|
|
80
|
+
|
|
81
|
+
echo "Uploading compiled ${applicationIndexOutFile} to bucket ${bucketUrl}"
|
|
82
|
+
gcloud storage cp \\
|
|
83
|
+
"$(dirname "$0")/${applicationIndexOutFile}" \\
|
|
84
|
+
"${bucketUrl}/" \\
|
|
85
|
+
-z html \\
|
|
86
|
+
--content-type="text/html" \\
|
|
87
|
+
--cache-control="public,max-age=0,no-transform"
|
|
88
|
+
|
|
89
|
+
echo "Creating version.json and uploading it to bucket ${bucketUrl}"
|
|
90
|
+
|
|
91
|
+
NODE_ENV=production ${packageManagerName} application-cli create-version \\
|
|
92
|
+
--version-url=${cdnUrl}/${bucketEnvironment}/version.json \\
|
|
93
|
+
--build-revision=${buildRevision} \\
|
|
94
|
+
--build-number=${buildNumber} \\
|
|
95
|
+
--out-file=$(dirname "$0")/version.json
|
|
96
|
+
|
|
97
|
+
gcloud storage cp \\
|
|
98
|
+
"$(dirname "$0")/version.json" \\
|
|
99
|
+
"${bucketUrl}/" \\
|
|
100
|
+
-z json \\
|
|
101
|
+
--content-type="application/json" \\
|
|
102
|
+
--cache-control="public,max-age=0,no-transform"
|
|
103
|
+
`;
|
|
79
104
|
return uploadScriptContent;
|
|
80
105
|
}
|
|
81
106
|
|
|
82
107
|
function createApplicationAssetsUploadScript(_ref) {
|
|
83
|
-
var _context, _context2, _context3, _context4, _context5, _context6;
|
|
84
108
|
let bucketUrl = _ref.bucketUrl,
|
|
85
109
|
assetsPath = _ref.assetsPath,
|
|
86
110
|
skipMenu = _ref.skipMenu;
|
|
87
|
-
const uploadScriptContent =
|
|
111
|
+
const uploadScriptContent = `#!/usr/bin/env bash
|
|
112
|
+
|
|
113
|
+
set -e
|
|
114
|
+
|
|
115
|
+
# NOTES:
|
|
116
|
+
# https://cloud.google.com/sdk/gcloud/reference/storage/cp
|
|
117
|
+
# 1. The '-z' option triggers compressing the assets before
|
|
118
|
+
# uploading them and sets the 'Content-Encoding' to 'gzip'.
|
|
119
|
+
# 2. The 'Accept-encoding: gzip' is set automatically by the 'gcloud storage'.
|
|
120
|
+
# 3. The 'max-age' is set to 1 year which is considered the maximum
|
|
121
|
+
# "valid" lifetime of an asset to be cached.
|
|
122
|
+
# 4. The '-n' will skip uploading existing files and prevents them to
|
|
123
|
+
# be overwritten
|
|
124
|
+
echo "Uploading static assets to bucket ${bucketUrl}"
|
|
125
|
+
|
|
126
|
+
gcloud storage cp \\
|
|
127
|
+
${assetsPath}/public/{*.css,*.js,*.js.map,*.png,*.html,robots.txt} \\
|
|
128
|
+
"${bucketUrl}" \\
|
|
129
|
+
-n \\
|
|
130
|
+
-z js,css \\
|
|
131
|
+
--cache-control="public,max-age=31536000,no-transform"
|
|
132
|
+
|
|
133
|
+
if ${skipMenu}; then
|
|
134
|
+
echo "Skipping menu.json upload"
|
|
135
|
+
else
|
|
136
|
+
echo "Uploading menu.json to bucket ${bucketUrl}"
|
|
137
|
+
# NOTE: somehow the 'cache-control:private' doesn't work.
|
|
138
|
+
# I mean, the file is uploaded with the correct metadata but when I fetch
|
|
139
|
+
# the file the response contains the header
|
|
140
|
+
# 'cache-control: public,max-age=31536000,no-transform', even though the
|
|
141
|
+
# documentation clearly states that by marking the header as 'private' will
|
|
142
|
+
# disable the cache (for publicly readable objects).
|
|
143
|
+
# https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#cache-control
|
|
144
|
+
# However, I found out that, by requesting the file with any RANDOM
|
|
145
|
+
# query parameter, will instruct the storage to return a 'fresh' object
|
|
146
|
+
# (without any cache control).
|
|
147
|
+
# Unofficial source: https://stackoverflow.com/a/49052895
|
|
148
|
+
# This seems to be the 'easiest' option to 'disable' the cache for public
|
|
149
|
+
# objects. Other alternative approaces are:
|
|
150
|
+
# * make the object private with some simple ACL (private objects are not cached)
|
|
151
|
+
# * suffix the file name with e.g. the git SHA, so we have different files
|
|
152
|
+
# for each upload ('index.html.template-\${CIRCLE_SHA1}'). The server knows
|
|
153
|
+
# the git SHA on runtime and can get the correct file when it starts.
|
|
154
|
+
# * find out why the 'private' cache control does not work
|
|
155
|
+
gcloud storage cp \\
|
|
156
|
+
${assetsPath}/menu.json \\
|
|
157
|
+
${bucketUrl} \\
|
|
158
|
+
-z json \\
|
|
159
|
+
--content-type="application/json" \\
|
|
160
|
+
--cache-control="public,max-age=0,no-transform"
|
|
161
|
+
fi
|
|
162
|
+
`;
|
|
88
163
|
return uploadScriptContent;
|
|
89
164
|
}
|
|
90
165
|
|
|
91
166
|
function ownKeys$3(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
92
|
-
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
167
|
+
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__default["default"](_context = ownKeys$3(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$3(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
93
168
|
function loadDotenvFiles(_ref) {
|
|
94
169
|
let dotenvPath = _ref.dotenvPath,
|
|
95
170
|
cloudEnvironment = _ref.cloudEnvironment;
|
|
@@ -100,12 +175,12 @@ function loadDotenvFiles(_ref) {
|
|
|
100
175
|
|
|
101
176
|
// Check if the given path exists.
|
|
102
177
|
if (!fs__default["default"].existsSync(dotenvPath)) {
|
|
103
|
-
throw new Error(
|
|
178
|
+
throw new Error(`The dotenv folder path does not exist: "${dotenvPath}".`);
|
|
104
179
|
}
|
|
105
180
|
|
|
106
181
|
// Load the environment values
|
|
107
182
|
const sharedDotenvFile = '.env.production';
|
|
108
|
-
const cloudDotenvFile =
|
|
183
|
+
const cloudDotenvFile = `.env.${cloudEnvironment}`;
|
|
109
184
|
|
|
110
185
|
// The shared dotenv file across environments is optional
|
|
111
186
|
const sharedProductionEnvironment = dotenv__default["default"].config({
|
|
@@ -117,19 +192,23 @@ function loadDotenvFiles(_ref) {
|
|
|
117
192
|
path: path__default["default"].join(dotenvPath, cloudDotenvFile)
|
|
118
193
|
});
|
|
119
194
|
if (cloudSpecificProductionEnvironment.error) {
|
|
120
|
-
|
|
121
|
-
throw new Error(_concatInstanceProperty__default["default"](_context = "Failed loading '".concat(cloudDotenvFile, "' in '")).call(_context, dotenvPath, "'. Make sure it exists."));
|
|
195
|
+
throw new Error(`Failed loading '${cloudDotenvFile}' in '${dotenvPath}'. Make sure it exists.`);
|
|
122
196
|
}
|
|
123
197
|
if (sharedProductionEnvironment.error) {
|
|
124
|
-
|
|
125
|
-
throw new Error(_concatInstanceProperty__default["default"](_context2 = "Failed loading '".concat(sharedDotenvFile, "' in '")).call(_context2, dotenvPath, "'. Make sure it exists."));
|
|
198
|
+
throw new Error(`Failed loading '${sharedDotenvFile}' in '${dotenvPath}'. Make sure it exists.`);
|
|
126
199
|
}
|
|
127
200
|
return _objectSpread$3(_objectSpread$3({}, sharedProductionEnvironment.parsed), cloudSpecificProductionEnvironment.parsed);
|
|
128
201
|
}
|
|
129
202
|
|
|
130
203
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
131
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
204
|
+
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__default["default"](_context5 = ownKeys$2(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys$2(Object(t))).call(_context6, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
132
205
|
const buckedConfigExplorer = cosmiconfig.cosmiconfig('google-storage-buckets');
|
|
206
|
+
function assertCollapsedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment) {
|
|
207
|
+
return typeof bucketEnvironmentConfigOrBucketEnvironment == 'string';
|
|
208
|
+
}
|
|
209
|
+
function assertExpandedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment) {
|
|
210
|
+
return typeof bucketEnvironmentConfigOrBucketEnvironment == 'object' && typeof bucketEnvironmentConfigOrBucketEnvironment.cloudEnvironment == 'string' && typeof bucketEnvironmentConfigOrBucketEnvironment.bucketEnvironment == 'string';
|
|
211
|
+
}
|
|
133
212
|
function writeUploadScriptFile(_ref) {
|
|
134
213
|
let fileName = _ref.fileName,
|
|
135
214
|
fileContent = _ref.fileContent,
|
|
@@ -143,7 +222,7 @@ function writeUploadScriptFile(_ref) {
|
|
|
143
222
|
function getBucketNamespace(prNumber) {
|
|
144
223
|
if (!prNumber) return;
|
|
145
224
|
if (prNumber === 'merchant-center-preview') return prNumber;
|
|
146
|
-
return
|
|
225
|
+
return `mc-${prNumber}`;
|
|
147
226
|
}
|
|
148
227
|
|
|
149
228
|
/**
|
|
@@ -161,32 +240,30 @@ function getApplicationAssetsBucketUrl(_ref2) {
|
|
|
161
240
|
let bucketRegion = _ref2.bucketRegion,
|
|
162
241
|
prNumber = _ref2.prNumber,
|
|
163
242
|
applicationName = _ref2.applicationName;
|
|
164
|
-
const applicationAssetsBucketUrl = _filterInstanceProperty__default["default"](_context = [
|
|
243
|
+
const applicationAssetsBucketUrl = _filterInstanceProperty__default["default"](_context = [`gs://${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context, Boolean);
|
|
165
244
|
return applicationAssetsBucketUrl.join('/');
|
|
166
245
|
}
|
|
167
246
|
function getApplicationIndexBucketUrl(_ref3) {
|
|
168
|
-
var _context2;
|
|
169
247
|
let bucketRegion = _ref3.bucketRegion,
|
|
170
248
|
prNumber = _ref3.prNumber,
|
|
171
249
|
applicationName = _ref3.applicationName,
|
|
172
|
-
|
|
250
|
+
bucketEnvironment = _ref3.bucketEnvironment;
|
|
173
251
|
const applicationAssetsBucketUrl = getApplicationAssetsBucketUrl({
|
|
174
252
|
bucketRegion,
|
|
175
253
|
prNumber,
|
|
176
254
|
applicationName
|
|
177
255
|
});
|
|
178
|
-
const applicationIndexBucketUrl =
|
|
256
|
+
const applicationIndexBucketUrl = `${applicationAssetsBucketUrl}/${bucketEnvironment}`;
|
|
179
257
|
return applicationIndexBucketUrl;
|
|
180
258
|
}
|
|
181
259
|
function getCdnUrl(_ref4) {
|
|
182
|
-
var
|
|
260
|
+
var _context2;
|
|
183
261
|
let bucketRegion = _ref4.bucketRegion,
|
|
184
262
|
prNumber = _ref4.prNumber,
|
|
185
263
|
applicationName = _ref4.applicationName;
|
|
186
|
-
return _filterInstanceProperty__default["default"](
|
|
264
|
+
return _filterInstanceProperty__default["default"](_context2 = [`https://storage.googleapis.com/${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context2, Boolean).join('/');
|
|
187
265
|
}
|
|
188
266
|
async function compileApplicationAssets(_ref5) {
|
|
189
|
-
var _context4, _context5;
|
|
190
267
|
let cliFlags = _ref5.cliFlags,
|
|
191
268
|
bucketRegion = _ref5.bucketRegion,
|
|
192
269
|
paths = _ref5.paths;
|
|
@@ -200,7 +277,7 @@ async function compileApplicationAssets(_ref5) {
|
|
|
200
277
|
skipMenu: cliFlags.skipMenu
|
|
201
278
|
});
|
|
202
279
|
const parsedApplicationAssetsUploadScriptFile = path__default["default"].parse(cliFlags.applicationAssetsUploadScriptOutFile);
|
|
203
|
-
const applicationAssetsUploadScriptFileName =
|
|
280
|
+
const applicationAssetsUploadScriptFileName = `${parsedApplicationAssetsUploadScriptFile.name}-${bucketRegion}${parsedApplicationAssetsUploadScriptFile.ext}`;
|
|
204
281
|
writeUploadScriptFile({
|
|
205
282
|
fileName: applicationAssetsUploadScriptFileName,
|
|
206
283
|
fileContent: applicationAssetsUploadScriptContent,
|
|
@@ -211,7 +288,8 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
211
288
|
let cliFlags = _ref6.cliFlags,
|
|
212
289
|
paths = _ref6.paths,
|
|
213
290
|
bucketRegion = _ref6.bucketRegion,
|
|
214
|
-
cloudEnvironment = _ref6.cloudEnvironment
|
|
291
|
+
cloudEnvironment = _ref6.cloudEnvironment,
|
|
292
|
+
bucketEnvironment = _ref6.bucketEnvironment;
|
|
215
293
|
const cloudEnvironmentDeploymentPath = path__default["default"].join(paths.deploymentsPath, cloudEnvironment);
|
|
216
294
|
// Ensure the folder exists
|
|
217
295
|
const createDeploymentsFolderResult = await execa__default["default"]('mkdir', ['-p', cloudEnvironmentDeploymentPath], {
|
|
@@ -233,7 +311,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
233
311
|
})), {}, {
|
|
234
312
|
// The trailing slash is important to indicate to the CSP directive that all the resources
|
|
235
313
|
// under that path should be allowed.
|
|
236
|
-
MC_CDN_URL:
|
|
314
|
+
MC_CDN_URL: `${cdnUrl}/`
|
|
237
315
|
}, cliFlags.mcUrl ? {
|
|
238
316
|
MC_URL: cliFlags.mcUrl
|
|
239
317
|
} : {}), cliFlags.mcApiUrl ? {
|
|
@@ -271,10 +349,10 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
271
349
|
bucketRegion,
|
|
272
350
|
prNumber: cliFlags.prNumber,
|
|
273
351
|
applicationName: cliFlags.applicationName,
|
|
274
|
-
|
|
352
|
+
bucketEnvironment
|
|
275
353
|
}),
|
|
276
354
|
cdnUrl,
|
|
277
|
-
|
|
355
|
+
bucketEnvironment,
|
|
278
356
|
buildRevision: cliFlags.buildRevision,
|
|
279
357
|
buildNumber: cliFlags.buildNumber,
|
|
280
358
|
applicationIndexOutFile: cliFlags.applicationIndexOutFile
|
|
@@ -295,7 +373,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
295
373
|
}
|
|
296
374
|
}
|
|
297
375
|
async function command$3(cliFlags, cwd) {
|
|
298
|
-
var
|
|
376
|
+
var _context3;
|
|
299
377
|
let cloudEnvironmentsGroupedByBucketRegions;
|
|
300
378
|
try {
|
|
301
379
|
// This is the list of the supported cloud environments and their related bucket location.
|
|
@@ -320,24 +398,36 @@ async function command$3(cliFlags, cwd) {
|
|
|
320
398
|
dotenvPath: cliFlags.dotenvFolder && path__default["default"].join(monorepoRoot.rootDir, cliFlags.dotenvFolder),
|
|
321
399
|
assetsPath
|
|
322
400
|
};
|
|
323
|
-
const taskList = new listr2.Listr(_mapInstanceProperty__default["default"](
|
|
401
|
+
const taskList = new listr2.Listr(_mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](cloudEnvironmentsGroupedByBucketRegions.config)).call(_context3, _ref7 => {
|
|
324
402
|
let _ref8 = _slicedToArray(_ref7, 2),
|
|
325
403
|
bucketRegion = _ref8[0],
|
|
326
|
-
|
|
404
|
+
bucketEnvironmentConfigs = _ref8[1];
|
|
327
405
|
return {
|
|
328
|
-
title:
|
|
406
|
+
title: `Compiling for bucket region ${bucketRegion}`,
|
|
329
407
|
task: () => {
|
|
330
|
-
var
|
|
331
|
-
return new listr2.Listr(_concatInstanceProperty__default["default"](
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
408
|
+
var _context4;
|
|
409
|
+
return new listr2.Listr(_concatInstanceProperty__default["default"](_context4 = _mapInstanceProperty__default["default"](bucketEnvironmentConfigs).call(bucketEnvironmentConfigs, bucketEnvironmentConfigOrBucketEnvironment => {
|
|
410
|
+
let cloudEnvironment = '';
|
|
411
|
+
let bucketEnvironment = '';
|
|
412
|
+
if (assertExpandedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment)) {
|
|
413
|
+
cloudEnvironment = bucketEnvironmentConfigOrBucketEnvironment.cloudEnvironment;
|
|
414
|
+
bucketEnvironment = bucketEnvironmentConfigOrBucketEnvironment.bucketEnvironment;
|
|
415
|
+
} else if (assertCollapsedBucketEnvironmentConfig(bucketEnvironmentConfigOrBucketEnvironment)) {
|
|
416
|
+
cloudEnvironment = bucketEnvironmentConfigOrBucketEnvironment;
|
|
417
|
+
bucketEnvironment = bucketEnvironmentConfigOrBucketEnvironment;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
title: `Compiling application index for environment ${cloudEnvironment} and bucket ${bucketEnvironment}`,
|
|
421
|
+
task: () => compileEnvironmentApplicationIndexes({
|
|
422
|
+
cliFlags,
|
|
423
|
+
paths,
|
|
424
|
+
bucketRegion,
|
|
425
|
+
cloudEnvironment,
|
|
426
|
+
bucketEnvironment
|
|
427
|
+
})
|
|
428
|
+
};
|
|
429
|
+
})).call(_context4, {
|
|
430
|
+
title: `Compiling application assets`,
|
|
341
431
|
task: () => compileApplicationAssets({
|
|
342
432
|
cliFlags,
|
|
343
433
|
bucketRegion,
|
|
@@ -382,60 +472,63 @@ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
|
|
|
382
472
|
*/
|
|
383
473
|
|
|
384
474
|
const mapApplicationMenuConfigToGraqhQLMenuJson = config => {
|
|
385
|
-
var
|
|
475
|
+
var _context2;
|
|
386
476
|
const entryPointUriPath = config.env.entryPointUriPath;
|
|
387
477
|
|
|
388
478
|
// @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
389
|
-
const accountLinks =
|
|
479
|
+
const accountLinks = config.env.__DEVELOPMENT__?.accountLinks ?? [];
|
|
390
480
|
if (accountLinks.length > 0) {
|
|
391
|
-
return _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
|
|
400
|
-
};
|
|
401
|
-
});
|
|
481
|
+
return _mapInstanceProperty__default["default"](accountLinks).call(accountLinks, menuLink => ({
|
|
482
|
+
key: menuLink.uriPath,
|
|
483
|
+
uriPath: menuLink.uriPath,
|
|
484
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLink.labelAllLocales, menuLink.defaultLabel),
|
|
485
|
+
permissions: menuLink.permissions ?? [],
|
|
486
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
487
|
+
featureToggle: menuLink.featureToggle ?? null
|
|
488
|
+
}));
|
|
402
489
|
}
|
|
403
|
-
const menuLinks =
|
|
490
|
+
const menuLinks = config.env.__DEVELOPMENT__?.menuLinks;
|
|
404
491
|
return {
|
|
405
492
|
key: entryPointUriPath,
|
|
406
493
|
uriPath: entryPointUriPath,
|
|
407
494
|
icon: menuLinks.icon,
|
|
408
|
-
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks
|
|
495
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks?.labelAllLocales, menuLinks?.defaultLabel),
|
|
409
496
|
permissions: menuLinks.permissions,
|
|
410
497
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
411
|
-
featureToggle:
|
|
498
|
+
featureToggle: menuLinks.featureToggle ?? null,
|
|
412
499
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
413
|
-
menuVisibility:
|
|
500
|
+
menuVisibility: menuLinks.menuVisibility ?? null,
|
|
414
501
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
415
|
-
actionRights:
|
|
502
|
+
actionRights: menuLinks.actionRights ?? null,
|
|
416
503
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
417
|
-
dataFences:
|
|
418
|
-
submenu: _mapInstanceProperty__default["default"](_context2 = menuLinks.submenuLinks).call(_context2, submenuLink => {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
|
|
433
|
-
};
|
|
434
|
-
}),
|
|
504
|
+
dataFences: menuLinks.dataFences ?? null,
|
|
505
|
+
submenu: _mapInstanceProperty__default["default"](_context2 = menuLinks.submenuLinks).call(_context2, submenuLink => ({
|
|
506
|
+
key: submenuLink.uriPath.replace('/', '-'),
|
|
507
|
+
uriPath: submenuLink.uriPath,
|
|
508
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(submenuLink.labelAllLocales, submenuLink.defaultLabel),
|
|
509
|
+
permissions: submenuLink.permissions,
|
|
510
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
511
|
+
featureToggle: submenuLink.featureToggle ?? null,
|
|
512
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
513
|
+
menuVisibility: submenuLink.menuVisibility ?? null,
|
|
514
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
515
|
+
actionRights: submenuLink.actionRights ?? null,
|
|
516
|
+
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
517
|
+
dataFences: submenuLink.dataFences ?? null
|
|
518
|
+
})),
|
|
435
519
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
436
|
-
shouldRenderDivider:
|
|
520
|
+
shouldRenderDivider: menuLinks.shouldRenderDivider ?? false
|
|
437
521
|
};
|
|
438
522
|
};
|
|
523
|
+
|
|
524
|
+
// During the migration to the Naming Convention Record for Cloud Environments
|
|
525
|
+
// we need to gracefully use the non-compliant and compliant environment names
|
|
526
|
+
// for staging to avoid a breaking release of the CLI.
|
|
527
|
+
const doesCloudEnvironmentExist = _ref => {
|
|
528
|
+
let dotenvPath = _ref.dotenvPath,
|
|
529
|
+
cloudEnvironment = _ref.cloudEnvironment;
|
|
530
|
+
return fs__default["default"].existsSync(path__default["default"].join(dotenvPath ?? '', cloudEnvironment));
|
|
531
|
+
};
|
|
439
532
|
async function command$2(cliFlags, cwd) {
|
|
440
533
|
const applicationDirectory = getApplicationDirectory(cwd);
|
|
441
534
|
const monorepoRoot = findRoot.findRootSync(cwd);
|
|
@@ -444,7 +537,11 @@ async function command$2(cliFlags, cwd) {
|
|
|
444
537
|
dotenvPath,
|
|
445
538
|
// The env itself is not important for the menu. However, the application config
|
|
446
539
|
// uses environment placeholders and therefore we need to provide the variables for it.
|
|
447
|
-
|
|
540
|
+
// TODO: Remove after all repositories migrated to NCR.
|
|
541
|
+
cloudEnvironment: doesCloudEnvironmentExist({
|
|
542
|
+
dotenvPath,
|
|
543
|
+
cloudEnvironment: '.env.ctp_staging_gcp_europe-west1_v1'
|
|
544
|
+
}) ? 'ctp_staging_gcp_europe-west1_v1' : 'ctp-gcp-staging'
|
|
448
545
|
})), {}, {
|
|
449
546
|
// Again, make sure that the environment is "development", otherwise
|
|
450
547
|
// the menu config won't be available.
|
|
@@ -613,15 +710,15 @@ function validateMenu(menuJson) {
|
|
|
613
710
|
async function command(cliFlags) {
|
|
614
711
|
const menuJsonPath = cliFlags.inputFile;
|
|
615
712
|
const isAppbarMenu = cliFlags.navigation === 'top';
|
|
616
|
-
if (!menuJsonPath) throw new Error(
|
|
617
|
-
if (!fs__default["default"].existsSync(menuJsonPath)) throw new Error(
|
|
713
|
+
if (!menuJsonPath) throw new Error(`--input-file cannot be empty. please provide the path of compiled menu.json`);
|
|
714
|
+
if (!fs__default["default"].existsSync(menuJsonPath)) throw new Error(`The menu.json file doesn't exist: ${menuJsonPath}`);
|
|
618
715
|
const menuJson = fs__default["default"].readFileSync(menuJsonPath, 'utf-8');
|
|
619
716
|
return validateMenu(JSON.parse(menuJson), isAppbarMenu ? appbarMenuSchema : navbarMenuSchema);
|
|
620
717
|
}
|
|
621
718
|
|
|
622
719
|
var pkgJson = {
|
|
623
720
|
name: "@commercetools-frontend/application-cli",
|
|
624
|
-
version: "1.
|
|
721
|
+
version: "1.8.1",
|
|
625
722
|
description: "Internal CLI to manage Merchant Center application deployments across various environments.",
|
|
626
723
|
keywords: [
|
|
627
724
|
"commercetools",
|
|
@@ -646,9 +743,9 @@ var pkgJson = {
|
|
|
646
743
|
"@babel/core": "^7.22.11",
|
|
647
744
|
"@babel/runtime": "^7.21.0",
|
|
648
745
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
649
|
-
"@commercetools-frontend/application-config": "22.
|
|
650
|
-
"@commercetools-frontend/constants": "22.
|
|
651
|
-
"@commercetools-frontend/l10n": "22.
|
|
746
|
+
"@commercetools-frontend/application-config": "22.11.0",
|
|
747
|
+
"@commercetools-frontend/constants": "22.11.0",
|
|
748
|
+
"@commercetools-frontend/l10n": "22.11.0",
|
|
652
749
|
"@manypkg/find-root": "2.2.1",
|
|
653
750
|
cac: "^6.7.14",
|
|
654
751
|
cosmiconfig: "8.3.6",
|
|
@@ -673,7 +770,8 @@ var pkgJson = {
|
|
|
673
770
|
},
|
|
674
771
|
preconstruct: {
|
|
675
772
|
entrypoints: [
|
|
676
|
-
"./cli.ts"
|
|
773
|
+
"./cli.ts",
|
|
774
|
+
"./index.ts"
|
|
677
775
|
]
|
|
678
776
|
}
|
|
679
777
|
};
|
|
@@ -692,7 +790,7 @@ const run = async () => {
|
|
|
692
790
|
// Default command
|
|
693
791
|
cli.command('').usage('\n\n Compile deployments and menus and create versions for MC applications').action(cli.outputHelp);
|
|
694
792
|
const usageCompileDeployment = 'Compile the deployments for an application for all environments.';
|
|
695
|
-
cli.command('compile-deployments', usageCompileDeployment).usage(
|
|
793
|
+
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.', {
|
|
696
794
|
default: 'application.html'
|
|
697
795
|
}).option('--application-index-upload-script-out-file [path]', '(optional) The name of the the application index upload script file.', {
|
|
698
796
|
default: 'upload-index.sh'
|
|
@@ -704,15 +802,15 @@ const run = async () => {
|
|
|
704
802
|
await command$3(options, cwd);
|
|
705
803
|
});
|
|
706
804
|
const usageCompileMenu = 'Compile the menu links of an application into a `menu.json`. This is only required for internal applications';
|
|
707
|
-
cli.command('compile-menu', usageCompileMenu).usage(
|
|
805
|
+
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 => {
|
|
708
806
|
await command$2(options, cwd);
|
|
709
807
|
});
|
|
710
808
|
const usageValidateMenu = 'Validate compiled `menu.json` file';
|
|
711
|
-
cli.command('validate-menu', usageValidateMenu).usage(
|
|
809
|
+
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 => {
|
|
712
810
|
await command(options);
|
|
713
811
|
});
|
|
714
812
|
const usageCreateVersion = 'Output a JSON string about the information in the `version.json` for a deployment, including the updated list of rollbacks.';
|
|
715
|
-
cli.command('create-version', usageCreateVersion).usage(
|
|
813
|
+
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', {
|
|
716
814
|
default: 15
|
|
717
815
|
}).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 => {
|
|
718
816
|
await command$1(options);
|