@commercetools-frontend/create-mc-app 22.2.1 → 22.3.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 +10 -0
- package/dist/commercetools-frontend-create-mc-app.cjs.dev.js +48 -91
- package/dist/commercetools-frontend-create-mc-app.cjs.prod.js +48 -91
- package/dist/commercetools-frontend-create-mc-app.esm.js +48 -91
- package/dist/declarations/src/types.d.ts +5 -1
- package/dist/declarations/src/utils.d.ts +3 -1
- package/dist/declarations/src/validations.d.ts +2 -2
- package/package.json +10 -3
- package/src/cli.ts +15 -6
- package/src/process-options.ts +1 -0
- package/src/tasks/install-dependencies.ts +3 -3
- package/src/tasks/update-package-json.ts +8 -1
- package/src/types.ts +6 -1
- package/src/utils.ts +16 -0
- package/src/validations.ts +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @commercetools-frontend/create-mc-app
|
|
2
2
|
|
|
3
|
+
## 22.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2976](https://github.com/commercetools/merchant-center-application-kit/pull/2976) [`9add8f46b`](https://github.com/commercetools/merchant-center-application-kit/commit/9add8f46b668fb95b2c966a087bfb00c807ab55e) Thanks [@emmenko](https://github.com/emmenko)! - We migrate from Yarn to Pnpm as the package manager for the App Kit repository. As a result of it there were several packages that didn't specify all the needed dependencies. This is fixed now.
|
|
8
|
+
|
|
9
|
+
- [#3087](https://github.com/commercetools/merchant-center-application-kit/pull/3087) [`31326fc31`](https://github.com/commercetools/merchant-center-application-kit/commit/31326fc315517e98f98b2b661e7b3d8598ca3316) Thanks [@emmenko](https://github.com/emmenko)! - Support new CLI options `--package-manager`. This is useful to explicitly configure the template with the package manager of you choice.
|
|
10
|
+
|
|
11
|
+
For backwards compatibility, Yarn will be automatically used if available if the `--package-manager` option is not provided.
|
|
12
|
+
|
|
3
13
|
## 22.2.1
|
|
4
14
|
|
|
5
15
|
## 22.2.0
|
|
@@ -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.
|
|
70
|
+
version: "22.3.0",
|
|
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: {
|
|
@@ -93,6 +93,8 @@ var pkgJson = {
|
|
|
93
93
|
"@babel/core": "^7.20.12",
|
|
94
94
|
"@babel/runtime": "^7.20.13",
|
|
95
95
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
96
|
+
"@types/babel__core": "^7.20.0",
|
|
97
|
+
"@types/semver": "^7.5.0",
|
|
96
98
|
cac: "6.7.14",
|
|
97
99
|
execa: "5.1.1",
|
|
98
100
|
listr2: "5.0.8",
|
|
@@ -117,14 +119,10 @@ async function getLatestReleaseVersion() {
|
|
|
117
119
|
|
|
118
120
|
function hintOutdatedVersion(currentVersion, releaseVersion) {
|
|
119
121
|
var _context;
|
|
120
|
-
|
|
121
122
|
const hasBeenReleastedInLatestTag = semver__default["default"].gt(releaseVersion, currentVersion);
|
|
122
|
-
|
|
123
123
|
const hintNewerVersions = _filterInstanceProperty__default["default"](_context = [hasBeenReleastedInLatestTag && "".concat(releaseVersion)]).call(_context, Boolean).join(', ');
|
|
124
|
-
|
|
125
124
|
if (hintNewerVersions.length > 0) {
|
|
126
125
|
var _context2;
|
|
127
|
-
|
|
128
126
|
console.log('');
|
|
129
127
|
console.log(_concatInstanceProperty__default["default"](_context2 = "New version available! ".concat(currentVersion, " -> ")).call(_context2, hintNewerVersions));
|
|
130
128
|
console.log('');
|
|
@@ -132,7 +130,6 @@ function hintOutdatedVersion(currentVersion, releaseVersion) {
|
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
const isSemVer = version => /^(v?)([0-9].[0-9].[0-9])+/.test(version);
|
|
135
|
-
|
|
136
133
|
const shouldUseYarn = () => {
|
|
137
134
|
try {
|
|
138
135
|
const result = execa__default["default"].commandSync('yarn --version', {
|
|
@@ -143,28 +140,30 @@ const shouldUseYarn = () => {
|
|
|
143
140
|
return false;
|
|
144
141
|
}
|
|
145
142
|
};
|
|
146
|
-
|
|
143
|
+
const getPreferredPackageManager = options => {
|
|
144
|
+
if (options.packageManager) {
|
|
145
|
+
return options.packageManager;
|
|
146
|
+
}
|
|
147
|
+
// Attempt to use yarn (backwards compatibility)
|
|
148
|
+
if (shouldUseYarn()) {
|
|
149
|
+
return 'yarn';
|
|
150
|
+
}
|
|
151
|
+
// Fall back to npm
|
|
152
|
+
return 'npm';
|
|
153
|
+
};
|
|
147
154
|
const slugify = name => name.toLowerCase().replace(/_/gi, '-');
|
|
148
|
-
|
|
149
155
|
const upperFirst = value => value.charAt(0).toUpperCase() + _sliceInstanceProperty__default["default"](value).call(value, 1);
|
|
150
|
-
|
|
151
156
|
const wordify = slug => {
|
|
152
157
|
var _context;
|
|
153
|
-
|
|
154
158
|
return _mapInstanceProperty__default["default"](_context = slug.split('-')).call(_context, word => upperFirst(word)).join(' ');
|
|
155
159
|
};
|
|
156
|
-
|
|
157
160
|
const resolveFilePathByExtension = requestedModule => {
|
|
158
161
|
var _context2, _context4;
|
|
159
|
-
|
|
160
162
|
const fileExtension = _findInstanceProperty__default["default"](_context2 = ['.js', '.ts', '.mjs', '.cjs']).call(_context2, ext => {
|
|
161
163
|
var _context3;
|
|
162
|
-
|
|
163
164
|
const filePath = _concatInstanceProperty__default["default"](_context3 = "".concat(requestedModule)).call(_context3, ext);
|
|
164
|
-
|
|
165
165
|
return fs__default["default"].existsSync(filePath);
|
|
166
166
|
});
|
|
167
|
-
|
|
168
167
|
return _concatInstanceProperty__default["default"](_context4 = "".concat(requestedModule)).call(_context4, fileExtension);
|
|
169
168
|
};
|
|
170
169
|
|
|
@@ -172,112 +171,91 @@ const availableTemplates = {
|
|
|
172
171
|
starter: 'starter',
|
|
173
172
|
'starter-typescript': 'starter-typescript'
|
|
174
173
|
};
|
|
175
|
-
|
|
176
174
|
const throwIfTemplateIsNotSupported = templateName => {
|
|
177
175
|
var _context;
|
|
178
|
-
|
|
179
176
|
switch (templateName) {
|
|
180
177
|
case availableTemplates.starter:
|
|
181
178
|
case availableTemplates['starter-typescript']:
|
|
182
179
|
break;
|
|
183
|
-
|
|
184
180
|
default:
|
|
185
181
|
const templateNamesList = _Object$keys__default["default"](availableTemplates).toString();
|
|
186
|
-
|
|
187
182
|
throw new Error(_concatInstanceProperty__default["default"](_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\"."));
|
|
188
183
|
}
|
|
189
184
|
};
|
|
190
|
-
|
|
191
185
|
const throwIfProjectDirectoryExists = (dirName, dirPath) => {
|
|
192
186
|
if (fs__default["default"].existsSync(dirPath)) {
|
|
193
187
|
var _context2;
|
|
194
|
-
|
|
195
188
|
throw new Error(_concatInstanceProperty__default["default"](_context2 = "A directory named \"".concat(dirName, "\" already exists at this location \"")).call(_context2, dirPath, "\". Please choose a different project name or remove the directory, then try running the command again."));
|
|
196
189
|
}
|
|
197
190
|
};
|
|
198
|
-
|
|
199
191
|
const throwIfTemplateVersionDoesNotExist = (templateName, templateFolderPath, versionToCheck) => {
|
|
200
192
|
if (!fs__default["default"].existsSync(templateFolderPath)) {
|
|
201
193
|
var _context3;
|
|
202
|
-
|
|
203
194
|
throw new Error(_concatInstanceProperty__default["default"](_context3 = "The downloaded template \"".concat(templateName, "\" does not exist for the given version \"")).call(_context3, versionToCheck, "\". Check the releases page if you are looking for a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
204
|
-
}
|
|
195
|
+
}
|
|
196
|
+
// In case the version is semver (usually release tags) we check that
|
|
205
197
|
// the cloned repository contains the template matching the given version
|
|
206
|
-
|
|
207
|
-
|
|
208
198
|
if (isSemVer(versionToCheck)) {
|
|
209
199
|
const templatePackageJson = JSON.parse(fs__default["default"].readFileSync(path__default["default"].join(templateFolderPath, 'package.json'), {
|
|
210
200
|
encoding: 'utf8'
|
|
211
201
|
}));
|
|
212
202
|
const versionAsNumber = versionToCheck.replace('v', '');
|
|
213
|
-
|
|
214
203
|
if (templatePackageJson.version !== versionAsNumber) {
|
|
215
204
|
var _context4, _context5;
|
|
216
|
-
|
|
217
205
|
throw new Error(_concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "The downloaded template \"".concat(templateName, "\" does not match the version \"")).call(_context5, versionAsNumber, "\", instead got \"")).call(_context4, templatePackageJson.version, "\". Check the releases page if you want to provide a specific version: https://github.com/commercetools/merchant-center-application-kit/releases"));
|
|
218
206
|
}
|
|
219
207
|
}
|
|
220
208
|
};
|
|
221
|
-
|
|
222
209
|
const throwIfInitialProjectKeyIsMissing = initialProjectKey => {
|
|
223
210
|
if (!initialProjectKey) {
|
|
224
211
|
throw new Error("Provide a valid project key that you have access to.");
|
|
225
212
|
}
|
|
226
213
|
};
|
|
227
|
-
|
|
228
214
|
const throwIfNodeVersionIsNotSupported = (currentNodeVersion, expectedVersionRange) => {
|
|
229
215
|
const hasValidNodeVersion = semver__default["default"].satisfies(currentNodeVersion, expectedVersionRange);
|
|
230
|
-
|
|
231
216
|
if (!hasValidNodeVersion) {
|
|
232
217
|
var _context6;
|
|
233
|
-
|
|
234
218
|
throw new Error(_concatInstanceProperty__default["default"](_context6 = "You are running Node ".concat(currentNodeVersion, " but create-mc-app requires Node ")).call(_context6, expectedVersionRange, ". Please update your version of Node."));
|
|
235
219
|
}
|
|
236
220
|
};
|
|
237
221
|
|
|
238
222
|
const question = (rl, value) => new _Promise__default["default"](resolve => rl.question(value, resolve));
|
|
239
|
-
|
|
240
223
|
const getEntryPointUriPath = async (rl, options) => {
|
|
241
224
|
var _context;
|
|
242
|
-
|
|
243
225
|
if (options.entryPointUriPath) {
|
|
244
226
|
return options.entryPointUriPath;
|
|
245
227
|
}
|
|
246
|
-
|
|
247
228
|
const randomEntryPointUriPath = _concatInstanceProperty__default["default"](_context = "".concat(options.template, "-")).call(_context, crypto__default["default"].randomBytes(3).toString('hex'));
|
|
248
|
-
|
|
249
229
|
if (options.yes) {
|
|
250
230
|
return randomEntryPointUriPath;
|
|
251
231
|
}
|
|
252
|
-
|
|
253
232
|
const answerEntryPointUriPath = await question(rl, "Provide the Custom Application entryPointUriPath (default \"".concat(randomEntryPointUriPath, "\"): "));
|
|
254
233
|
return answerEntryPointUriPath || randomEntryPointUriPath;
|
|
255
234
|
};
|
|
256
|
-
|
|
257
235
|
const getInitialProjectKey = async (rl, options) => {
|
|
258
236
|
if (options.initialProjectKey) {
|
|
259
237
|
return options.initialProjectKey;
|
|
260
238
|
}
|
|
261
|
-
|
|
262
239
|
const initialProjectKey = await question(rl, "Provide the initial project key for local development: ");
|
|
263
240
|
throwIfInitialProjectKeyIsMissing(initialProjectKey);
|
|
264
241
|
return initialProjectKey;
|
|
265
242
|
};
|
|
266
|
-
|
|
267
243
|
async function processOptions(projectDirectoryName, options) {
|
|
268
244
|
if (!projectDirectoryName) {
|
|
269
245
|
throw new Error('Missing required argument "[project-directory]"');
|
|
270
246
|
}
|
|
247
|
+
const projectDirectoryPath = path__default["default"].resolve(projectDirectoryName);
|
|
271
248
|
|
|
272
|
-
|
|
273
|
-
|
|
249
|
+
// Parse options
|
|
274
250
|
let tagOrBranchVersion = options.templateVersion || 'main';
|
|
275
251
|
tagOrBranchVersion = isSemVer(tagOrBranchVersion) && !_startsWithInstanceProperty__default["default"](tagOrBranchVersion).call(tagOrBranchVersion, 'v') ? "v".concat(tagOrBranchVersion) : tagOrBranchVersion;
|
|
276
|
-
const templateName = options.template;
|
|
252
|
+
const templateName = options.template;
|
|
277
253
|
|
|
254
|
+
// Validate options
|
|
278
255
|
throwIfProjectDirectoryExists(projectDirectoryName, projectDirectoryPath);
|
|
279
|
-
throwIfTemplateIsNotSupported(templateName);
|
|
256
|
+
throwIfTemplateIsNotSupported(templateName);
|
|
280
257
|
|
|
258
|
+
// Read prompts
|
|
281
259
|
const rl = readline__default["default"].createInterface({
|
|
282
260
|
input: process.stdin,
|
|
283
261
|
output: process.stdout
|
|
@@ -291,18 +269,17 @@ async function processOptions(projectDirectoryName, options) {
|
|
|
291
269
|
templateName,
|
|
292
270
|
tagOrBranchVersion,
|
|
293
271
|
entryPointUriPath,
|
|
294
|
-
initialProjectKey
|
|
272
|
+
initialProjectKey,
|
|
273
|
+
packageManager: options.packageManager
|
|
295
274
|
};
|
|
296
275
|
}
|
|
297
276
|
|
|
298
277
|
const filesToBeRemoved = ['CHANGELOG.md'];
|
|
299
|
-
|
|
300
278
|
function downloadTemplate(options) {
|
|
301
279
|
return {
|
|
302
280
|
title: 'Downloading template',
|
|
303
281
|
task: () => {
|
|
304
282
|
var _context;
|
|
305
|
-
|
|
306
283
|
const tmpDir = os__default["default"].tmpdir();
|
|
307
284
|
const tmpFolderNameForClonedRepository = ['merchant-center-application-kit', '--', options.tagOrBranchVersion, '--', _Date$now__default["default"]().toString()].join('');
|
|
308
285
|
const clonedRepositoryPath = path__default["default"].join(tmpDir, tmpFolderNameForClonedRepository);
|
|
@@ -315,11 +292,9 @@ function downloadTemplate(options) {
|
|
|
315
292
|
cwd: tmpDir,
|
|
316
293
|
encoding: 'utf-8'
|
|
317
294
|
});
|
|
318
|
-
|
|
319
295
|
if (result.failed) {
|
|
320
296
|
throw new Error(result.stderr);
|
|
321
297
|
}
|
|
322
|
-
|
|
323
298
|
throwIfTemplateVersionDoesNotExist(options.templateName, clonedRepositoryPath, options.tagOrBranchVersion);
|
|
324
299
|
return result.stdout;
|
|
325
300
|
}
|
|
@@ -327,21 +302,18 @@ function downloadTemplate(options) {
|
|
|
327
302
|
title: _concatInstanceProperty__default["default"](_context = "Copying template ".concat(options.templateName, " into project directory ")).call(_context, options.projectDirectoryPath),
|
|
328
303
|
task: async () => {
|
|
329
304
|
const command = process.platform === 'win32' || process.platform === 'cygwin' ? 'move' : 'mv';
|
|
330
|
-
const result = await execa__default["default"](command, [templateFolderPath,
|
|
305
|
+
const result = await execa__default["default"](command, [templateFolderPath,
|
|
306
|
+
// Wrap folder path in quotes to avoid issues with empty spaces in the folder names.
|
|
331
307
|
options.projectDirectoryPath], {
|
|
332
308
|
encoding: 'utf-8'
|
|
333
309
|
});
|
|
334
|
-
|
|
335
310
|
if (result.failed) {
|
|
336
311
|
throw new Error(result.stderr);
|
|
337
312
|
}
|
|
338
|
-
|
|
339
313
|
const templatePackageJsonPath = path__default["default"].join(options.projectDirectoryPath, 'package.json');
|
|
340
|
-
|
|
341
314
|
if (!fs__default["default"].existsSync(templatePackageJsonPath)) {
|
|
342
315
|
throw new Error("Unable to verify that the template application has a package.json at \"".concat(templatePackageJsonPath, "\""));
|
|
343
316
|
}
|
|
344
|
-
|
|
345
317
|
return result.stdout;
|
|
346
318
|
}
|
|
347
319
|
}, {
|
|
@@ -351,11 +323,9 @@ function downloadTemplate(options) {
|
|
|
351
323
|
const result = await execa__default["default"](command, _mapInstanceProperty__default["default"](filesToBeRemoved).call(filesToBeRemoved, filePath => path__default["default"].join(options.projectDirectoryPath, filePath)), {
|
|
352
324
|
encoding: 'utf-8'
|
|
353
325
|
});
|
|
354
|
-
|
|
355
326
|
if (result.failed) {
|
|
356
327
|
throw new Error(result.stderr);
|
|
357
328
|
}
|
|
358
|
-
|
|
359
329
|
return result.stdout;
|
|
360
330
|
}
|
|
361
331
|
}]);
|
|
@@ -367,10 +337,10 @@ function installDependencies(options) {
|
|
|
367
337
|
return {
|
|
368
338
|
title: 'Installing dependencies (this might take a while)',
|
|
369
339
|
task: () => {
|
|
370
|
-
const
|
|
371
|
-
const packageManager = useYarn ? 'yarn' : 'npm'; // TODO: we could check for min yarn/npm versions
|
|
372
|
-
// See https://github.com/facebook/create-react-app/blob/0f4781e8507249ce29a9ac1409fece67c1a53c38/packages/create-react-app/createReactApp.js#L225-L254
|
|
340
|
+
const packageManager = getPreferredPackageManager(options);
|
|
373
341
|
|
|
342
|
+
// TODO: we could check for min yarn/npm versions
|
|
343
|
+
// See https://github.com/facebook/create-react-app/blob/0f4781e8507249ce29a9ac1409fece67c1a53c38/packages/create-react-app/createReactApp.js#L225-L254
|
|
374
344
|
return execa__default["default"](packageManager, ['install'], {
|
|
375
345
|
cwd: options.projectDirectoryPath,
|
|
376
346
|
encoding: 'utf-8'
|
|
@@ -380,25 +350,20 @@ function installDependencies(options) {
|
|
|
380
350
|
}
|
|
381
351
|
|
|
382
352
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
383
|
-
|
|
384
353
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
385
|
-
|
|
386
354
|
const replaceApplicationKitPackageVersionWith = function (releaseVersion) {
|
|
387
355
|
var _context;
|
|
388
|
-
|
|
389
356
|
let dependencies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
390
357
|
return _reduceInstanceProperty__default["default"](_context = _Object$entries__default["default"](dependencies)).call(_context, (updatedDependencies, _ref) => {
|
|
391
358
|
let _ref2 = _slicedToArray(_ref, 2),
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
359
|
+
dependencyName = _ref2[0],
|
|
360
|
+
dependencyVersion = _ref2[1];
|
|
395
361
|
const updatedVersion = dependencyVersion === 'workspace:*' ? releaseVersion : dependencyVersion;
|
|
396
362
|
return _objectSpread(_objectSpread({}, updatedDependencies), {}, {
|
|
397
363
|
[dependencyName]: updatedVersion
|
|
398
364
|
});
|
|
399
365
|
}, {});
|
|
400
366
|
};
|
|
401
|
-
|
|
402
367
|
function updatePackageJson(options, releaseVersion) {
|
|
403
368
|
return {
|
|
404
369
|
title: 'Updating package.json',
|
|
@@ -407,7 +372,7 @@ function updatePackageJson(options, releaseVersion) {
|
|
|
407
372
|
const appPackageJson = JSON.parse(fs__default["default"].readFileSync(packageJsonPath, {
|
|
408
373
|
encoding: 'utf8'
|
|
409
374
|
}));
|
|
410
|
-
|
|
375
|
+
const packageManager = getPreferredPackageManager(options);
|
|
411
376
|
const updatedAppPackageJson = _Object$assign__default["default"]({}, appPackageJson, {
|
|
412
377
|
version: '1.0.0',
|
|
413
378
|
// Given the package name is derived from the `projectDirectoryName`
|
|
@@ -418,9 +383,11 @@ function updatePackageJson(options, releaseVersion) {
|
|
|
418
383
|
description: '',
|
|
419
384
|
// Replace the package versions with the `workspace:` syntax to the real version.
|
|
420
385
|
dependencies: replaceApplicationKitPackageVersionWith(releaseVersion, appPackageJson.dependencies),
|
|
421
|
-
devDependencies: replaceApplicationKitPackageVersionWith(releaseVersion, appPackageJson.devDependencies)
|
|
386
|
+
devDependencies: replaceApplicationKitPackageVersionWith(releaseVersion, appPackageJson.devDependencies),
|
|
387
|
+
scripts: _objectSpread(_objectSpread({}, appPackageJson.scripts), {}, {
|
|
388
|
+
'start:prod:local': appPackageJson.scripts['start:prod:local'].replace('yarn', packageManager)
|
|
389
|
+
})
|
|
422
390
|
});
|
|
423
|
-
|
|
424
391
|
fs__default["default"].writeFileSync(packageJsonPath, _JSON$stringify__default["default"](updatedAppPackageJson, null, 2) + os__default["default"].EOL, {
|
|
425
392
|
encoding: 'utf8'
|
|
426
393
|
});
|
|
@@ -440,32 +407,27 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
440
407
|
}) && nodePath.parent.type === 'ObjectProperty') {
|
|
441
408
|
nodePath.parent.value = core.types.stringLiteral(appName);
|
|
442
409
|
}
|
|
443
|
-
|
|
444
410
|
if (nodePath.isIdentifier({
|
|
445
411
|
name: 'initialProjectKey'
|
|
446
412
|
}) && nodePath.parent.type === 'ObjectProperty') {
|
|
447
413
|
nodePath.parent.value = core.types.stringLiteral(options.initialProjectKey);
|
|
448
414
|
}
|
|
449
|
-
|
|
450
415
|
if (nodePath.isIdentifier({
|
|
451
416
|
name: 'defaultLabel'
|
|
452
417
|
})) {
|
|
453
418
|
const isMainMenuLinkParent = nodePath.findParent(parentPath => parentPath.isIdentifier({
|
|
454
419
|
name: 'mainMenuLink'
|
|
455
420
|
}));
|
|
456
|
-
|
|
457
421
|
if (isMainMenuLinkParent && nodePath.parent.type === 'ObjectProperty') {
|
|
458
422
|
nodePath.parent.value = core.types.stringLiteral(appName);
|
|
459
423
|
}
|
|
460
424
|
}
|
|
461
425
|
}
|
|
462
|
-
|
|
463
426
|
}
|
|
464
427
|
};
|
|
465
428
|
}],
|
|
466
429
|
retainLines: true
|
|
467
430
|
});
|
|
468
|
-
|
|
469
431
|
if (result !== null && result !== void 0 && result.code) {
|
|
470
432
|
const prettierConfig = prettier__default["default"].resolveConfig.sync(options.projectDirectoryPath);
|
|
471
433
|
const formattedData = prettier__default["default"].format(result.code + os__default["default"].EOL, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : undefined);
|
|
@@ -474,7 +436,6 @@ function replaceApplicationInfoInCustomApplicationConfig(filePath, options) {
|
|
|
474
436
|
});
|
|
475
437
|
}
|
|
476
438
|
}
|
|
477
|
-
|
|
478
439
|
function updateCustomApplicationConfig(options) {
|
|
479
440
|
return {
|
|
480
441
|
title: 'Updating Custom Applications config',
|
|
@@ -495,13 +456,11 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
495
456
|
nodePath.node.init = core.types.stringLiteral(options.entryPointUriPath);
|
|
496
457
|
}
|
|
497
458
|
}
|
|
498
|
-
|
|
499
459
|
}
|
|
500
460
|
};
|
|
501
461
|
}],
|
|
502
462
|
retainLines: true
|
|
503
463
|
});
|
|
504
|
-
|
|
505
464
|
if (result !== null && result !== void 0 && result.code) {
|
|
506
465
|
const prettierConfig = prettier__default["default"].resolveConfig.sync(options.projectDirectoryPath);
|
|
507
466
|
const formattedData = prettier__default["default"].format(result.code + os__default["default"].EOL, prettierConfig !== null && prettierConfig !== void 0 ? prettierConfig : undefined);
|
|
@@ -510,7 +469,6 @@ function replaceEntryPointUriPathInConstants(filePath, options) {
|
|
|
510
469
|
});
|
|
511
470
|
}
|
|
512
471
|
}
|
|
513
|
-
|
|
514
472
|
function updateApplicationConstants(options) {
|
|
515
473
|
return {
|
|
516
474
|
title: 'Updating application constants',
|
|
@@ -522,14 +480,14 @@ function updateApplicationConstants(options) {
|
|
|
522
480
|
}
|
|
523
481
|
|
|
524
482
|
throwIfNodeVersionIsNotSupported(process.versions.node, pkgJson.engines.node);
|
|
525
|
-
const cli = cac.cac('create-mc-app');
|
|
483
|
+
const cli = cac.cac('create-mc-app');
|
|
484
|
+
|
|
485
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
526
486
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
527
487
|
// terminate the Node.js process with a non-zero exit code.
|
|
528
|
-
|
|
529
488
|
process.on('unhandledRejection', err => {
|
|
530
489
|
throw err;
|
|
531
490
|
});
|
|
532
|
-
|
|
533
491
|
const run = () => {
|
|
534
492
|
// Default command
|
|
535
493
|
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.', {
|
|
@@ -540,34 +498,33 @@ const run = () => {
|
|
|
540
498
|
default: false
|
|
541
499
|
}).option('--yes', '(optional) If set, the prompt options with default values will be skipped.', {
|
|
542
500
|
default: false
|
|
543
|
-
}).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) => {
|
|
501
|
+
}).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.').option('--package-manager <value>', '(optional) The preferred package manager to use: npm, yarn, pnpm.').action(async (projectDirectory, options) => {
|
|
544
502
|
var _context;
|
|
545
|
-
|
|
546
503
|
if (!projectDirectory) {
|
|
547
504
|
cli.outputHelp();
|
|
548
505
|
return;
|
|
549
506
|
}
|
|
550
|
-
|
|
551
507
|
const releaseVersion = await getLatestReleaseVersion();
|
|
552
508
|
hintOutdatedVersion(pkgJson.version, releaseVersion);
|
|
553
509
|
console.log('');
|
|
554
510
|
console.log("Documentation available at https://docs.commercetools.com/custom-applications");
|
|
555
511
|
console.log('');
|
|
556
512
|
const taskOptions = await processOptions(projectDirectory, options);
|
|
557
|
-
const
|
|
513
|
+
const shouldInstallDependencies = !options.skipInstall ||
|
|
514
|
+
// TODO: remove once we manage to ensure the package manager is installed, for example via Corepack.
|
|
515
|
+
options.packageManager === 'pnpm';
|
|
516
|
+
const taskList = new listr2.Listr(_filterInstanceProperty__default["default"](_context = [downloadTemplate(taskOptions), updatePackageJson(taskOptions, releaseVersion), updateCustomApplicationConfig(taskOptions), updateApplicationConstants(taskOptions), shouldInstallDependencies && installDependencies(taskOptions)]).call(_context, Boolean));
|
|
558
517
|
await taskList.run();
|
|
559
|
-
const
|
|
518
|
+
const packageManager = getPreferredPackageManager(taskOptions);
|
|
560
519
|
console.log('');
|
|
561
520
|
console.log("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 The Custom Application has been created in the \"".concat(taskOptions.projectDirectoryName, "\" folder."));
|
|
562
521
|
console.log('');
|
|
563
522
|
console.log("To get started:");
|
|
564
523
|
console.log("$ cd ".concat(taskOptions.projectDirectoryName));
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
console.log("$ ".concat(useYarn ? 'yarn' : 'npm', " install"));
|
|
524
|
+
if (!shouldInstallDependencies) {
|
|
525
|
+
console.log("$ ".concat(packageManager, " install"));
|
|
568
526
|
}
|
|
569
|
-
|
|
570
|
-
console.log("$ ".concat(useYarn ? 'yarn' : 'npm', " start"));
|
|
527
|
+
console.log("$ ".concat(packageManager, " start"));
|
|
571
528
|
console.log('');
|
|
572
529
|
console.log("Visit https://docs.commercetools.com/custom-applications for more info about developing Custom Applications. Enjoy \uD83D\uDE80");
|
|
573
530
|
});
|