@commercetools-frontend/application-cli 1.7.3 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/cli/dist/commercetools-frontend-application-cli-cli.cjs.dev.js +177 -91
- package/cli/dist/commercetools-frontend-application-cli-cli.cjs.prod.js +177 -91
- package/cli/dist/commercetools-frontend-application-cli-cli.esm.js +176 -90
- 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
|
@@ -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
|
-
|
|
47
|
+
bucketEnvironment = _ref.bucketEnvironment,
|
|
49
48
|
buildRevision = _ref.buildRevision,
|
|
50
49
|
buildNumber = _ref.buildNumber,
|
|
51
50
|
applicationIndexOutFile = _ref.applicationIndexOutFile;
|
|
52
|
-
const uploadScriptContent =
|
|
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 =
|
|
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
|
|
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(
|
|
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 =
|
|
157
|
+
const cloudDotenvFile = `.env.${cloudEnvironment}`;
|
|
83
158
|
|
|
84
159
|
// The shared dotenv file across environments is optional
|
|
85
160
|
const sharedProductionEnvironment = dotenv.config({
|
|
@@ -91,18 +166,23 @@ function loadDotenvFiles(_ref) {
|
|
|
91
166
|
path: path.join(dotenvPath, cloudDotenvFile)
|
|
92
167
|
});
|
|
93
168
|
if (cloudSpecificProductionEnvironment.error) {
|
|
94
|
-
|
|
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
|
-
throw new Error(
|
|
172
|
+
throw new Error(`Failed loading '${sharedDotenvFile}' in '${dotenvPath}'. Make sure it exists.`);
|
|
99
173
|
}
|
|
100
174
|
return _objectSpread$3(_objectSpread$3({}, sharedProductionEnvironment.parsed), cloudSpecificProductionEnvironment.parsed);
|
|
101
175
|
}
|
|
102
176
|
|
|
103
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; }
|
|
104
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
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; }
|
|
105
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
|
+
}
|
|
106
186
|
function writeUploadScriptFile(_ref) {
|
|
107
187
|
let fileName = _ref.fileName,
|
|
108
188
|
fileContent = _ref.fileContent,
|
|
@@ -116,7 +196,7 @@ function writeUploadScriptFile(_ref) {
|
|
|
116
196
|
function getBucketNamespace(prNumber) {
|
|
117
197
|
if (!prNumber) return;
|
|
118
198
|
if (prNumber === 'merchant-center-preview') return prNumber;
|
|
119
|
-
return
|
|
199
|
+
return `mc-${prNumber}`;
|
|
120
200
|
}
|
|
121
201
|
|
|
122
202
|
/**
|
|
@@ -134,32 +214,30 @@ function getApplicationAssetsBucketUrl(_ref2) {
|
|
|
134
214
|
let bucketRegion = _ref2.bucketRegion,
|
|
135
215
|
prNumber = _ref2.prNumber,
|
|
136
216
|
applicationName = _ref2.applicationName;
|
|
137
|
-
const applicationAssetsBucketUrl = _filterInstanceProperty(_context = [
|
|
217
|
+
const applicationAssetsBucketUrl = _filterInstanceProperty(_context = [`gs://${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context, Boolean);
|
|
138
218
|
return applicationAssetsBucketUrl.join('/');
|
|
139
219
|
}
|
|
140
220
|
function getApplicationIndexBucketUrl(_ref3) {
|
|
141
|
-
var _context2;
|
|
142
221
|
let bucketRegion = _ref3.bucketRegion,
|
|
143
222
|
prNumber = _ref3.prNumber,
|
|
144
223
|
applicationName = _ref3.applicationName,
|
|
145
|
-
|
|
224
|
+
bucketEnvironment = _ref3.bucketEnvironment;
|
|
146
225
|
const applicationAssetsBucketUrl = getApplicationAssetsBucketUrl({
|
|
147
226
|
bucketRegion,
|
|
148
227
|
prNumber,
|
|
149
228
|
applicationName
|
|
150
229
|
});
|
|
151
|
-
const applicationIndexBucketUrl =
|
|
230
|
+
const applicationIndexBucketUrl = `${applicationAssetsBucketUrl}/${bucketEnvironment}`;
|
|
152
231
|
return applicationIndexBucketUrl;
|
|
153
232
|
}
|
|
154
233
|
function getCdnUrl(_ref4) {
|
|
155
|
-
var
|
|
234
|
+
var _context2;
|
|
156
235
|
let bucketRegion = _ref4.bucketRegion,
|
|
157
236
|
prNumber = _ref4.prNumber,
|
|
158
237
|
applicationName = _ref4.applicationName;
|
|
159
|
-
return _filterInstanceProperty(
|
|
238
|
+
return _filterInstanceProperty(_context2 = [`https://storage.googleapis.com/${bucketRegion}`, getBucketNamespace(prNumber), applicationName]).call(_context2, Boolean).join('/');
|
|
160
239
|
}
|
|
161
240
|
async function compileApplicationAssets(_ref5) {
|
|
162
|
-
var _context4, _context5;
|
|
163
241
|
let cliFlags = _ref5.cliFlags,
|
|
164
242
|
bucketRegion = _ref5.bucketRegion,
|
|
165
243
|
paths = _ref5.paths;
|
|
@@ -173,7 +251,7 @@ async function compileApplicationAssets(_ref5) {
|
|
|
173
251
|
skipMenu: cliFlags.skipMenu
|
|
174
252
|
});
|
|
175
253
|
const parsedApplicationAssetsUploadScriptFile = path.parse(cliFlags.applicationAssetsUploadScriptOutFile);
|
|
176
|
-
const applicationAssetsUploadScriptFileName =
|
|
254
|
+
const applicationAssetsUploadScriptFileName = `${parsedApplicationAssetsUploadScriptFile.name}-${bucketRegion}${parsedApplicationAssetsUploadScriptFile.ext}`;
|
|
177
255
|
writeUploadScriptFile({
|
|
178
256
|
fileName: applicationAssetsUploadScriptFileName,
|
|
179
257
|
fileContent: applicationAssetsUploadScriptContent,
|
|
@@ -184,7 +262,8 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
184
262
|
let cliFlags = _ref6.cliFlags,
|
|
185
263
|
paths = _ref6.paths,
|
|
186
264
|
bucketRegion = _ref6.bucketRegion,
|
|
187
|
-
cloudEnvironment = _ref6.cloudEnvironment
|
|
265
|
+
cloudEnvironment = _ref6.cloudEnvironment,
|
|
266
|
+
bucketEnvironment = _ref6.bucketEnvironment;
|
|
188
267
|
const cloudEnvironmentDeploymentPath = path.join(paths.deploymentsPath, cloudEnvironment);
|
|
189
268
|
// Ensure the folder exists
|
|
190
269
|
const createDeploymentsFolderResult = await execa('mkdir', ['-p', cloudEnvironmentDeploymentPath], {
|
|
@@ -206,7 +285,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
206
285
|
})), {}, {
|
|
207
286
|
// The trailing slash is important to indicate to the CSP directive that all the resources
|
|
208
287
|
// under that path should be allowed.
|
|
209
|
-
MC_CDN_URL:
|
|
288
|
+
MC_CDN_URL: `${cdnUrl}/`
|
|
210
289
|
}, cliFlags.mcUrl ? {
|
|
211
290
|
MC_URL: cliFlags.mcUrl
|
|
212
291
|
} : {}), cliFlags.mcApiUrl ? {
|
|
@@ -244,10 +323,10 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
244
323
|
bucketRegion,
|
|
245
324
|
prNumber: cliFlags.prNumber,
|
|
246
325
|
applicationName: cliFlags.applicationName,
|
|
247
|
-
|
|
326
|
+
bucketEnvironment
|
|
248
327
|
}),
|
|
249
328
|
cdnUrl,
|
|
250
|
-
|
|
329
|
+
bucketEnvironment,
|
|
251
330
|
buildRevision: cliFlags.buildRevision,
|
|
252
331
|
buildNumber: cliFlags.buildNumber,
|
|
253
332
|
applicationIndexOutFile: cliFlags.applicationIndexOutFile
|
|
@@ -268,7 +347,7 @@ async function compileEnvironmentApplicationIndexes(_ref6) {
|
|
|
268
347
|
}
|
|
269
348
|
}
|
|
270
349
|
async function command$3(cliFlags, cwd) {
|
|
271
|
-
var
|
|
350
|
+
var _context3;
|
|
272
351
|
let cloudEnvironmentsGroupedByBucketRegions;
|
|
273
352
|
try {
|
|
274
353
|
// This is the list of the supported cloud environments and their related bucket location.
|
|
@@ -293,24 +372,36 @@ async function command$3(cliFlags, cwd) {
|
|
|
293
372
|
dotenvPath: cliFlags.dotenvFolder && path.join(monorepoRoot.rootDir, cliFlags.dotenvFolder),
|
|
294
373
|
assetsPath
|
|
295
374
|
};
|
|
296
|
-
const taskList = new Listr(_mapInstanceProperty(
|
|
375
|
+
const taskList = new Listr(_mapInstanceProperty(_context3 = _Object$entries(cloudEnvironmentsGroupedByBucketRegions.config)).call(_context3, _ref7 => {
|
|
297
376
|
let _ref8 = _slicedToArray(_ref7, 2),
|
|
298
377
|
bucketRegion = _ref8[0],
|
|
299
|
-
|
|
378
|
+
bucketEnvironmentConfigs = _ref8[1];
|
|
300
379
|
return {
|
|
301
|
-
title:
|
|
380
|
+
title: `Compiling for bucket region ${bucketRegion}`,
|
|
302
381
|
task: () => {
|
|
303
|
-
var
|
|
304
|
-
return new Listr(_concatInstanceProperty(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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`,
|
|
314
405
|
task: () => compileApplicationAssets({
|
|
315
406
|
cliFlags,
|
|
316
407
|
bucketRegion,
|
|
@@ -355,58 +446,52 @@ const mapLabelAllLocalesWithDefaults = (labelAllLocales, defaultLabel) => {
|
|
|
355
446
|
*/
|
|
356
447
|
|
|
357
448
|
const mapApplicationMenuConfigToGraqhQLMenuJson = config => {
|
|
358
|
-
var
|
|
449
|
+
var _context2;
|
|
359
450
|
const entryPointUriPath = config.env.entryPointUriPath;
|
|
360
451
|
|
|
361
452
|
// @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
362
|
-
const accountLinks =
|
|
453
|
+
const accountLinks = config.env.__DEVELOPMENT__?.accountLinks ?? [];
|
|
363
454
|
if (accountLinks.length > 0) {
|
|
364
|
-
return _mapInstanceProperty(accountLinks).call(accountLinks, menuLink => {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
featureToggle: (_menuLink$featureTogg = menuLink.featureToggle) !== null && _menuLink$featureTogg !== void 0 ? _menuLink$featureTogg : null
|
|
373
|
-
};
|
|
374
|
-
});
|
|
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
|
+
}));
|
|
375
463
|
}
|
|
376
|
-
const menuLinks =
|
|
464
|
+
const menuLinks = config.env.__DEVELOPMENT__?.menuLinks;
|
|
377
465
|
return {
|
|
378
466
|
key: entryPointUriPath,
|
|
379
467
|
uriPath: entryPointUriPath,
|
|
380
468
|
icon: menuLinks.icon,
|
|
381
|
-
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks
|
|
469
|
+
labelAllLocales: mapLabelAllLocalesWithDefaults(menuLinks?.labelAllLocales, menuLinks?.defaultLabel),
|
|
382
470
|
permissions: menuLinks.permissions,
|
|
383
471
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
384
|
-
featureToggle:
|
|
472
|
+
featureToggle: menuLinks.featureToggle ?? null,
|
|
385
473
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
386
|
-
menuVisibility:
|
|
474
|
+
menuVisibility: menuLinks.menuVisibility ?? null,
|
|
387
475
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
388
|
-
actionRights:
|
|
476
|
+
actionRights: menuLinks.actionRights ?? null,
|
|
389
477
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
390
|
-
dataFences:
|
|
391
|
-
submenu: _mapInstanceProperty(_context2 = menuLinks.submenuLinks).call(_context2, submenuLink => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
dataFences: (_submenuLink$dataFenc = submenuLink.dataFences) !== null && _submenuLink$dataFenc !== void 0 ? _submenuLink$dataFenc : null
|
|
406
|
-
};
|
|
407
|
-
}),
|
|
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
|
+
})),
|
|
408
493
|
// @ts-ignore: not defined in schema, as it's only used internally.
|
|
409
|
-
shouldRenderDivider:
|
|
494
|
+
shouldRenderDivider: menuLinks.shouldRenderDivider ?? false
|
|
410
495
|
};
|
|
411
496
|
};
|
|
412
497
|
async function command$2(cliFlags, cwd) {
|
|
@@ -417,7 +502,7 @@ async function command$2(cliFlags, cwd) {
|
|
|
417
502
|
dotenvPath,
|
|
418
503
|
// The env itself is not important for the menu. However, the application config
|
|
419
504
|
// uses environment placeholders and therefore we need to provide the variables for it.
|
|
420
|
-
cloudEnvironment: '
|
|
505
|
+
cloudEnvironment: 'ctp_staging_gcp_europe-west1_v1'
|
|
421
506
|
})), {}, {
|
|
422
507
|
// Again, make sure that the environment is "development", otherwise
|
|
423
508
|
// the menu config won't be available.
|
|
@@ -586,15 +671,15 @@ function validateMenu(menuJson) {
|
|
|
586
671
|
async function command(cliFlags) {
|
|
587
672
|
const menuJsonPath = cliFlags.inputFile;
|
|
588
673
|
const isAppbarMenu = cliFlags.navigation === 'top';
|
|
589
|
-
if (!menuJsonPath) throw new Error(
|
|
590
|
-
if (!fs.existsSync(menuJsonPath)) throw new Error(
|
|
674
|
+
if (!menuJsonPath) throw new Error(`--input-file cannot be empty. please provide the path of compiled menu.json`);
|
|
675
|
+
if (!fs.existsSync(menuJsonPath)) throw new Error(`The menu.json file doesn't exist: ${menuJsonPath}`);
|
|
591
676
|
const menuJson = fs.readFileSync(menuJsonPath, 'utf-8');
|
|
592
677
|
return validateMenu(JSON.parse(menuJson), isAppbarMenu ? appbarMenuSchema : navbarMenuSchema);
|
|
593
678
|
}
|
|
594
679
|
|
|
595
680
|
var pkgJson = {
|
|
596
681
|
name: "@commercetools-frontend/application-cli",
|
|
597
|
-
version: "1.
|
|
682
|
+
version: "1.8.0",
|
|
598
683
|
description: "Internal CLI to manage Merchant Center application deployments across various environments.",
|
|
599
684
|
keywords: [
|
|
600
685
|
"commercetools",
|
|
@@ -619,9 +704,9 @@ var pkgJson = {
|
|
|
619
704
|
"@babel/core": "^7.22.11",
|
|
620
705
|
"@babel/runtime": "^7.21.0",
|
|
621
706
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
622
|
-
"@commercetools-frontend/application-config": "22.
|
|
623
|
-
"@commercetools-frontend/constants": "22.
|
|
624
|
-
"@commercetools-frontend/l10n": "22.
|
|
707
|
+
"@commercetools-frontend/application-config": "22.11.0",
|
|
708
|
+
"@commercetools-frontend/constants": "22.11.0",
|
|
709
|
+
"@commercetools-frontend/l10n": "22.11.0",
|
|
625
710
|
"@manypkg/find-root": "2.2.1",
|
|
626
711
|
cac: "^6.7.14",
|
|
627
712
|
cosmiconfig: "8.3.6",
|
|
@@ -646,7 +731,8 @@ var pkgJson = {
|
|
|
646
731
|
},
|
|
647
732
|
preconstruct: {
|
|
648
733
|
entrypoints: [
|
|
649
|
-
"./cli.ts"
|
|
734
|
+
"./cli.ts",
|
|
735
|
+
"./index.ts"
|
|
650
736
|
]
|
|
651
737
|
}
|
|
652
738
|
};
|
|
@@ -665,7 +751,7 @@ const run = async () => {
|
|
|
665
751
|
// Default command
|
|
666
752
|
cli.command('').usage('\n\n Compile deployments and menus and create versions for MC applications').action(cli.outputHelp);
|
|
667
753
|
const usageCompileDeployment = 'Compile the deployments for an application for all environments.';
|
|
668
|
-
cli.command('compile-deployments', usageCompileDeployment).usage(
|
|
754
|
+
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.', {
|
|
669
755
|
default: 'application.html'
|
|
670
756
|
}).option('--application-index-upload-script-out-file [path]', '(optional) The name of the the application index upload script file.', {
|
|
671
757
|
default: 'upload-index.sh'
|
|
@@ -677,15 +763,15 @@ const run = async () => {
|
|
|
677
763
|
await command$3(options, cwd);
|
|
678
764
|
});
|
|
679
765
|
const usageCompileMenu = 'Compile the menu links of an application into a `menu.json`. This is only required for internal applications';
|
|
680
|
-
cli.command('compile-menu', usageCompileMenu).usage(
|
|
766
|
+
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 => {
|
|
681
767
|
await command$2(options, cwd);
|
|
682
768
|
});
|
|
683
769
|
const usageValidateMenu = 'Validate compiled `menu.json` file';
|
|
684
|
-
cli.command('validate-menu', usageValidateMenu).usage(
|
|
770
|
+
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 => {
|
|
685
771
|
await command(options);
|
|
686
772
|
});
|
|
687
773
|
const usageCreateVersion = 'Output a JSON string about the information in the `version.json` for a deployment, including the updated list of rollbacks.';
|
|
688
|
-
cli.command('create-version', usageCreateVersion).usage(
|
|
774
|
+
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', {
|
|
689
775
|
default: 15
|
|
690
776
|
}).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 => {
|
|
691
777
|
await command$1(options);
|
|
@@ -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 @@
|
|
|
1
|
+
|
|
@@ -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 {};
|