@commercetools-frontend/create-mc-app 22.8.1 → 22.8.2
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/CHANGELOG.md +2 -0
- package/dist/commercetools-frontend-create-mc-app.cjs.dev.js +82 -35
- package/dist/commercetools-frontend-create-mc-app.cjs.prod.js +82 -35
- package/dist/commercetools-frontend-create-mc-app.esm.js +82 -35
- package/dist/declarations/src/constants.d.ts +9 -0
- package/dist/declarations/src/tasks/index.d.ts +1 -1
- package/dist/declarations/src/tasks/update-application-config.d.ts +4 -0
- package/dist/declarations/src/types.d.ts +6 -2
- package/dist/declarations/src/utils.d.ts +3 -2
- package/dist/declarations/src/validations.d.ts +3 -2
- package/package.json +1 -1
- package/src/cli.ts +11 -3
- package/src/constants.ts +11 -0
- package/src/process-options.ts +11 -3
- package/src/tasks/download-template.ts +7 -4
- package/src/tasks/index.ts +1 -1
- package/src/tasks/{update-custom-application-config.ts → update-application-config.ts} +34 -17
- package/src/tasks/update-application-constants.ts +6 -4
- package/src/tasks/update-package-json.ts +3 -3
- package/src/types.ts +7 -2
- package/src/utils.ts +10 -2
- package/src/validations.ts +27 -8
- package/dist/declarations/src/tasks/update-custom-application-config.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,16 +10,16 @@ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/ins
|
|
|
10
10
|
var semver = require('semver');
|
|
11
11
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
12
12
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
13
|
-
var crypto = require('crypto');
|
|
14
|
-
var path = require('path');
|
|
15
|
-
var readline = require('readline');
|
|
13
|
+
var crypto = require('node:crypto');
|
|
14
|
+
var path = require('node:path');
|
|
15
|
+
var readline = require('node:readline');
|
|
16
16
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
17
17
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
18
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
19
|
-
var fs = require('fs');
|
|
19
|
+
var fs = require('node:fs');
|
|
20
20
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
21
21
|
var _Date$now = require('@babel/runtime-corejs3/core-js-stable/date/now');
|
|
22
|
-
var os = require('os');
|
|
22
|
+
var os = require('node:os');
|
|
23
23
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
24
24
|
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
25
25
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
@@ -67,7 +67,7 @@ var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
|
67
67
|
|
|
68
68
|
var pkgJson = {
|
|
69
69
|
name: "@commercetools-frontend/create-mc-app",
|
|
70
|
-
version: "22.8.
|
|
70
|
+
version: "22.8.2",
|
|
71
71
|
description: "Create Merchant Center applications to quickly get up and running",
|
|
72
72
|
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
73
73
|
repository: {
|
|
@@ -109,6 +109,15 @@ var pkgJson = {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
+
const applicationTypes = {
|
|
113
|
+
'custom-application': 'custom-application',
|
|
114
|
+
'custom-view': 'custom-view'
|
|
115
|
+
};
|
|
116
|
+
const availableTemplates = {
|
|
117
|
+
starter: 'starter',
|
|
118
|
+
'starter-typescript': 'starter-typescript'
|
|
119
|
+
};
|
|
120
|
+
|
|
112
121
|
async function getLatestReleaseVersion() {
|
|
113
122
|
const commandResult = await execa__default["default"].command('npm view @commercetools-frontend/create-mc-app --json', {
|
|
114
123
|
encoding: 'utf-8'
|
|
@@ -176,31 +185,48 @@ const resolveFilePathByExtension = requestedModule => {
|
|
|
176
185
|
return _concatInstanceProperty__default["default"](_context4 = "".concat(requestedModule)).call(_context4, fileExtension);
|
|
177
186
|
};
|
|
178
187
|
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
188
|
+
const throwIfApplicationTypeIsNotSupported = applicationType => {
|
|
189
|
+
switch (applicationType) {
|
|
190
|
+
case applicationTypes['custom-view']:
|
|
191
|
+
{
|
|
192
|
+
if (process.env.ENABLE_EXPERIMENTAL_CUSTOM_VIEWS !== 'true') {
|
|
193
|
+
throw new Error("Custom Views generation is not yet supported.");
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case applicationTypes['custom-application']:
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
{
|
|
201
|
+
var _context;
|
|
202
|
+
const applicationTypesList = _Object$keys__default["default"](applicationTypes).toString();
|
|
203
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "The provided application type \"".concat(applicationType, "\" does not exist. Available types are \"")).call(_context, applicationTypesList, "\". Make sure you are also using the latest version of \"@commercetools-frontend/create-mc-app\"."));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
182
206
|
};
|
|
183
207
|
const throwIfTemplateIsNotSupported = templateName => {
|
|
184
|
-
var _context;
|
|
185
208
|
switch (templateName) {
|
|
186
209
|
case availableTemplates.starter:
|
|
187
210
|
case availableTemplates['starter-typescript']:
|
|
188
211
|
break;
|
|
189
212
|
default:
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
{
|
|
214
|
+
var _context2;
|
|
215
|
+
const templateNamesList = _Object$keys__default["default"](availableTemplates).toString();
|
|
216
|
+
throw new Error(_concatInstanceProperty__default["default"](_context2 = "The provided template name \"".concat(templateName, "\" does not exist. Available templates are \"")).call(_context2, templateNamesList, "\". Make sure you are also using the latest version of \"@commercetools-frontend/create-mc-app\"."));
|
|
217
|
+
}
|
|
192
218
|
}
|
|
193
219
|
};
|
|
194
220
|
const throwIfProjectDirectoryExists = (dirName, dirPath) => {
|
|
195
221
|
if (fs__default["default"].existsSync(dirPath)) {
|
|
196
|
-
var
|
|
197
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
222
|
+
var _context3;
|
|
223
|
+
throw new Error(_concatInstanceProperty__default["default"](_context3 = "A directory named \"".concat(dirName, "\" already exists at this location \"")).call(_context3, dirPath, "\". Please choose a different project name or remove the directory, then try running the command again."));
|
|
198
224
|
}
|
|
199
225
|
};
|
|
200
226
|
const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, versionToCheck) => {
|
|
201
227
|
if (!fs__default["default"].existsSync(templateFolderPath)) {
|
|
202
|
-
var
|
|
203
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
228
|
+
var _context4;
|
|
229
|
+
throw new Error(_concatInstanceProperty__default["default"](_context4 = "The downloaded template \"".concat(templateName, "\" does not exist for the given version \"")).call(_context4, versionToCheck, "\". Check the releases page if you are looking for a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
204
230
|
}
|
|
205
231
|
// In case the version is semver (usually release tags) we check that
|
|
206
232
|
// the cloned repository contains the template matching the given version
|
|
@@ -210,8 +236,8 @@ const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, ve
|
|
|
210
236
|
}));
|
|
211
237
|
const versionAsNumber = versionToCheck.replace('v', '');
|
|
212
238
|
if (templatePackageJson.version !== versionAsNumber) {
|
|
213
|
-
var
|
|
214
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
239
|
+
var _context5, _context6;
|
|
240
|
+
throw new Error(_concatInstanceProperty__default["default"](_context5 = _concatInstanceProperty__default["default"](_context6 = "The downloaded template \"".concat(templateName, "\" does not match the version \"")).call(_context6, versionAsNumber, "\", instead got \"")).call(_context5, templatePackageJson.version, "\". Check the releases page if you want to provide a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
215
241
|
}
|
|
216
242
|
}
|
|
217
243
|
};
|
|
@@ -223,14 +249,17 @@ const throwIfInitialProjectKeyIsMissing = initialProjectKey => {
|
|
|
223
249
|
const throwIfNodeVersionIsNotSupported = (currentNodeVersion, expectedVersionRange) => {
|
|
224
250
|
const hasValidNodeVersion = semver__default["default"].satisfies(currentNodeVersion, expectedVersionRange);
|
|
225
251
|
if (!hasValidNodeVersion) {
|
|
226
|
-
var
|
|
227
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
252
|
+
var _context7;
|
|
253
|
+
throw new Error(_concatInstanceProperty__default["default"](_context7 = "You are running Node ".concat(currentNodeVersion, " but create-mc-app requires Node ")).call(_context7, expectedVersionRange, ". Please update your version of Node."));
|
|
228
254
|
}
|
|
229
255
|
};
|
|
230
256
|
|
|
231
257
|
const question = (rl, value) => new _Promise__default["default"](resolve => rl.question(value, resolve));
|
|
232
258
|
const getEntryPointUriPath = async (rl, options) => {
|
|
233
259
|
var _context;
|
|
260
|
+
if (options.applicationType === applicationTypes['custom-view']) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
234
263
|
if (options.entryPointUriPath) {
|
|
235
264
|
return options.entryPointUriPath;
|
|
236
265
|
}
|
|
@@ -261,6 +290,7 @@ async function processOptions(projectDirectoryName, options) {
|
|
|
261
290
|
const templateName = options.template;
|
|
262
291
|
|
|
263
292
|
// Validate options
|
|
293
|
+
throwIfApplicationTypeIsNotSupported(options.applicationType);
|
|
264
294
|
throwIfProjectDirectoryExists(projectDirectoryName, projectDirectoryPath);
|
|
265
295
|
throwIfTemplateIsNotSupported(templateName);
|
|
266
296
|
|
|
@@ -273,6 +303,7 @@ async function processOptions(projectDirectoryName, options) {
|
|
|
273
303
|
const initialProjectKey = await getInitialProjectKey(rl, options);
|
|
274
304
|
rl.close();
|
|
275
305
|
return {
|
|
306
|
+
applicationType: options.applicationType,
|
|
276
307
|
projectDirectoryName,
|
|
277
308
|
projectDirectoryPath,
|
|
278
309
|
templateName,
|
|
@@ -292,7 +323,7 @@ function downloadTemplate(options) {
|
|
|
292
323
|
const tmpDir = os__default["default"].tmpdir();
|
|
293
324
|
const tmpFolderNameForClonedRepository = ['merchant-center-application-kit', '--', options.tagOrBranchVersion, '--', _Date$now__default["default"]().toString()].join('');
|
|
294
325
|
const clonedRepositoryPath = path__default["default"].join(tmpDir, tmpFolderNameForClonedRepository);
|
|
295
|
-
const templateFolderPath = path__default["default"].join(clonedRepositoryPath, 'application-templates', options.templateName);
|
|
326
|
+
const templateFolderPath = path__default["default"].join(clonedRepositoryPath, options.applicationType === applicationTypes['custom-view'] ? 'custom-views-templates' : 'application-templates', options.templateName);
|
|
296
327
|
return new listr2.Listr([{
|
|
297
328
|
title: "Cloning repository using branch ".concat(options.tagOrBranchVersion),
|
|
298
329
|
task: async () => {
|
|
@@ -404,10 +435,11 @@ function updatePackageJson(options, releaseVersion) {
|
|
|
404
435
|
};
|
|
405
436
|
}
|
|
406
437
|
|
|
407
|
-
function
|
|
408
|
-
const appName = wordify(options.entryPointUriPath);
|
|
438
|
+
function replaceApplicationInfoInApplicationConfig(filePath, options) {
|
|
409
439
|
const result = core.transformFileSync(filePath, {
|
|
410
|
-
plugins: [function
|
|
440
|
+
plugins: [function replaceConfig() {
|
|
441
|
+
var _options$entryPointUr;
|
|
442
|
+
const appName = wordify((_options$entryPointUr = options.entryPointUriPath) !== null && _options$entryPointUr !== void 0 ? _options$entryPointUr : options.projectDirectoryName);
|
|
411
443
|
return {
|
|
412
444
|
visitor: {
|
|
413
445
|
Identifier(nodePath) {
|
|
@@ -421,7 +453,7 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
421
453
|
}) && nodePath.parent.type === 'ObjectProperty') {
|
|
422
454
|
nodePath.parent.value = core.types.stringLiteral(options.initialProjectKey);
|
|
423
455
|
}
|
|
424
|
-
if (nodePath.isIdentifier({
|
|
456
|
+
if (options.applicationType === applicationTypes['custom-application'] && nodePath.isIdentifier({
|
|
425
457
|
name: 'defaultLabel'
|
|
426
458
|
})) {
|
|
427
459
|
const isMainMenuLinkParent = nodePath.findParent(parentPath => parentPath.isIdentifier({
|
|
@@ -445,12 +477,22 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
445
477
|
});
|
|
446
478
|
}
|
|
447
479
|
}
|
|
448
|
-
function
|
|
480
|
+
function getApplicationConfigName(options) {
|
|
481
|
+
switch (options.applicationType) {
|
|
482
|
+
case applicationTypes['custom-application']:
|
|
483
|
+
return 'custom-application-config';
|
|
484
|
+
case applicationTypes['custom-view']:
|
|
485
|
+
return 'custom-view-config';
|
|
486
|
+
default:
|
|
487
|
+
throw new Error("Unknown application type ".concat(options.applicationType));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function updateApplicationConfig(options) {
|
|
449
491
|
return {
|
|
450
|
-
title: 'Updating
|
|
492
|
+
title: 'Updating application config file',
|
|
451
493
|
task: () => {
|
|
452
|
-
const
|
|
453
|
-
|
|
494
|
+
const configPath = resolveFilePathByExtension(path__default["default"].join(options.projectDirectoryPath, getApplicationConfigName(options)));
|
|
495
|
+
replaceApplicationInfoInApplicationConfig(configPath, options);
|
|
454
496
|
}
|
|
455
497
|
};
|
|
456
498
|
}
|
|
@@ -481,6 +523,7 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
481
523
|
function updateApplicationConstants(options) {
|
|
482
524
|
return {
|
|
483
525
|
title: 'Updating application constants',
|
|
526
|
+
enabled: options.applicationType === applicationTypes['custom-application'],
|
|
484
527
|
task: () => {
|
|
485
528
|
const applicationConstantsPath = resolveFilePathByExtension(path__default["default"].join(options.projectDirectoryPath, 'src/constants'));
|
|
486
529
|
replaceEntryPointUriPathInConstants(applicationConstantsPath, options);
|
|
@@ -499,8 +542,10 @@ process.on('unhandledRejection', err => {
|
|
|
499
542
|
});
|
|
500
543
|
const run = () => {
|
|
501
544
|
// Default command
|
|
502
|
-
cli.command('[project-directory]').usage('[project-directory]\n\n Bootstraps a new Custom Application project using one of the predefined templates.').option('--
|
|
503
|
-
default: '
|
|
545
|
+
cli.command('[project-directory]').usage('[project-directory]\n\n Bootstraps a new Custom Application project using one of the predefined templates.').option('--application-type <type>', '(optional) The type of the application to create: custom-application (default) or custom-view.', {
|
|
546
|
+
default: applicationTypes['custom-application']
|
|
547
|
+
}).option('--template <name>', '(optional) The name of the template to install.', {
|
|
548
|
+
default: availableTemplates.starter
|
|
504
549
|
}).option('--template-version <version>', '(optional) The version of the template to install (either a git tag or a git branch of the "commercetools/merchant-center-application-kit" repository).', {
|
|
505
550
|
default: 'main'
|
|
506
551
|
}).option('--skip-install', '(optional) Skip installing the dependencies after cloning the template.', {
|
|
@@ -516,17 +561,18 @@ const run = () => {
|
|
|
516
561
|
const releaseVersion = await getLatestReleaseVersion();
|
|
517
562
|
hintOutdatedVersion(pkgJson.version, releaseVersion);
|
|
518
563
|
console.log('');
|
|
519
|
-
console.log(
|
|
564
|
+
console.log( // TODO: Use link based on the application type
|
|
565
|
+
"Documentation available at https://docs.commercetools.com/custom-applications");
|
|
520
566
|
console.log('');
|
|
521
567
|
const taskOptions = await processOptions(projectDirectory, options);
|
|
522
568
|
const shouldInstallDependencies = !options.skipInstall ||
|
|
523
569
|
// TODO: remove once we manage to ensure the package manager is installed, for example via Corepack.
|
|
524
570
|
options.packageManager === 'pnpm';
|
|
525
|
-
const taskList = new listr2.Listr(_filterInstanceProperty__default["default"](_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion),
|
|
571
|
+
const taskList = new listr2.Listr(_filterInstanceProperty__default["default"](_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion), updateApplicationConfig(taskOptions), updateApplicationConstants(taskOptions), shouldInstallDependencies && installDependencies(taskOptions)]).call(_context, Boolean));
|
|
526
572
|
await taskList.run();
|
|
527
573
|
const packageManager = getPreferredPackageManager(taskOptions);
|
|
528
574
|
console.log('');
|
|
529
|
-
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The
|
|
575
|
+
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The application has been created in the \"".concat(taskOptions.projectDirectoryName, "\" folder."));
|
|
530
576
|
console.log('');
|
|
531
577
|
console.log("To get started:");
|
|
532
578
|
console.log("$ cd ".concat(taskOptions.projectDirectoryName));
|
|
@@ -535,7 +581,8 @@ const run = () => {
|
|
|
535
581
|
}
|
|
536
582
|
console.log("$ ".concat(packageManager, " start"));
|
|
537
583
|
console.log('');
|
|
538
|
-
console.log(
|
|
584
|
+
console.log( // TODO: Use link based on the application type
|
|
585
|
+
"Visit https://docs.commercetools.com/custom-applications for more info about developing Custom Applications. Enjoy \uD83D\uDE80");
|
|
539
586
|
});
|
|
540
587
|
cli.help();
|
|
541
588
|
cli.version(pkgJson.version);
|
|
@@ -10,16 +10,16 @@ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/ins
|
|
|
10
10
|
var semver = require('semver');
|
|
11
11
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
12
12
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
13
|
-
var crypto = require('crypto');
|
|
14
|
-
var path = require('path');
|
|
15
|
-
var readline = require('readline');
|
|
13
|
+
var crypto = require('node:crypto');
|
|
14
|
+
var path = require('node:path');
|
|
15
|
+
var readline = require('node:readline');
|
|
16
16
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
17
17
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
18
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
19
|
-
var fs = require('fs');
|
|
19
|
+
var fs = require('node:fs');
|
|
20
20
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
21
21
|
var _Date$now = require('@babel/runtime-corejs3/core-js-stable/date/now');
|
|
22
|
-
var os = require('os');
|
|
22
|
+
var os = require('node:os');
|
|
23
23
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
24
24
|
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
25
25
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
@@ -67,7 +67,7 @@ var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
|
67
67
|
|
|
68
68
|
var pkgJson = {
|
|
69
69
|
name: "@commercetools-frontend/create-mc-app",
|
|
70
|
-
version: "22.8.
|
|
70
|
+
version: "22.8.2",
|
|
71
71
|
description: "Create Merchant Center applications to quickly get up and running",
|
|
72
72
|
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
73
73
|
repository: {
|
|
@@ -109,6 +109,15 @@ var pkgJson = {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
+
const applicationTypes = {
|
|
113
|
+
'custom-application': 'custom-application',
|
|
114
|
+
'custom-view': 'custom-view'
|
|
115
|
+
};
|
|
116
|
+
const availableTemplates = {
|
|
117
|
+
starter: 'starter',
|
|
118
|
+
'starter-typescript': 'starter-typescript'
|
|
119
|
+
};
|
|
120
|
+
|
|
112
121
|
async function getLatestReleaseVersion() {
|
|
113
122
|
const commandResult = await execa__default["default"].command('npm view @commercetools-frontend/create-mc-app --json', {
|
|
114
123
|
encoding: 'utf-8'
|
|
@@ -176,31 +185,48 @@ const resolveFilePathByExtension = requestedModule => {
|
|
|
176
185
|
return _concatInstanceProperty__default["default"](_context4 = "".concat(requestedModule)).call(_context4, fileExtension);
|
|
177
186
|
};
|
|
178
187
|
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
188
|
+
const throwIfApplicationTypeIsNotSupported = applicationType => {
|
|
189
|
+
switch (applicationType) {
|
|
190
|
+
case applicationTypes['custom-view']:
|
|
191
|
+
{
|
|
192
|
+
if (process.env.ENABLE_EXPERIMENTAL_CUSTOM_VIEWS !== 'true') {
|
|
193
|
+
throw new Error("Custom Views generation is not yet supported.");
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case applicationTypes['custom-application']:
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
{
|
|
201
|
+
var _context;
|
|
202
|
+
const applicationTypesList = _Object$keys__default["default"](applicationTypes).toString();
|
|
203
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "The provided application type \"".concat(applicationType, "\" does not exist. Available types are \"")).call(_context, applicationTypesList, "\". Make sure you are also using the latest version of \"@commercetools-frontend/create-mc-app\"."));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
182
206
|
};
|
|
183
207
|
const throwIfTemplateIsNotSupported = templateName => {
|
|
184
|
-
var _context;
|
|
185
208
|
switch (templateName) {
|
|
186
209
|
case availableTemplates.starter:
|
|
187
210
|
case availableTemplates['starter-typescript']:
|
|
188
211
|
break;
|
|
189
212
|
default:
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
{
|
|
214
|
+
var _context2;
|
|
215
|
+
const templateNamesList = _Object$keys__default["default"](availableTemplates).toString();
|
|
216
|
+
throw new Error(_concatInstanceProperty__default["default"](_context2 = "The provided template name \"".concat(templateName, "\" does not exist. Available templates are \"")).call(_context2, templateNamesList, "\". Make sure you are also using the latest version of \"@commercetools-frontend/create-mc-app\"."));
|
|
217
|
+
}
|
|
192
218
|
}
|
|
193
219
|
};
|
|
194
220
|
const throwIfProjectDirectoryExists = (dirName, dirPath) => {
|
|
195
221
|
if (fs__default["default"].existsSync(dirPath)) {
|
|
196
|
-
var
|
|
197
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
222
|
+
var _context3;
|
|
223
|
+
throw new Error(_concatInstanceProperty__default["default"](_context3 = "A directory named \"".concat(dirName, "\" already exists at this location \"")).call(_context3, dirPath, "\". Please choose a different project name or remove the directory, then try running the command again."));
|
|
198
224
|
}
|
|
199
225
|
};
|
|
200
226
|
const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, versionToCheck) => {
|
|
201
227
|
if (!fs__default["default"].existsSync(templateFolderPath)) {
|
|
202
|
-
var
|
|
203
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
228
|
+
var _context4;
|
|
229
|
+
throw new Error(_concatInstanceProperty__default["default"](_context4 = "The downloaded template \"".concat(templateName, "\" does not exist for the given version \"")).call(_context4, versionToCheck, "\". Check the releases page if you are looking for a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
204
230
|
}
|
|
205
231
|
// In case the version is semver (usually release tags) we check that
|
|
206
232
|
// the cloned repository contains the template matching the given version
|
|
@@ -210,8 +236,8 @@ const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, ve
|
|
|
210
236
|
}));
|
|
211
237
|
const versionAsNumber = versionToCheck.replace('v', '');
|
|
212
238
|
if (templatePackageJson.version !== versionAsNumber) {
|
|
213
|
-
var
|
|
214
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
239
|
+
var _context5, _context6;
|
|
240
|
+
throw new Error(_concatInstanceProperty__default["default"](_context5 = _concatInstanceProperty__default["default"](_context6 = "The downloaded template \"".concat(templateName, "\" does not match the version \"")).call(_context6, versionAsNumber, "\", instead got \"")).call(_context5, templatePackageJson.version, "\". Check the releases page if you want to provide a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
215
241
|
}
|
|
216
242
|
}
|
|
217
243
|
};
|
|
@@ -223,14 +249,17 @@ const throwIfInitialProjectKeyIsMissing = initialProjectKey => {
|
|
|
223
249
|
const throwIfNodeVersionIsNotSupported = (currentNodeVersion, expectedVersionRange) => {
|
|
224
250
|
const hasValidNodeVersion = semver__default["default"].satisfies(currentNodeVersion, expectedVersionRange);
|
|
225
251
|
if (!hasValidNodeVersion) {
|
|
226
|
-
var
|
|
227
|
-
throw new Error(_concatInstanceProperty__default["default"](
|
|
252
|
+
var _context7;
|
|
253
|
+
throw new Error(_concatInstanceProperty__default["default"](_context7 = "You are running Node ".concat(currentNodeVersion, " but create-mc-app requires Node ")).call(_context7, expectedVersionRange, ". Please update your version of Node."));
|
|
228
254
|
}
|
|
229
255
|
};
|
|
230
256
|
|
|
231
257
|
const question = (rl, value) => new _Promise__default["default"](resolve => rl.question(value, resolve));
|
|
232
258
|
const getEntryPointUriPath = async (rl, options) => {
|
|
233
259
|
var _context;
|
|
260
|
+
if (options.applicationType === applicationTypes['custom-view']) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
234
263
|
if (options.entryPointUriPath) {
|
|
235
264
|
return options.entryPointUriPath;
|
|
236
265
|
}
|
|
@@ -261,6 +290,7 @@ async function processOptions(projectDirectoryName, options) {
|
|
|
261
290
|
const templateName = options.template;
|
|
262
291
|
|
|
263
292
|
// Validate options
|
|
293
|
+
throwIfApplicationTypeIsNotSupported(options.applicationType);
|
|
264
294
|
throwIfProjectDirectoryExists(projectDirectoryName, projectDirectoryPath);
|
|
265
295
|
throwIfTemplateIsNotSupported(templateName);
|
|
266
296
|
|
|
@@ -273,6 +303,7 @@ async function processOptions(projectDirectoryName, options) {
|
|
|
273
303
|
const initialProjectKey = await getInitialProjectKey(rl, options);
|
|
274
304
|
rl.close();
|
|
275
305
|
return {
|
|
306
|
+
applicationType: options.applicationType,
|
|
276
307
|
projectDirectoryName,
|
|
277
308
|
projectDirectoryPath,
|
|
278
309
|
templateName,
|
|
@@ -292,7 +323,7 @@ function downloadTemplate(options) {
|
|
|
292
323
|
const tmpDir = os__default["default"].tmpdir();
|
|
293
324
|
const tmpFolderNameForClonedRepository = ['merchant-center-application-kit', '--', options.tagOrBranchVersion, '--', _Date$now__default["default"]().toString()].join('');
|
|
294
325
|
const clonedRepositoryPath = path__default["default"].join(tmpDir, tmpFolderNameForClonedRepository);
|
|
295
|
-
const templateFolderPath = path__default["default"].join(clonedRepositoryPath, 'application-templates', options.templateName);
|
|
326
|
+
const templateFolderPath = path__default["default"].join(clonedRepositoryPath, options.applicationType === applicationTypes['custom-view'] ? 'custom-views-templates' : 'application-templates', options.templateName);
|
|
296
327
|
return new listr2.Listr([{
|
|
297
328
|
title: "Cloning repository using branch ".concat(options.tagOrBranchVersion),
|
|
298
329
|
task: async () => {
|
|
@@ -404,10 +435,11 @@ function updatePackageJson(options, releaseVersion) {
|
|
|
404
435
|
};
|
|
405
436
|
}
|
|
406
437
|
|
|
407
|
-
function
|
|
408
|
-
const appName = wordify(options.entryPointUriPath);
|
|
438
|
+
function replaceApplicationInfoInApplicationConfig(filePath, options) {
|
|
409
439
|
const result = core.transformFileSync(filePath, {
|
|
410
|
-
plugins: [function
|
|
440
|
+
plugins: [function replaceConfig() {
|
|
441
|
+
var _options$entryPointUr;
|
|
442
|
+
const appName = wordify((_options$entryPointUr = options.entryPointUriPath) !== null && _options$entryPointUr !== void 0 ? _options$entryPointUr : options.projectDirectoryName);
|
|
411
443
|
return {
|
|
412
444
|
visitor: {
|
|
413
445
|
Identifier(nodePath) {
|
|
@@ -421,7 +453,7 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
421
453
|
}) && nodePath.parent.type === 'ObjectProperty') {
|
|
422
454
|
nodePath.parent.value = core.types.stringLiteral(options.initialProjectKey);
|
|
423
455
|
}
|
|
424
|
-
if (nodePath.isIdentifier({
|
|
456
|
+
if (options.applicationType === applicationTypes['custom-application'] && nodePath.isIdentifier({
|
|
425
457
|
name: 'defaultLabel'
|
|
426
458
|
})) {
|
|
427
459
|
const isMainMenuLinkParent = nodePath.findParent(parentPath => parentPath.isIdentifier({
|
|
@@ -445,12 +477,22 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
445
477
|
});
|
|
446
478
|
}
|
|
447
479
|
}
|
|
448
|
-
function
|
|
480
|
+
function getApplicationConfigName(options) {
|
|
481
|
+
switch (options.applicationType) {
|
|
482
|
+
case applicationTypes['custom-application']:
|
|
483
|
+
return 'custom-application-config';
|
|
484
|
+
case applicationTypes['custom-view']:
|
|
485
|
+
return 'custom-view-config';
|
|
486
|
+
default:
|
|
487
|
+
throw new Error("Unknown application type ".concat(options.applicationType));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function updateApplicationConfig(options) {
|
|
449
491
|
return {
|
|
450
|
-
title: 'Updating
|
|
492
|
+
title: 'Updating application config file',
|
|
451
493
|
task: () => {
|
|
452
|
-
const
|
|
453
|
-
|
|
494
|
+
const configPath = resolveFilePathByExtension(path__default["default"].join(options.projectDirectoryPath, getApplicationConfigName(options)));
|
|
495
|
+
replaceApplicationInfoInApplicationConfig(configPath, options);
|
|
454
496
|
}
|
|
455
497
|
};
|
|
456
498
|
}
|
|
@@ -481,6 +523,7 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
481
523
|
function updateApplicationConstants(options) {
|
|
482
524
|
return {
|
|
483
525
|
title: 'Updating application constants',
|
|
526
|
+
enabled: options.applicationType === applicationTypes['custom-application'],
|
|
484
527
|
task: () => {
|
|
485
528
|
const applicationConstantsPath = resolveFilePathByExtension(path__default["default"].join(options.projectDirectoryPath, 'src/constants'));
|
|
486
529
|
replaceEntryPointUriPathInConstants(applicationConstantsPath, options);
|
|
@@ -499,8 +542,10 @@ process.on('unhandledRejection', err => {
|
|
|
499
542
|
});
|
|
500
543
|
const run = () => {
|
|
501
544
|
// Default command
|
|
502
|
-
cli.command('[project-directory]').usage('[project-directory]\n\n Bootstraps a new Custom Application project using one of the predefined templates.').option('--
|
|
503
|
-
default: '
|
|
545
|
+
cli.command('[project-directory]').usage('[project-directory]\n\n Bootstraps a new Custom Application project using one of the predefined templates.').option('--application-type <type>', '(optional) The type of the application to create: custom-application (default) or custom-view.', {
|
|
546
|
+
default: applicationTypes['custom-application']
|
|
547
|
+
}).option('--template <name>', '(optional) The name of the template to install.', {
|
|
548
|
+
default: availableTemplates.starter
|
|
504
549
|
}).option('--template-version <version>', '(optional) The version of the template to install (either a git tag or a git branch of the "commercetools/merchant-center-application-kit" repository).', {
|
|
505
550
|
default: 'main'
|
|
506
551
|
}).option('--skip-install', '(optional) Skip installing the dependencies after cloning the template.', {
|
|
@@ -516,17 +561,18 @@ const run = () => {
|
|
|
516
561
|
const releaseVersion = await getLatestReleaseVersion();
|
|
517
562
|
hintOutdatedVersion(pkgJson.version, releaseVersion);
|
|
518
563
|
console.log('');
|
|
519
|
-
console.log(
|
|
564
|
+
console.log( // TODO: Use link based on the application type
|
|
565
|
+
"Documentation available at https://docs.commercetools.com/custom-applications");
|
|
520
566
|
console.log('');
|
|
521
567
|
const taskOptions = await processOptions(projectDirectory, options);
|
|
522
568
|
const shouldInstallDependencies = !options.skipInstall ||
|
|
523
569
|
// TODO: remove once we manage to ensure the package manager is installed, for example via Corepack.
|
|
524
570
|
options.packageManager === 'pnpm';
|
|
525
|
-
const taskList = new listr2.Listr(_filterInstanceProperty__default["default"](_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion),
|
|
571
|
+
const taskList = new listr2.Listr(_filterInstanceProperty__default["default"](_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion), updateApplicationConfig(taskOptions), updateApplicationConstants(taskOptions), shouldInstallDependencies && installDependencies(taskOptions)]).call(_context, Boolean));
|
|
526
572
|
await taskList.run();
|
|
527
573
|
const packageManager = getPreferredPackageManager(taskOptions);
|
|
528
574
|
console.log('');
|
|
529
|
-
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The
|
|
575
|
+
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The application has been created in the \"".concat(taskOptions.projectDirectoryName, "\" folder."));
|
|
530
576
|
console.log('');
|
|
531
577
|
console.log("To get started:");
|
|
532
578
|
console.log("$ cd ".concat(taskOptions.projectDirectoryName));
|
|
@@ -535,7 +581,8 @@ const run = () => {
|
|
|
535
581
|
}
|
|
536
582
|
console.log("$ ".concat(packageManager, " start"));
|
|
537
583
|
console.log('');
|
|
538
|
-
console.log(
|
|
584
|
+
console.log( // TODO: Use link based on the application type
|
|
585
|
+
"Visit https://docs.commercetools.com/custom-applications for more info about developing Custom Applications. Enjoy \uD83D\uDE80");
|
|
539
586
|
});
|
|
540
587
|
cli.help();
|
|
541
588
|
cli.version(pkgJson.version);
|