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