@commercetools-frontend/create-mc-app 21.23.10 → 21.24.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/CHANGELOG.md +8 -0
- package/dist/commercetools-frontend-create-mc-app.cjs.dev.js +274 -519
- package/dist/commercetools-frontend-create-mc-app.cjs.prod.js +274 -519
- package/dist/commercetools-frontend-create-mc-app.esm.js +263 -507
- package/package.json +2 -2
- package/src/cli.ts +4 -4
- package/src/process-options.ts +3 -3
- package/src/tasks/download-template.ts +1 -1
- package/src/tasks/install-dependencies.ts +1 -1
- package/src/tasks/update-application-constants.ts +3 -3
- package/src/tasks/update-custom-application-config.ts +3 -3
- package/src/tasks/update-package-json.ts +2 -2
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/esm/asyncToGenerator';
|
|
2
|
-
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
3
1
|
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
4
2
|
import { cac } from 'cac';
|
|
5
3
|
import { Listr } from 'listr2';
|
|
6
|
-
import _Date$now from '@babel/runtime-corejs3/core-js-stable/date/now';
|
|
7
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
8
|
-
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
import os from 'os';
|
|
11
|
-
import path from 'path';
|
|
12
4
|
import execa from 'execa';
|
|
13
|
-
import
|
|
5
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
14
6
|
import semver from 'semver';
|
|
7
|
+
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
8
|
+
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
9
|
+
import crypto from 'crypto';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import readline from 'readline';
|
|
15
12
|
import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
|
|
13
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
16
14
|
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
17
|
+
import _Date$now from '@babel/runtime-corejs3/core-js-stable/date/now';
|
|
18
|
+
import os from 'os';
|
|
17
19
|
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
18
20
|
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
19
21
|
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
@@ -26,20 +28,77 @@ import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/insta
|
|
|
26
28
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
27
29
|
import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign';
|
|
28
30
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
29
|
-
import prettier from 'prettier';
|
|
30
31
|
import { transformFileSync, types } from '@babel/core';
|
|
31
|
-
import
|
|
32
|
-
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
33
|
-
import readline from 'readline';
|
|
34
|
-
import crypto from 'crypto';
|
|
32
|
+
import prettier from 'prettier';
|
|
35
33
|
|
|
36
|
-
var
|
|
37
|
-
|
|
34
|
+
var pkgJson = {
|
|
35
|
+
name: "@commercetools-frontend/create-mc-app",
|
|
36
|
+
version: "21.24.0",
|
|
37
|
+
description: "Create Merchant Center applications to quickly get up and running",
|
|
38
|
+
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
39
|
+
repository: {
|
|
40
|
+
type: "git",
|
|
41
|
+
url: "https://github.com/commercetools/merchant-center-application-kit.git",
|
|
42
|
+
directory: "packages/create-mc-app"
|
|
43
|
+
},
|
|
44
|
+
homepage: "https://docs.commercetools.com/custom-applications",
|
|
45
|
+
keywords: [
|
|
46
|
+
"javascript",
|
|
47
|
+
"frontend",
|
|
48
|
+
"react",
|
|
49
|
+
"toolkit"
|
|
50
|
+
],
|
|
51
|
+
license: "MIT",
|
|
52
|
+
publishConfig: {
|
|
53
|
+
access: "public"
|
|
54
|
+
},
|
|
55
|
+
main: "dist/commercetools-frontend-create-mc-app.cjs.js",
|
|
56
|
+
module: "dist/commercetools-frontend-create-mc-app.esm.js",
|
|
57
|
+
bin: "./bin/cli.js",
|
|
58
|
+
dependencies: {
|
|
59
|
+
"@babel/core": "^7.20.12",
|
|
60
|
+
"@babel/runtime": "^7.20.13",
|
|
61
|
+
"@babel/runtime-corejs3": "^7.20.13",
|
|
62
|
+
cac: "6.7.14",
|
|
63
|
+
execa: "5.1.1",
|
|
64
|
+
listr2: "5.0.8",
|
|
65
|
+
prettier: "2.8.4",
|
|
66
|
+
semver: "7.3.8"
|
|
67
|
+
},
|
|
68
|
+
engines: {
|
|
69
|
+
node: "14.x || >=16.0.0"
|
|
70
|
+
}
|
|
38
71
|
};
|
|
39
72
|
|
|
40
|
-
|
|
73
|
+
async function getLatestReleaseVersion() {
|
|
74
|
+
const commandResult = await execa.command('npm view @commercetools-frontend/create-mc-app --json', {
|
|
75
|
+
encoding: 'utf-8'
|
|
76
|
+
});
|
|
77
|
+
const packageInfoForTagLatest = JSON.parse(commandResult.stdout);
|
|
78
|
+
return packageInfoForTagLatest.version;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function hintOutdatedVersion(currentVersion, releaseVersion) {
|
|
82
|
+
var _context;
|
|
83
|
+
|
|
84
|
+
const hasBeenReleastedInLatestTag = semver.gt(releaseVersion, currentVersion);
|
|
85
|
+
|
|
86
|
+
const hintNewerVersions = _filterInstanceProperty(_context = [hasBeenReleastedInLatestTag && "".concat(releaseVersion)]).call(_context, Boolean).join(', ');
|
|
87
|
+
|
|
88
|
+
if (hintNewerVersions.length > 0) {
|
|
89
|
+
var _context2;
|
|
90
|
+
|
|
91
|
+
console.log('');
|
|
92
|
+
console.log(_concatInstanceProperty(_context2 = "New version available! ".concat(currentVersion, " -> ")).call(_context2, hintNewerVersions));
|
|
93
|
+
console.log('');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const isSemVer = version => /^(v?)([0-9].[0-9].[0-9])+/.test(version);
|
|
98
|
+
|
|
99
|
+
const shouldUseYarn = () => {
|
|
41
100
|
try {
|
|
42
|
-
|
|
101
|
+
const result = execa.commandSync('yarn --version', {
|
|
43
102
|
stdio: 'ignore'
|
|
44
103
|
});
|
|
45
104
|
return !result.failed;
|
|
@@ -48,29 +107,23 @@ var shouldUseYarn = function shouldUseYarn() {
|
|
|
48
107
|
}
|
|
49
108
|
};
|
|
50
109
|
|
|
51
|
-
|
|
52
|
-
return name.toLowerCase().replace(/_/gi, '-');
|
|
53
|
-
};
|
|
110
|
+
const slugify = name => name.toLowerCase().replace(/_/gi, '-');
|
|
54
111
|
|
|
55
|
-
|
|
56
|
-
return value.charAt(0).toUpperCase() + _sliceInstanceProperty(value).call(value, 1);
|
|
57
|
-
};
|
|
112
|
+
const upperFirst = value => value.charAt(0).toUpperCase() + _sliceInstanceProperty(value).call(value, 1);
|
|
58
113
|
|
|
59
|
-
|
|
114
|
+
const wordify = slug => {
|
|
60
115
|
var _context;
|
|
61
116
|
|
|
62
|
-
return _mapInstanceProperty(_context = slug.split('-')).call(_context,
|
|
63
|
-
return upperFirst(word);
|
|
64
|
-
}).join(' ');
|
|
117
|
+
return _mapInstanceProperty(_context = slug.split('-')).call(_context, word => upperFirst(word)).join(' ');
|
|
65
118
|
};
|
|
66
119
|
|
|
67
|
-
|
|
120
|
+
const resolveFilePathByExtension = requestedModule => {
|
|
68
121
|
var _context2, _context4;
|
|
69
122
|
|
|
70
|
-
|
|
123
|
+
const fileExtension = _findInstanceProperty(_context2 = ['.js', '.ts', '.mjs', '.cjs']).call(_context2, ext => {
|
|
71
124
|
var _context3;
|
|
72
125
|
|
|
73
|
-
|
|
126
|
+
const filePath = _concatInstanceProperty(_context3 = "".concat(requestedModule)).call(_context3, ext);
|
|
74
127
|
|
|
75
128
|
return fs.existsSync(filePath);
|
|
76
129
|
});
|
|
@@ -78,12 +131,12 @@ var resolveFilePathByExtension = function resolveFilePathByExtension(requestedMo
|
|
|
78
131
|
return _concatInstanceProperty(_context4 = "".concat(requestedModule)).call(_context4, fileExtension);
|
|
79
132
|
};
|
|
80
133
|
|
|
81
|
-
|
|
134
|
+
const availableTemplates = {
|
|
82
135
|
starter: 'starter',
|
|
83
136
|
'starter-typescript': 'starter-typescript'
|
|
84
137
|
};
|
|
85
138
|
|
|
86
|
-
|
|
139
|
+
const throwIfTemplateIsNotSupported = templateName => {
|
|
87
140
|
var _context;
|
|
88
141
|
|
|
89
142
|
switch (templateName) {
|
|
@@ -92,13 +145,13 @@ var throwIfTemplateIsNotSupported = function throwIfTemplateIsNotSupported(templ
|
|
|
92
145
|
break;
|
|
93
146
|
|
|
94
147
|
default:
|
|
95
|
-
|
|
148
|
+
const templateNamesList = _Object$keys(availableTemplates).toString();
|
|
96
149
|
|
|
97
150
|
throw new Error(_concatInstanceProperty(_context = "The provided template name \"".concat(templateName, "\" does not exist. Available templates are \"")).call(_context, templateNamesList, "\". Make sure you are also using the latest version of \"@commercetools-frontend/create-mc-app\"."));
|
|
98
151
|
}
|
|
99
152
|
};
|
|
100
153
|
|
|
101
|
-
|
|
154
|
+
const throwIfProjectDirectoryExists = (dirName, dirPath) => {
|
|
102
155
|
if (fs.existsSync(dirPath)) {
|
|
103
156
|
var _context2;
|
|
104
157
|
|
|
@@ -106,7 +159,7 @@ var throwIfProjectDirectoryExists = function throwIfProjectDirectoryExists(dirNa
|
|
|
106
159
|
}
|
|
107
160
|
};
|
|
108
161
|
|
|
109
|
-
|
|
162
|
+
const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, versionToCheck) => {
|
|
110
163
|
if (!fs.existsSync(templateFolderPath)) {
|
|
111
164
|
var _context3;
|
|
112
165
|
|
|
@@ -116,10 +169,10 @@ var throwIfTemplateVersionDoesNotExist = function throwIfTemplateVersionDoesNotE
|
|
|
116
169
|
|
|
117
170
|
|
|
118
171
|
if (isSemVer(versionToCheck)) {
|
|
119
|
-
|
|
172
|
+
const templatePackageJson = JSON.parse(fs.readFileSync(path.join(templateFolderPath, 'package.json'), {
|
|
120
173
|
encoding: 'utf8'
|
|
121
174
|
}));
|
|
122
|
-
|
|
175
|
+
const versionAsNumber = versionToCheck.replace('v', '');
|
|
123
176
|
|
|
124
177
|
if (templatePackageJson.version !== versionAsNumber) {
|
|
125
178
|
var _context4, _context5;
|
|
@@ -129,14 +182,14 @@ var throwIfTemplateVersionDoesNotExist = function throwIfTemplateVersionDoesNotE
|
|
|
129
182
|
}
|
|
130
183
|
};
|
|
131
184
|
|
|
132
|
-
|
|
185
|
+
const throwIfInitialProjectKeyIsMissing = initialProjectKey => {
|
|
133
186
|
if (!initialProjectKey) {
|
|
134
187
|
throw new Error("Provide a valid project key that you have access to.");
|
|
135
188
|
}
|
|
136
189
|
};
|
|
137
190
|
|
|
138
|
-
|
|
139
|
-
|
|
191
|
+
const throwIfNodeVersionIsNotSupported = (currentNodeVersion, expectedVersionRange) => {
|
|
192
|
+
const hasValidNodeVersion = semver.satisfies(currentNodeVersion, expectedVersionRange);
|
|
140
193
|
|
|
141
194
|
if (!hasValidNodeVersion) {
|
|
142
195
|
var _context6;
|
|
@@ -145,158 +198,129 @@ var throwIfNodeVersionIsNotSupported = function throwIfNodeVersionIsNotSupported
|
|
|
145
198
|
}
|
|
146
199
|
};
|
|
147
200
|
|
|
148
|
-
|
|
201
|
+
const question = (rl, value) => new _Promise(resolve => rl.question(value, resolve));
|
|
202
|
+
|
|
203
|
+
const getEntryPointUriPath = async (rl, options) => {
|
|
204
|
+
var _context;
|
|
205
|
+
|
|
206
|
+
if (options.entryPointUriPath) {
|
|
207
|
+
return options.entryPointUriPath;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const randomEntryPointUriPath = _concatInstanceProperty(_context = "".concat(options.template, "-")).call(_context, crypto.randomBytes(3).toString('hex'));
|
|
211
|
+
|
|
212
|
+
if (options.yes) {
|
|
213
|
+
return randomEntryPointUriPath;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const answerEntryPointUriPath = await question(rl, "Provide the Custom Application entryPointUriPath (default \"".concat(randomEntryPointUriPath, "\"): "));
|
|
217
|
+
return answerEntryPointUriPath || randomEntryPointUriPath;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const getInitialProjectKey = async (rl, options) => {
|
|
221
|
+
if (options.initialProjectKey) {
|
|
222
|
+
return options.initialProjectKey;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const initialProjectKey = await question(rl, "Provide the initial project key for local development: ");
|
|
226
|
+
throwIfInitialProjectKeyIsMissing(initialProjectKey);
|
|
227
|
+
return initialProjectKey;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
async function processOptions(projectDirectoryName, options) {
|
|
231
|
+
if (!projectDirectoryName) {
|
|
232
|
+
throw new Error('Missing required argument "[project-directory]"');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const projectDirectoryPath = path.resolve(projectDirectoryName); // Parse options
|
|
236
|
+
|
|
237
|
+
let tagOrBranchVersion = options.templateVersion || 'main';
|
|
238
|
+
tagOrBranchVersion = isSemVer(tagOrBranchVersion) && !_startsWithInstanceProperty(tagOrBranchVersion).call(tagOrBranchVersion, 'v') ? "v".concat(tagOrBranchVersion) : tagOrBranchVersion;
|
|
239
|
+
const templateName = options.template; // Validate options
|
|
240
|
+
|
|
241
|
+
throwIfProjectDirectoryExists(projectDirectoryName, projectDirectoryPath);
|
|
242
|
+
throwIfTemplateIsNotSupported(templateName); // Read prompts
|
|
243
|
+
|
|
244
|
+
const rl = readline.createInterface({
|
|
245
|
+
input: process.stdin,
|
|
246
|
+
output: process.stdout
|
|
247
|
+
});
|
|
248
|
+
const entryPointUriPath = await getEntryPointUriPath(rl, options);
|
|
249
|
+
const initialProjectKey = await getInitialProjectKey(rl, options);
|
|
250
|
+
rl.close();
|
|
251
|
+
return {
|
|
252
|
+
projectDirectoryName,
|
|
253
|
+
projectDirectoryPath,
|
|
254
|
+
templateName,
|
|
255
|
+
tagOrBranchVersion,
|
|
256
|
+
entryPointUriPath,
|
|
257
|
+
initialProjectKey
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const filesToBeRemoved = ['CHANGELOG.md'];
|
|
149
262
|
|
|
150
263
|
function downloadTemplate(options) {
|
|
151
264
|
return {
|
|
152
265
|
title: 'Downloading template',
|
|
153
|
-
task:
|
|
154
|
-
var
|
|
266
|
+
task: () => {
|
|
267
|
+
var _context;
|
|
155
268
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
269
|
+
const tmpDir = os.tmpdir();
|
|
270
|
+
const tmpFolderNameForClonedRepository = ['merchant-center-application-kit', '--', options.tagOrBranchVersion, '--', _Date$now().toString()].join('');
|
|
271
|
+
const clonedRepositoryPath = path.join(tmpDir, tmpFolderNameForClonedRepository);
|
|
272
|
+
const templateFolderPath = path.join(clonedRepositoryPath, 'application-templates', options.templateName);
|
|
160
273
|
return new Listr([{
|
|
161
274
|
title: "Cloning repository using branch ".concat(options.tagOrBranchVersion),
|
|
162
|
-
task:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
cwd: tmpDir,
|
|
172
|
-
encoding: 'utf-8'
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
case 2:
|
|
176
|
-
result = _context.sent;
|
|
177
|
-
|
|
178
|
-
if (!result.failed) {
|
|
179
|
-
_context.next = 5;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
throw new Error(result.stderr);
|
|
184
|
-
|
|
185
|
-
case 5:
|
|
186
|
-
throwIfTemplateVersionDoesNotExist(options.templateName, clonedRepositoryPath, options.tagOrBranchVersion);
|
|
187
|
-
return _context.abrupt("return", result.stdout);
|
|
188
|
-
|
|
189
|
-
case 7:
|
|
190
|
-
case "end":
|
|
191
|
-
return _context.stop();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}, _callee);
|
|
195
|
-
}));
|
|
196
|
-
|
|
197
|
-
function task() {
|
|
198
|
-
return _task.apply(this, arguments);
|
|
275
|
+
task: async () => {
|
|
276
|
+
// Shallow clone repository
|
|
277
|
+
const result = await execa('git', ['clone', "--branch=".concat(options.tagOrBranchVersion), '--depth=1', 'https://github.com/commercetools/merchant-center-application-kit.git', tmpFolderNameForClonedRepository], {
|
|
278
|
+
cwd: tmpDir,
|
|
279
|
+
encoding: 'utf-8'
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
if (result.failed) {
|
|
283
|
+
throw new Error(result.stderr);
|
|
199
284
|
}
|
|
200
285
|
|
|
201
|
-
|
|
202
|
-
|
|
286
|
+
throwIfTemplateVersionDoesNotExist(options.templateName, clonedRepositoryPath, options.tagOrBranchVersion);
|
|
287
|
+
return result.stdout;
|
|
288
|
+
}
|
|
203
289
|
}, {
|
|
204
|
-
title: _concatInstanceProperty(
|
|
205
|
-
task:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
case 3:
|
|
220
|
-
result = _context3.sent;
|
|
221
|
-
|
|
222
|
-
if (!result.failed) {
|
|
223
|
-
_context3.next = 6;
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
throw new Error(result.stderr);
|
|
228
|
-
|
|
229
|
-
case 6:
|
|
230
|
-
templatePackageJsonPath = path.join(options.projectDirectoryPath, 'package.json');
|
|
231
|
-
|
|
232
|
-
if (fs.existsSync(templatePackageJsonPath)) {
|
|
233
|
-
_context3.next = 9;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
throw new Error("Unable to verify that the template application has a package.json at \"".concat(templatePackageJsonPath, "\""));
|
|
238
|
-
|
|
239
|
-
case 9:
|
|
240
|
-
return _context3.abrupt("return", result.stdout);
|
|
241
|
-
|
|
242
|
-
case 10:
|
|
243
|
-
case "end":
|
|
244
|
-
return _context3.stop();
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}, _callee2);
|
|
248
|
-
}));
|
|
290
|
+
title: _concatInstanceProperty(_context = "Copying template ".concat(options.templateName, " into project directory ")).call(_context, options.projectDirectoryPath),
|
|
291
|
+
task: async () => {
|
|
292
|
+
const command = process.platform === 'win32' || process.platform === 'cygwin' ? 'move' : 'mv';
|
|
293
|
+
const result = await execa(command, [templateFolderPath, // Wrap folder path in quotes to avoid issues with empty spaces in the folder names.
|
|
294
|
+
options.projectDirectoryPath], {
|
|
295
|
+
encoding: 'utf-8'
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
if (result.failed) {
|
|
299
|
+
throw new Error(result.stderr);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const templatePackageJsonPath = path.join(options.projectDirectoryPath, 'package.json');
|
|
249
303
|
|
|
250
|
-
|
|
251
|
-
|
|
304
|
+
if (!fs.existsSync(templatePackageJsonPath)) {
|
|
305
|
+
throw new Error("Unable to verify that the template application has a package.json at \"".concat(templatePackageJsonPath, "\""));
|
|
252
306
|
}
|
|
253
307
|
|
|
254
|
-
return
|
|
255
|
-
}
|
|
308
|
+
return result.stdout;
|
|
309
|
+
}
|
|
256
310
|
}, {
|
|
257
311
|
title: "Cleaning up project directory",
|
|
258
|
-
task:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
_context4.next = 3;
|
|
267
|
-
return execa(command, _mapInstanceProperty(filesToBeRemoved).call(filesToBeRemoved, function (filePath) {
|
|
268
|
-
return path.join(options.projectDirectoryPath, filePath);
|
|
269
|
-
}), {
|
|
270
|
-
encoding: 'utf-8'
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
case 3:
|
|
274
|
-
result = _context4.sent;
|
|
275
|
-
|
|
276
|
-
if (!result.failed) {
|
|
277
|
-
_context4.next = 6;
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
throw new Error(result.stderr);
|
|
282
|
-
|
|
283
|
-
case 6:
|
|
284
|
-
return _context4.abrupt("return", result.stdout);
|
|
285
|
-
|
|
286
|
-
case 7:
|
|
287
|
-
case "end":
|
|
288
|
-
return _context4.stop();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}, _callee3);
|
|
292
|
-
}));
|
|
293
|
-
|
|
294
|
-
function task() {
|
|
295
|
-
return _task3.apply(this, arguments);
|
|
312
|
+
task: async () => {
|
|
313
|
+
const command = process.platform === 'win32' || process.platform === 'cygwin' ? 'del' : 'rm';
|
|
314
|
+
const result = await execa(command, _mapInstanceProperty(filesToBeRemoved).call(filesToBeRemoved, filePath => path.join(options.projectDirectoryPath, filePath)), {
|
|
315
|
+
encoding: 'utf-8'
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
if (result.failed) {
|
|
319
|
+
throw new Error(result.stderr);
|
|
296
320
|
}
|
|
297
321
|
|
|
298
|
-
return
|
|
299
|
-
}
|
|
322
|
+
return result.stdout;
|
|
323
|
+
}
|
|
300
324
|
}]);
|
|
301
325
|
}
|
|
302
326
|
};
|
|
@@ -305,9 +329,9 @@ function downloadTemplate(options) {
|
|
|
305
329
|
function installDependencies(options) {
|
|
306
330
|
return {
|
|
307
331
|
title: 'Installing dependencies (this might take a while)',
|
|
308
|
-
task:
|
|
309
|
-
|
|
310
|
-
|
|
332
|
+
task: () => {
|
|
333
|
+
const useYarn = shouldUseYarn();
|
|
334
|
+
const packageManager = useYarn ? 'yarn' : 'npm'; // TODO: we could check for min yarn/npm versions
|
|
311
335
|
// See https://github.com/facebook/create-react-app/blob/0f4781e8507249ce29a9ac1409fece67c1a53c38/packages/create-react-app/createReactApp.js#L225-L254
|
|
312
336
|
|
|
313
337
|
return execa(packageManager, ['install'], {
|
|
@@ -322,30 +346,32 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
|
322
346
|
|
|
323
347
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
324
348
|
|
|
325
|
-
|
|
349
|
+
const replaceApplicationKitPackageVersionWith = function (releaseVersion) {
|
|
326
350
|
var _context;
|
|
327
351
|
|
|
328
|
-
|
|
329
|
-
return _reduceInstanceProperty(_context = _Object$entries(dependencies)).call(_context,
|
|
330
|
-
|
|
352
|
+
let dependencies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
353
|
+
return _reduceInstanceProperty(_context = _Object$entries(dependencies)).call(_context, (updatedDependencies, _ref) => {
|
|
354
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
331
355
|
dependencyName = _ref2[0],
|
|
332
356
|
dependencyVersion = _ref2[1];
|
|
333
357
|
|
|
334
|
-
|
|
335
|
-
return _objectSpread(_objectSpread({}, updatedDependencies), {},
|
|
358
|
+
const updatedVersion = dependencyVersion === 'workspace:*' ? releaseVersion : dependencyVersion;
|
|
359
|
+
return _objectSpread(_objectSpread({}, updatedDependencies), {}, {
|
|
360
|
+
[dependencyName]: updatedVersion
|
|
361
|
+
});
|
|
336
362
|
}, {});
|
|
337
363
|
};
|
|
338
364
|
|
|
339
365
|
function updatePackageJson(options, releaseVersion) {
|
|
340
366
|
return {
|
|
341
367
|
title: 'Updating package.json',
|
|
342
|
-
task:
|
|
343
|
-
|
|
344
|
-
|
|
368
|
+
task: () => {
|
|
369
|
+
const packageJsonPath = path.join(options.projectDirectoryPath, 'package.json');
|
|
370
|
+
const appPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, {
|
|
345
371
|
encoding: 'utf8'
|
|
346
372
|
}));
|
|
347
373
|
|
|
348
|
-
|
|
374
|
+
const updatedAppPackageJson = _Object$assign({}, appPackageJson, {
|
|
349
375
|
version: '1.0.0',
|
|
350
376
|
// Given the package name is derived from the `projectDirectoryName`
|
|
351
377
|
// the latter needs to be sanitised to have a ensure a valid package name.
|
|
@@ -366,12 +392,12 @@ function updatePackageJson(options, releaseVersion) {
|
|
|
366
392
|
}
|
|
367
393
|
|
|
368
394
|
function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
369
|
-
|
|
370
|
-
|
|
395
|
+
const appName = wordify(options.entryPointUriPath);
|
|
396
|
+
const result = transformFileSync(filePath, {
|
|
371
397
|
plugins: [function replaceCustomApplicationConfig() {
|
|
372
398
|
return {
|
|
373
399
|
visitor: {
|
|
374
|
-
Identifier
|
|
400
|
+
Identifier(nodePath) {
|
|
375
401
|
if (nodePath.isIdentifier({
|
|
376
402
|
name: 'name'
|
|
377
403
|
}) && nodePath.parent.type === 'ObjectProperty') {
|
|
@@ -387,17 +413,16 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
387
413
|
if (nodePath.isIdentifier({
|
|
388
414
|
name: 'defaultLabel'
|
|
389
415
|
})) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
});
|
|
394
|
-
});
|
|
416
|
+
const isMainMenuLinkParent = nodePath.findParent(parentPath => parentPath.isIdentifier({
|
|
417
|
+
name: 'mainMenuLink'
|
|
418
|
+
}));
|
|
395
419
|
|
|
396
420
|
if (isMainMenuLinkParent && nodePath.parent.type === 'ObjectProperty') {
|
|
397
421
|
nodePath.parent.value = types.stringLiteral(appName);
|
|
398
422
|
}
|
|
399
423
|
}
|
|
400
424
|
}
|
|
425
|
+
|
|
401
426
|
}
|
|
402
427
|
};
|
|
403
428
|
}],
|
|
@@ -405,8 +430,8 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
405
430
|
});
|
|
406
431
|
|
|
407
432
|
if (result !== null && result !== void 0 && result.code) {
|
|
408
|
-
|
|
409
|
-
|
|
433
|
+
const prettierConfig = prettier.resolveConfig.sync(options.projectDirectoryPath);
|
|
434
|
+
const formattedData = prettier.format(result.code + os.EOL, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : undefined);
|
|
410
435
|
fs.writeFileSync(filePath, formattedData, {
|
|
411
436
|
encoding: 'utf8'
|
|
412
437
|
});
|
|
@@ -416,23 +441,24 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
416
441
|
function updateCustomApplicationConfig(options) {
|
|
417
442
|
return {
|
|
418
443
|
title: 'Updating Custom Applications config',
|
|
419
|
-
task:
|
|
420
|
-
|
|
444
|
+
task: () => {
|
|
445
|
+
const customApplicationConfigPath = resolveFilePathByExtension(path.join(options.projectDirectoryPath, 'custom-application-config'));
|
|
421
446
|
replaceApplicationInfoInCustomApplicationConfig(customApplicationConfigPath, options);
|
|
422
447
|
}
|
|
423
448
|
};
|
|
424
449
|
}
|
|
425
450
|
|
|
426
451
|
function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
427
|
-
|
|
452
|
+
const result = transformFileSync(filePath, {
|
|
428
453
|
plugins: [function replaceConstants() {
|
|
429
454
|
return {
|
|
430
455
|
visitor: {
|
|
431
|
-
VariableDeclarator
|
|
456
|
+
VariableDeclarator(nodePath) {
|
|
432
457
|
if (nodePath.node.id.type === 'Identifier' && nodePath.node.id.name === 'entryPointUriPath') {
|
|
433
458
|
nodePath.node.init = types.stringLiteral(options.entryPointUriPath);
|
|
434
459
|
}
|
|
435
460
|
}
|
|
461
|
+
|
|
436
462
|
}
|
|
437
463
|
};
|
|
438
464
|
}],
|
|
@@ -440,8 +466,8 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
440
466
|
});
|
|
441
467
|
|
|
442
468
|
if (result !== null && result !== void 0 && result.code) {
|
|
443
|
-
|
|
444
|
-
|
|
469
|
+
const prettierConfig = prettier.resolveConfig.sync(options.projectDirectoryPath);
|
|
470
|
+
const formattedData = prettier.format(result.code + os.EOL, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : undefined);
|
|
445
471
|
fs.writeFileSync(filePath, formattedData, {
|
|
446
472
|
encoding: 'utf8'
|
|
447
473
|
});
|
|
@@ -451,260 +477,23 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
451
477
|
function updateApplicationConstants(options) {
|
|
452
478
|
return {
|
|
453
479
|
title: 'Updating application constants',
|
|
454
|
-
task:
|
|
455
|
-
|
|
480
|
+
task: () => {
|
|
481
|
+
const applicationConstantsPath = resolveFilePathByExtension(path.join(options.projectDirectoryPath, 'src/constants'));
|
|
456
482
|
replaceEntryPointUriPathInConstants(applicationConstantsPath, options);
|
|
457
483
|
}
|
|
458
484
|
};
|
|
459
485
|
}
|
|
460
486
|
|
|
461
|
-
function getLatestReleaseVersion() {
|
|
462
|
-
return _getLatestReleaseVersion.apply(this, arguments);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function _getLatestReleaseVersion() {
|
|
466
|
-
_getLatestReleaseVersion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
467
|
-
var commandResult, packageInfoForTagLatest;
|
|
468
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
469
|
-
while (1) {
|
|
470
|
-
switch (_context.prev = _context.next) {
|
|
471
|
-
case 0:
|
|
472
|
-
_context.next = 2;
|
|
473
|
-
return execa.command('npm view @commercetools-frontend/create-mc-app --json', {
|
|
474
|
-
encoding: 'utf-8'
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
case 2:
|
|
478
|
-
commandResult = _context.sent;
|
|
479
|
-
packageInfoForTagLatest = JSON.parse(commandResult.stdout);
|
|
480
|
-
return _context.abrupt("return", packageInfoForTagLatest.version);
|
|
481
|
-
|
|
482
|
-
case 5:
|
|
483
|
-
case "end":
|
|
484
|
-
return _context.stop();
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}, _callee);
|
|
488
|
-
}));
|
|
489
|
-
return _getLatestReleaseVersion.apply(this, arguments);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function hintOutdatedVersion(currentVersion, releaseVersion) {
|
|
493
|
-
var _context;
|
|
494
|
-
|
|
495
|
-
var hasBeenReleastedInLatestTag = semver.gt(releaseVersion, currentVersion);
|
|
496
|
-
|
|
497
|
-
var hintNewerVersions = _filterInstanceProperty(_context = [hasBeenReleastedInLatestTag && "".concat(releaseVersion)]).call(_context, Boolean).join(', ');
|
|
498
|
-
|
|
499
|
-
if (hintNewerVersions.length > 0) {
|
|
500
|
-
var _context2;
|
|
501
|
-
|
|
502
|
-
console.log('');
|
|
503
|
-
console.log(_concatInstanceProperty(_context2 = "New version available! ".concat(currentVersion, " -> ")).call(_context2, hintNewerVersions));
|
|
504
|
-
console.log('');
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
var question = function question(rl, value) {
|
|
509
|
-
return new _Promise(function (resolve) {
|
|
510
|
-
return rl.question(value, resolve);
|
|
511
|
-
});
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
var getEntryPointUriPath = /*#__PURE__*/function () {
|
|
515
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(rl, options) {
|
|
516
|
-
var _context;
|
|
517
|
-
|
|
518
|
-
var randomEntryPointUriPath, answerEntryPointUriPath;
|
|
519
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
520
|
-
while (1) {
|
|
521
|
-
switch (_context2.prev = _context2.next) {
|
|
522
|
-
case 0:
|
|
523
|
-
if (!options.entryPointUriPath) {
|
|
524
|
-
_context2.next = 2;
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return _context2.abrupt("return", options.entryPointUriPath);
|
|
529
|
-
|
|
530
|
-
case 2:
|
|
531
|
-
randomEntryPointUriPath = _concatInstanceProperty(_context = "".concat(options.template, "-")).call(_context, crypto.randomBytes(3).toString('hex'));
|
|
532
|
-
|
|
533
|
-
if (!options.yes) {
|
|
534
|
-
_context2.next = 5;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return _context2.abrupt("return", randomEntryPointUriPath);
|
|
539
|
-
|
|
540
|
-
case 5:
|
|
541
|
-
_context2.next = 7;
|
|
542
|
-
return question(rl, "Provide the Custom Application entryPointUriPath (default \"".concat(randomEntryPointUriPath, "\"): "));
|
|
543
|
-
|
|
544
|
-
case 7:
|
|
545
|
-
answerEntryPointUriPath = _context2.sent;
|
|
546
|
-
return _context2.abrupt("return", answerEntryPointUriPath || randomEntryPointUriPath);
|
|
547
|
-
|
|
548
|
-
case 9:
|
|
549
|
-
case "end":
|
|
550
|
-
return _context2.stop();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}, _callee);
|
|
554
|
-
}));
|
|
555
|
-
|
|
556
|
-
return function getEntryPointUriPath(_x, _x2) {
|
|
557
|
-
return _ref.apply(this, arguments);
|
|
558
|
-
};
|
|
559
|
-
}();
|
|
560
|
-
|
|
561
|
-
var getInitialProjectKey = /*#__PURE__*/function () {
|
|
562
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(rl, options) {
|
|
563
|
-
var initialProjectKey;
|
|
564
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
565
|
-
while (1) {
|
|
566
|
-
switch (_context3.prev = _context3.next) {
|
|
567
|
-
case 0:
|
|
568
|
-
if (!options.initialProjectKey) {
|
|
569
|
-
_context3.next = 2;
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
return _context3.abrupt("return", options.initialProjectKey);
|
|
574
|
-
|
|
575
|
-
case 2:
|
|
576
|
-
_context3.next = 4;
|
|
577
|
-
return question(rl, "Provide the initial project key for local development: ");
|
|
578
|
-
|
|
579
|
-
case 4:
|
|
580
|
-
initialProjectKey = _context3.sent;
|
|
581
|
-
throwIfInitialProjectKeyIsMissing(initialProjectKey);
|
|
582
|
-
return _context3.abrupt("return", initialProjectKey);
|
|
583
|
-
|
|
584
|
-
case 7:
|
|
585
|
-
case "end":
|
|
586
|
-
return _context3.stop();
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}, _callee2);
|
|
590
|
-
}));
|
|
591
|
-
|
|
592
|
-
return function getInitialProjectKey(_x3, _x4) {
|
|
593
|
-
return _ref2.apply(this, arguments);
|
|
594
|
-
};
|
|
595
|
-
}();
|
|
596
|
-
|
|
597
|
-
function processOptions(_x5, _x6) {
|
|
598
|
-
return _processOptions.apply(this, arguments);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
function _processOptions() {
|
|
602
|
-
_processOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(projectDirectoryName, options) {
|
|
603
|
-
var projectDirectoryPath, tagOrBranchVersion, templateName, rl, entryPointUriPath, initialProjectKey;
|
|
604
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
605
|
-
while (1) {
|
|
606
|
-
switch (_context4.prev = _context4.next) {
|
|
607
|
-
case 0:
|
|
608
|
-
if (projectDirectoryName) {
|
|
609
|
-
_context4.next = 2;
|
|
610
|
-
break;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
throw new Error('Missing required argument "[project-directory]"');
|
|
614
|
-
|
|
615
|
-
case 2:
|
|
616
|
-
projectDirectoryPath = path.resolve(projectDirectoryName); // Parse options
|
|
617
|
-
|
|
618
|
-
tagOrBranchVersion = options.templateVersion || 'main';
|
|
619
|
-
tagOrBranchVersion = isSemVer(tagOrBranchVersion) && !_startsWithInstanceProperty(tagOrBranchVersion).call(tagOrBranchVersion, 'v') ? "v".concat(tagOrBranchVersion) : tagOrBranchVersion;
|
|
620
|
-
templateName = options.template; // Validate options
|
|
621
|
-
|
|
622
|
-
throwIfProjectDirectoryExists(projectDirectoryName, projectDirectoryPath);
|
|
623
|
-
throwIfTemplateIsNotSupported(templateName); // Read prompts
|
|
624
|
-
|
|
625
|
-
rl = readline.createInterface({
|
|
626
|
-
input: process.stdin,
|
|
627
|
-
output: process.stdout
|
|
628
|
-
});
|
|
629
|
-
_context4.next = 11;
|
|
630
|
-
return getEntryPointUriPath(rl, options);
|
|
631
|
-
|
|
632
|
-
case 11:
|
|
633
|
-
entryPointUriPath = _context4.sent;
|
|
634
|
-
_context4.next = 14;
|
|
635
|
-
return getInitialProjectKey(rl, options);
|
|
636
|
-
|
|
637
|
-
case 14:
|
|
638
|
-
initialProjectKey = _context4.sent;
|
|
639
|
-
rl.close();
|
|
640
|
-
return _context4.abrupt("return", {
|
|
641
|
-
projectDirectoryName: projectDirectoryName,
|
|
642
|
-
projectDirectoryPath: projectDirectoryPath,
|
|
643
|
-
templateName: templateName,
|
|
644
|
-
tagOrBranchVersion: tagOrBranchVersion,
|
|
645
|
-
entryPointUriPath: entryPointUriPath,
|
|
646
|
-
initialProjectKey: initialProjectKey
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
case 17:
|
|
650
|
-
case "end":
|
|
651
|
-
return _context4.stop();
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}, _callee3);
|
|
655
|
-
}));
|
|
656
|
-
return _processOptions.apply(this, arguments);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
var pkgJson = {
|
|
660
|
-
name: "@commercetools-frontend/create-mc-app",
|
|
661
|
-
version: "21.23.10",
|
|
662
|
-
description: "Create Merchant Center applications to quickly get up and running",
|
|
663
|
-
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
664
|
-
repository: {
|
|
665
|
-
type: "git",
|
|
666
|
-
url: "https://github.com/commercetools/merchant-center-application-kit.git",
|
|
667
|
-
directory: "packages/create-mc-app"
|
|
668
|
-
},
|
|
669
|
-
homepage: "https://docs.commercetools.com/custom-applications",
|
|
670
|
-
keywords: [
|
|
671
|
-
"javascript",
|
|
672
|
-
"frontend",
|
|
673
|
-
"react",
|
|
674
|
-
"toolkit"
|
|
675
|
-
],
|
|
676
|
-
license: "MIT",
|
|
677
|
-
publishConfig: {
|
|
678
|
-
access: "public"
|
|
679
|
-
},
|
|
680
|
-
main: "dist/commercetools-frontend-create-mc-app.cjs.js",
|
|
681
|
-
module: "dist/commercetools-frontend-create-mc-app.esm.js",
|
|
682
|
-
bin: "./bin/cli.js",
|
|
683
|
-
dependencies: {
|
|
684
|
-
"@babel/core": "^7.20.12",
|
|
685
|
-
"@babel/runtime": "^7.20.13",
|
|
686
|
-
"@babel/runtime-corejs3": "^7.20.13",
|
|
687
|
-
cac: "6.7.14",
|
|
688
|
-
execa: "5.1.1",
|
|
689
|
-
listr2: "5.0.7",
|
|
690
|
-
prettier: "2.8.4",
|
|
691
|
-
semver: "7.3.8"
|
|
692
|
-
},
|
|
693
|
-
engines: {
|
|
694
|
-
node: "14.x || >=16.0.0"
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
|
|
698
487
|
throwIfNodeVersionIsNotSupported(process.versions.node, pkgJson.engines.node);
|
|
699
|
-
|
|
488
|
+
const cli = cac('create-mc-app'); // Makes the script crash on unhandled rejections instead of silently
|
|
700
489
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
701
490
|
// terminate the Node.js process with a non-zero exit code.
|
|
702
491
|
|
|
703
|
-
process.on('unhandledRejection',
|
|
492
|
+
process.on('unhandledRejection', err => {
|
|
704
493
|
throw err;
|
|
705
494
|
});
|
|
706
495
|
|
|
707
|
-
|
|
496
|
+
const run = () => {
|
|
708
497
|
// Default command
|
|
709
498
|
cli.command('[project-directory]').usage('[project-directory]\n\n Bootstraps a new Custom Application project using one of the predefined templates.').option('--template <name>', '(optional) The name of the template to install.', {
|
|
710
499
|
default: 'starter'
|
|
@@ -714,70 +503,37 @@ var run = function run() {
|
|
|
714
503
|
default: false
|
|
715
504
|
}).option('--yes', '(optional) If set, the prompt options with default values will be skipped.', {
|
|
716
505
|
default: false
|
|
717
|
-
}).option('--entry-point-uri-path <value>', '(optional) The version of the template to install. (default: starter-<hash>)').option('--initial-project-key <value>', '(optional) A commercetools project key used for the initial login in development. By default, the value is prompted in the terminal.').action(
|
|
718
|
-
var
|
|
719
|
-
var _context;
|
|
720
|
-
|
|
721
|
-
var releaseVersion, taskOptions, taskList, useYarn;
|
|
722
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
723
|
-
while (1) {
|
|
724
|
-
switch (_context2.prev = _context2.next) {
|
|
725
|
-
case 0:
|
|
726
|
-
if (projectDirectory) {
|
|
727
|
-
_context2.next = 3;
|
|
728
|
-
break;
|
|
729
|
-
}
|
|
506
|
+
}).option('--entry-point-uri-path <value>', '(optional) The version of the template to install. (default: starter-<hash>)').option('--initial-project-key <value>', '(optional) A commercetools project key used for the initial login in development. By default, the value is prompted in the terminal.').action(async (projectDirectory, options) => {
|
|
507
|
+
var _context;
|
|
730
508
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
_context2.next = 5;
|
|
736
|
-
return getLatestReleaseVersion();
|
|
737
|
-
|
|
738
|
-
case 5:
|
|
739
|
-
releaseVersion = _context2.sent;
|
|
740
|
-
hintOutdatedVersion(pkgJson.version, releaseVersion);
|
|
741
|
-
console.log('');
|
|
742
|
-
console.log("Documentation available at https://docs.commercetools.com/custom-applications");
|
|
743
|
-
console.log('');
|
|
744
|
-
_context2.next = 12;
|
|
745
|
-
return processOptions(projectDirectory, options);
|
|
746
|
-
|
|
747
|
-
case 12:
|
|
748
|
-
taskOptions = _context2.sent;
|
|
749
|
-
taskList = new Listr(_filterInstanceProperty(_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion), updateCustomApplicationConfig(taskOptions), updateApplicationConstants(taskOptions), !options.skipInstall && installDependencies(taskOptions)]).call(_context, Boolean));
|
|
750
|
-
_context2.next = 16;
|
|
751
|
-
return taskList.run();
|
|
752
|
-
|
|
753
|
-
case 16:
|
|
754
|
-
useYarn = shouldUseYarn();
|
|
755
|
-
console.log('');
|
|
756
|
-
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The Custom Application has been created in the \"".concat(taskOptions.projectDirectoryName, "\" folder."));
|
|
757
|
-
console.log('');
|
|
758
|
-
console.log("To get started:");
|
|
759
|
-
console.log("$ cd ".concat(taskOptions.projectDirectoryName));
|
|
760
|
-
|
|
761
|
-
if (options.skipInstall) {
|
|
762
|
-
console.log("$ ".concat(useYarn ? 'yarn' : 'npm', " install"));
|
|
763
|
-
}
|
|
509
|
+
if (!projectDirectory) {
|
|
510
|
+
cli.outputHelp();
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
764
513
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
514
|
+
const releaseVersion = await getLatestReleaseVersion();
|
|
515
|
+
hintOutdatedVersion(pkgJson.version, releaseVersion);
|
|
516
|
+
console.log('');
|
|
517
|
+
console.log("Documentation available at https://docs.commercetools.com/custom-applications");
|
|
518
|
+
console.log('');
|
|
519
|
+
const taskOptions = await processOptions(projectDirectory, options);
|
|
520
|
+
const taskList = new Listr(_filterInstanceProperty(_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion), updateCustomApplicationConfig(taskOptions), updateApplicationConstants(taskOptions), !options.skipInstall && installDependencies(taskOptions)]).call(_context, Boolean));
|
|
521
|
+
await taskList.run();
|
|
522
|
+
const useYarn = shouldUseYarn();
|
|
523
|
+
console.log('');
|
|
524
|
+
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The Custom Application has been created in the \"".concat(taskOptions.projectDirectoryName, "\" folder."));
|
|
525
|
+
console.log('');
|
|
526
|
+
console.log("To get started:");
|
|
527
|
+
console.log("$ cd ".concat(taskOptions.projectDirectoryName));
|
|
768
528
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
}, _callee);
|
|
775
|
-
}));
|
|
529
|
+
if (options.skipInstall) {
|
|
530
|
+
console.log("$ ".concat(useYarn ? 'yarn' : 'npm', " install"));
|
|
531
|
+
}
|
|
776
532
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}
|
|
533
|
+
console.log("$ ".concat(useYarn ? 'yarn' : 'npm', " start"));
|
|
534
|
+
console.log('');
|
|
535
|
+
console.log("Visit https://docs.commercetools.com/custom-applications for more info about developing Custom Applications. Enjoy \uD83D\uDE80");
|
|
536
|
+
});
|
|
781
537
|
cli.help();
|
|
782
538
|
cli.version(pkgJson.version);
|
|
783
539
|
cli.parse();
|