esa-cli 0.0.2-beta.14 → 0.0.2-beta.16
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/dist/commands/commit/index.js +22 -4
- package/dist/commands/common/{routineUtils.js → utils.js} +104 -58
- package/dist/commands/deploy/index.js +11 -51
- package/dist/commands/init/helper.js +494 -6
- package/dist/commands/init/index.js +62 -494
- package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
- package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
- package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
- package/dist/commands/init/template.jsonc +50 -5
- package/dist/commands/init/types.js +1 -0
- package/dist/commands/login/index.js +18 -28
- package/dist/commands/utils.js +1 -1
- package/dist/components/mutiLevelSelect.js +19 -20
- package/dist/docs/Commands_en.md +111 -143
- package/dist/docs/Commands_zh_CN.md +110 -144
- package/dist/i18n/locales.json +76 -20
- package/dist/libs/apiService.js +8 -3
- package/dist/libs/git/index.js +80 -6
- package/dist/libs/logger.js +58 -0
- package/dist/utils/checkIsRoutineCreated.js +14 -3
- package/dist/utils/command.js +149 -0
- package/dist/utils/compress.js +42 -4
- package/dist/utils/fileUtils/index.js +30 -34
- package/dist/utils/prompt.js +97 -0
- package/package.json +3 -1
- package/dist/docs/eslint-config-en.md +0 -1
- package/dist/docs/eslint-config.md +0 -73
- package/dist/docs/init-command-quick-test.md +0 -208
- package/dist/docs/init-command-test-guide.md +0 -598
|
@@ -9,14 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { execSync } from 'child_process';
|
|
11
11
|
import path from 'path';
|
|
12
|
+
import { confirm as clackConfirm, isCancel, log, outro } from '@clack/prompts';
|
|
12
13
|
import chalk from 'chalk';
|
|
13
14
|
import fs from 'fs-extra';
|
|
14
|
-
import inquirer from 'inquirer';
|
|
15
15
|
import t from '../../i18n/index.js';
|
|
16
16
|
import logger from '../../libs/logger.js';
|
|
17
17
|
import Template from '../../libs/templates/index.js';
|
|
18
18
|
import { getDirName } from '../../utils/fileUtils/base.js';
|
|
19
|
-
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
19
|
+
import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
20
|
+
import { execCommand } from '../../utils/command.js';
|
|
21
|
+
import promptParameter from '../../utils/prompt.js';
|
|
22
|
+
import Haikunator from 'haikunator';
|
|
23
|
+
import { commitAndDeployVersion } from '../common/utils.js';
|
|
24
|
+
import { exit } from 'process';
|
|
20
25
|
export const getTemplateInstances = (templateHubPath) => {
|
|
21
26
|
return fs
|
|
22
27
|
.readdirSync(templateHubPath)
|
|
@@ -46,6 +51,7 @@ export const transferTemplatesToSelectItem = (configs, templateInstanceList, lan
|
|
|
46
51
|
return {
|
|
47
52
|
label: lang === 'en' ? config.Title_EN : config.Title_ZH,
|
|
48
53
|
value: value,
|
|
54
|
+
hint: lang === 'en' ? config.Desc_EN : config.Desc_ZH,
|
|
49
55
|
children
|
|
50
56
|
};
|
|
51
57
|
});
|
|
@@ -131,12 +137,11 @@ export function checkAndUpdatePackage(packageName) {
|
|
|
131
137
|
' ' +
|
|
132
138
|
t('display_latest_esa_template_version').d(`Latest esa-template version:`) +
|
|
133
139
|
chalk.green(latestVersion));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
name: 'isUpdate',
|
|
140
|
+
logger.stopSpinner();
|
|
141
|
+
const isUpdate = yield clackConfirm({
|
|
137
142
|
message: t('is_update_to_latest_version').d('Do you want to update templates to latest version?')
|
|
138
143
|
});
|
|
139
|
-
if (isUpdate) {
|
|
144
|
+
if (!isCancel(isUpdate) && isUpdate) {
|
|
140
145
|
spinner.start(t('template_updating').d('Updating templates to latest...'));
|
|
141
146
|
execSync(`rm -rf node_modules/${packageName}`, {
|
|
142
147
|
cwd: packageJsonPath
|
|
@@ -185,3 +190,486 @@ export const getAllFrameworkConfig = () => {
|
|
|
185
190
|
const json = JSON.parse(jsonc);
|
|
186
191
|
return json;
|
|
187
192
|
};
|
|
193
|
+
export function getInitParamsFromArgv(argv) {
|
|
194
|
+
const a = argv;
|
|
195
|
+
const HaikunatorCtor = Haikunator;
|
|
196
|
+
const haikunator = new HaikunatorCtor();
|
|
197
|
+
const params = {
|
|
198
|
+
name: ''
|
|
199
|
+
};
|
|
200
|
+
if (a.yes) {
|
|
201
|
+
params.name = haikunator.haikunate();
|
|
202
|
+
params.git = true;
|
|
203
|
+
params.deploy = true;
|
|
204
|
+
params.template = 'Hello World';
|
|
205
|
+
params.framework = undefined;
|
|
206
|
+
params.language = undefined;
|
|
207
|
+
params.yes = true;
|
|
208
|
+
}
|
|
209
|
+
if (typeof a.name === 'string')
|
|
210
|
+
params.name = a.name;
|
|
211
|
+
if (typeof a.template === 'string' && a.template) {
|
|
212
|
+
params.template = a.template;
|
|
213
|
+
params.framework = undefined;
|
|
214
|
+
params.language = undefined;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const fw = a.framework;
|
|
218
|
+
const lang = a.language;
|
|
219
|
+
if (fw) {
|
|
220
|
+
params.framework = fw;
|
|
221
|
+
}
|
|
222
|
+
if (lang) {
|
|
223
|
+
params.language = lang;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (typeof a.git === 'boolean')
|
|
227
|
+
params.git = Boolean(a.git);
|
|
228
|
+
if (typeof a.deploy === 'boolean')
|
|
229
|
+
params.deploy = Boolean(a.deploy);
|
|
230
|
+
return params;
|
|
231
|
+
}
|
|
232
|
+
// 配置项目名称
|
|
233
|
+
export const configProjectName = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
+
if (initParams.name) {
|
|
235
|
+
log.step(`Project name configured ${initParams.name}`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const HaikunatorCtor = Haikunator;
|
|
239
|
+
const haikunator = new HaikunatorCtor();
|
|
240
|
+
const defaultName = haikunator.haikunate();
|
|
241
|
+
const name = (yield promptParameter({
|
|
242
|
+
type: 'text',
|
|
243
|
+
question: `${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
|
|
244
|
+
label: 'Project name',
|
|
245
|
+
defaultValue: defaultName,
|
|
246
|
+
validate: (input) => {
|
|
247
|
+
if (input === '' || input === undefined) {
|
|
248
|
+
initParams.name = defaultName;
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
const regex = /^[a-z0-9-]{2,}$/;
|
|
252
|
+
if (!regex.test(input)) {
|
|
253
|
+
return t('init_name_error').d('Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.');
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
}));
|
|
258
|
+
initParams.name = name;
|
|
259
|
+
});
|
|
260
|
+
export const configCategory = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
261
|
+
if (initParams.category || initParams.framework || initParams.template) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const initMode = (yield promptParameter({
|
|
265
|
+
type: 'select',
|
|
266
|
+
question: 'How would you like to initialize the project?',
|
|
267
|
+
label: 'Init mode',
|
|
268
|
+
choices: [
|
|
269
|
+
{ name: 'Framework Starter', value: 'framework' },
|
|
270
|
+
{
|
|
271
|
+
name: 'Function Template',
|
|
272
|
+
value: 'template'
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}));
|
|
276
|
+
initParams.category = initMode;
|
|
277
|
+
});
|
|
278
|
+
/*
|
|
279
|
+
选择模板
|
|
280
|
+
如果选择的是framework,则选择具体的模版 vue /react等
|
|
281
|
+
如果选择的是template,则选择具体的模版 esa template
|
|
282
|
+
*/
|
|
283
|
+
export const configTemplate = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
|
+
if (initParams.template) {
|
|
285
|
+
log.step(`Template configured ${initParams.template}`);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (initParams.framework) {
|
|
289
|
+
log.step(`Framework configured ${initParams.framework}`);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (initParams.category === 'template') {
|
|
293
|
+
const templateItems = prepareTemplateItems();
|
|
294
|
+
const selectedTemplatePath = yield promptParameter({
|
|
295
|
+
type: 'multiLevelSelect',
|
|
296
|
+
question: 'Select a template:',
|
|
297
|
+
treeItems: templateItems
|
|
298
|
+
});
|
|
299
|
+
if (!selectedTemplatePath)
|
|
300
|
+
return null;
|
|
301
|
+
// TODO
|
|
302
|
+
initParams.template = selectedTemplatePath;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const allFrameworkConfig = getAllFrameworkConfig();
|
|
306
|
+
const fw = (yield promptParameter({
|
|
307
|
+
type: 'select',
|
|
308
|
+
question: 'Select a framework',
|
|
309
|
+
label: 'Framework',
|
|
310
|
+
choices: Object.keys(allFrameworkConfig).map((fw) => {
|
|
311
|
+
var _a;
|
|
312
|
+
return ({
|
|
313
|
+
name: allFrameworkConfig[fw].label,
|
|
314
|
+
value: fw,
|
|
315
|
+
hint: (_a = allFrameworkConfig[fw]) === null || _a === void 0 ? void 0 : _a.hint
|
|
316
|
+
});
|
|
317
|
+
})
|
|
318
|
+
}));
|
|
319
|
+
initParams.framework = fw;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
export const configLanguage = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
|
+
if (initParams.language) {
|
|
324
|
+
log.info(`Language configured ${initParams.language}`);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const framework = initParams.framework;
|
|
328
|
+
if (!framework) {
|
|
329
|
+
log.info('Framework config not configured, language skipped');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const frameworkConfig = getFrameworkConfig(framework);
|
|
333
|
+
if (frameworkConfig.language) {
|
|
334
|
+
const language = (yield promptParameter({
|
|
335
|
+
type: 'select',
|
|
336
|
+
question: t('init_language_select').d('Select programming language:'),
|
|
337
|
+
label: 'Language',
|
|
338
|
+
choices: [
|
|
339
|
+
{
|
|
340
|
+
name: t('init_language_typescript').d('TypeScript (.ts) - Type-safe JavaScript, recommended'),
|
|
341
|
+
value: 'typescript'
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: t('init_language_javascript').d('JavaScript (.js) - Traditional JavaScript'),
|
|
345
|
+
value: 'javascript'
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
defaultValue: 'typescript'
|
|
349
|
+
}));
|
|
350
|
+
initParams.language = language;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
export const createProject = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
354
|
+
var _a;
|
|
355
|
+
if (initParams.template) {
|
|
356
|
+
// resolve template value: it may be a filesystem path or a template title
|
|
357
|
+
let selectedTemplatePath = initParams.template;
|
|
358
|
+
if (!path.isAbsolute(selectedTemplatePath) ||
|
|
359
|
+
!fs.existsSync(selectedTemplatePath)) {
|
|
360
|
+
const instances = getTemplateInstances(templateHubPath);
|
|
361
|
+
const matched = instances.find((it) => it.title === initParams.template);
|
|
362
|
+
if (matched) {
|
|
363
|
+
selectedTemplatePath = matched.path;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (!fs.existsSync(selectedTemplatePath)) {
|
|
367
|
+
outro(`Project creation failed: cannot resolve template "${initParams.template}"`);
|
|
368
|
+
exit(1);
|
|
369
|
+
}
|
|
370
|
+
const res = yield initializeProject(selectedTemplatePath, initParams.name);
|
|
371
|
+
if (!res) {
|
|
372
|
+
outro(`Project creation failed`);
|
|
373
|
+
exit(1);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (initParams.framework) {
|
|
377
|
+
const framework = initParams.framework;
|
|
378
|
+
const frameworkConfig = getFrameworkConfig(framework);
|
|
379
|
+
const command = frameworkConfig.command;
|
|
380
|
+
const templateFlag = ((_a = frameworkConfig.language) === null || _a === void 0 ? void 0 : _a[initParams.language || 'typescript']) || '';
|
|
381
|
+
const extraParams = frameworkConfig.params || '';
|
|
382
|
+
const full = `${command} ${initParams.name} ${templateFlag} ${extraParams}`.trim();
|
|
383
|
+
const res = yield execCommand(['sh', '-lc', full], {
|
|
384
|
+
interactive: true,
|
|
385
|
+
startText: `Starting to execute framework command ${chalk.gray(full)}`,
|
|
386
|
+
doneText: `Framework command executed ${chalk.gray(full)}`
|
|
387
|
+
});
|
|
388
|
+
if (!res.success) {
|
|
389
|
+
outro(`Framework command execution failed`);
|
|
390
|
+
exit(1);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
export const installDependencies = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
395
|
+
if (initParams.template) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
399
|
+
const res = yield execCommand(['npm', 'install'], {
|
|
400
|
+
cwd: targetPath,
|
|
401
|
+
useSpinner: true,
|
|
402
|
+
silent: true,
|
|
403
|
+
startText: 'Installing dependencies',
|
|
404
|
+
doneText: 'Dependencies installed'
|
|
405
|
+
});
|
|
406
|
+
if (!res.success) {
|
|
407
|
+
outro(`Dependencies installation failed`);
|
|
408
|
+
exit(1);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
/**
|
|
412
|
+
* Apply configured file edits (方式1: overwrite) after project scaffold
|
|
413
|
+
*/
|
|
414
|
+
export const applyFileEdits = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
415
|
+
var _a;
|
|
416
|
+
if (!initParams.framework) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
const frameworkConfig = getFrameworkConfig(initParams.framework || '');
|
|
420
|
+
const edits = frameworkConfig.fileEdits || [];
|
|
421
|
+
if (!edits.length)
|
|
422
|
+
return true;
|
|
423
|
+
logger.startSubStep(`Applying file edits`);
|
|
424
|
+
const __dirname = getDirName(import.meta.url);
|
|
425
|
+
try {
|
|
426
|
+
const toRegexFromGlob = (pattern) => {
|
|
427
|
+
// Very small glob subset: *, ?, {a,b,c}
|
|
428
|
+
let escaped = pattern
|
|
429
|
+
.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&') // escape regex specials first
|
|
430
|
+
.replace(/\\\*/g, '.*')
|
|
431
|
+
.replace(/\\\?/g, '.');
|
|
432
|
+
// restore and convert {a,b} to (a|b)
|
|
433
|
+
escaped = escaped.replace(/\\\{([^}]+)\\\}/g, (_, inner) => {
|
|
434
|
+
const parts = inner.split(',').map((s) => s.trim());
|
|
435
|
+
return `(${parts.join('|')})`;
|
|
436
|
+
});
|
|
437
|
+
return new RegExp('^' + escaped + '$');
|
|
438
|
+
};
|
|
439
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
440
|
+
const listRootFiles = () => {
|
|
441
|
+
try {
|
|
442
|
+
return fs.readdirSync(targetPath);
|
|
443
|
+
}
|
|
444
|
+
catch (_a) {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
for (const edit of edits) {
|
|
449
|
+
if (((_a = edit.when) === null || _a === void 0 ? void 0 : _a.language) && initParams.language) {
|
|
450
|
+
if (edit.when.language !== initParams.language)
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
const createIfMissing = edit.createIfMissing !== false;
|
|
454
|
+
let matchedFiles = [];
|
|
455
|
+
if (edit.matchType === 'exact') {
|
|
456
|
+
matchedFiles = [edit.match];
|
|
457
|
+
}
|
|
458
|
+
else if (edit.matchType === 'glob') {
|
|
459
|
+
const regex = toRegexFromGlob(edit.match);
|
|
460
|
+
matchedFiles = listRootFiles().filter((name) => regex.test(name));
|
|
461
|
+
}
|
|
462
|
+
else if (edit.matchType === 'regex') {
|
|
463
|
+
const regex = new RegExp(edit.match);
|
|
464
|
+
matchedFiles = listRootFiles().filter((name) => regex.test(name));
|
|
465
|
+
}
|
|
466
|
+
// if no matched files and allowed to create, provide a reasonable default for common patterns
|
|
467
|
+
if (!matchedFiles.length && createIfMissing) {
|
|
468
|
+
if (edit.matchType === 'exact') {
|
|
469
|
+
matchedFiles = [edit.match];
|
|
470
|
+
}
|
|
471
|
+
else if (edit.matchType === 'glob' &&
|
|
472
|
+
/next\.config\.\{.*\}/.test(edit.match)) {
|
|
473
|
+
matchedFiles = ['next.config.ts'];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (!matchedFiles.length)
|
|
477
|
+
continue;
|
|
478
|
+
// resolve content
|
|
479
|
+
let payload = null;
|
|
480
|
+
if (edit.fromFile) {
|
|
481
|
+
const absFrom = path.isAbsolute(edit.fromFile)
|
|
482
|
+
? edit.fromFile
|
|
483
|
+
: path.join(__dirname, edit.fromFile);
|
|
484
|
+
payload = fs.readFileSync(absFrom, 'utf-8');
|
|
485
|
+
}
|
|
486
|
+
else if (typeof edit.content === 'string') {
|
|
487
|
+
payload = edit.content;
|
|
488
|
+
}
|
|
489
|
+
for (const rel of matchedFiles) {
|
|
490
|
+
const abs = path.join(targetPath, rel);
|
|
491
|
+
if (payload == null)
|
|
492
|
+
continue;
|
|
493
|
+
fs.ensureDirSync(path.dirname(abs));
|
|
494
|
+
fs.writeFileSync(abs, payload, 'utf-8');
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
logger.endSubStep('File edits applied');
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
catch (_b) {
|
|
501
|
+
outro(`File edits application failed`);
|
|
502
|
+
exit(1);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
export const installESACli = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
506
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
507
|
+
const res = yield execCommand(['npm', 'install', '-D', 'esa-cli'], {
|
|
508
|
+
cwd: targetPath,
|
|
509
|
+
useSpinner: true,
|
|
510
|
+
silent: true,
|
|
511
|
+
startText: 'Installing ESA CLI',
|
|
512
|
+
doneText: 'ESA CLI installed in the project'
|
|
513
|
+
});
|
|
514
|
+
if (!res.success) {
|
|
515
|
+
outro(`ESA CLI installation failed`);
|
|
516
|
+
exit(1);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
export const updateConfigFile = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
520
|
+
var _a, _b;
|
|
521
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
522
|
+
const configFormat = 'jsonc';
|
|
523
|
+
logger.startSubStep(`Updating config file`);
|
|
524
|
+
try {
|
|
525
|
+
if (initParams.framework) {
|
|
526
|
+
const frameworkConfig = getFrameworkConfig(initParams.framework);
|
|
527
|
+
const assetsDirectory = (_a = frameworkConfig.assets) === null || _a === void 0 ? void 0 : _a.directory;
|
|
528
|
+
const notFoundStrategy = (_b = frameworkConfig.assets) === null || _b === void 0 ? void 0 : _b.notFoundStrategy;
|
|
529
|
+
yield generateConfigFile(initParams.name, {
|
|
530
|
+
assets: assetsDirectory ? { directory: assetsDirectory } : undefined
|
|
531
|
+
}, targetPath, configFormat, notFoundStrategy);
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
// TODO revise template config file later
|
|
535
|
+
// console.log(
|
|
536
|
+
// 'test:',
|
|
537
|
+
// initParams.name,
|
|
538
|
+
// undefined,
|
|
539
|
+
// targetPath,
|
|
540
|
+
// configFormat
|
|
541
|
+
// );
|
|
542
|
+
// logger.startSubStep(`Updating config file`);
|
|
543
|
+
// await generateConfigFile(initParams.name, undefined, targetPath, 'toml');
|
|
544
|
+
}
|
|
545
|
+
logger.endSubStep('Config file updated');
|
|
546
|
+
}
|
|
547
|
+
catch (_c) {
|
|
548
|
+
outro(`Config file update failed`);
|
|
549
|
+
exit(1);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
export const initGit = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
553
|
+
const frameworkConfig = getFrameworkConfig(initParams.framework || '');
|
|
554
|
+
if ((frameworkConfig === null || frameworkConfig === void 0 ? void 0 : frameworkConfig.useGit) === false) {
|
|
555
|
+
log.step('Git skipped');
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
const gitInstalled = yield isGitInstalled();
|
|
559
|
+
if (!gitInstalled) {
|
|
560
|
+
log.step('You have not installed Git, Git skipped');
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
if (!initParams.git) {
|
|
564
|
+
const initGit = (yield promptParameter({
|
|
565
|
+
type: 'confirm',
|
|
566
|
+
question: t('init_git').d('Do you want to init git in your project?'),
|
|
567
|
+
label: 'Init git',
|
|
568
|
+
defaultValue: false
|
|
569
|
+
}));
|
|
570
|
+
initParams.git = initGit;
|
|
571
|
+
}
|
|
572
|
+
if (initParams.git) {
|
|
573
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
574
|
+
const res = yield execCommand(['git', 'init'], {
|
|
575
|
+
cwd: targetPath,
|
|
576
|
+
silent: true,
|
|
577
|
+
startText: 'Initializing git',
|
|
578
|
+
doneText: 'Git initialized'
|
|
579
|
+
});
|
|
580
|
+
if (!res.success) {
|
|
581
|
+
outro(`Git initialization failed`);
|
|
582
|
+
exit(1);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return true;
|
|
586
|
+
});
|
|
587
|
+
export function getGitVersion() {
|
|
588
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
589
|
+
try {
|
|
590
|
+
const stdout = yield execCommand(['git', '--version'], {
|
|
591
|
+
useSpinner: false,
|
|
592
|
+
silent: true,
|
|
593
|
+
captureOutput: true
|
|
594
|
+
});
|
|
595
|
+
const gitVersion = stdout.stdout.replace(/^git\s+version\s+/, '');
|
|
596
|
+
return gitVersion;
|
|
597
|
+
}
|
|
598
|
+
catch (_a) {
|
|
599
|
+
log.error('Failed to get Git version');
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
export function isGitInstalled() {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
+
return (yield getGitVersion()) !== null;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
export const buildProject = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
610
|
+
if (initParams.template) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
614
|
+
const res = yield execCommand(['npm', 'run', 'build'], {
|
|
615
|
+
useSpinner: true,
|
|
616
|
+
silent: true,
|
|
617
|
+
startText: 'Building project',
|
|
618
|
+
doneText: 'Project built',
|
|
619
|
+
cwd: targetPath
|
|
620
|
+
});
|
|
621
|
+
if (!res.success) {
|
|
622
|
+
outro(`Build project failed`);
|
|
623
|
+
exit(1);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
export function prepareTemplateItems() {
|
|
627
|
+
var _a;
|
|
628
|
+
const templateInstanceList = getTemplateInstances(templateHubPath);
|
|
629
|
+
const templateConfig = getTemplatesConfig();
|
|
630
|
+
const cliConfig = getCliConfig();
|
|
631
|
+
const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
|
|
632
|
+
return transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
|
|
633
|
+
}
|
|
634
|
+
export const deployProject = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
635
|
+
if (!initParams.deploy) {
|
|
636
|
+
log.step('Deploy project skipped');
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
const targetPath = path.join(process.cwd(), initParams.name);
|
|
640
|
+
const res = yield commitAndDeployVersion(initParams.name, undefined, undefined, 'Init project', targetPath, 'all');
|
|
641
|
+
if (!res) {
|
|
642
|
+
outro(`Deploy project failed`);
|
|
643
|
+
exit(1);
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
export function initializeProject(selectedTemplatePath, name) {
|
|
647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
+
const selectTemplate = new Template(selectedTemplatePath, name);
|
|
649
|
+
const projectConfig = getProjectConfig(selectedTemplatePath);
|
|
650
|
+
if (!projectConfig) {
|
|
651
|
+
logger.notInProject();
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
const targetPath = path.join(process.cwd(), name);
|
|
655
|
+
if (fs.existsSync(targetPath)) {
|
|
656
|
+
logger.block();
|
|
657
|
+
logger.tree([
|
|
658
|
+
`${chalk.bgRed(' ERROR ')} ${chalk.bold.red(t('init_abort').d('Initialization aborted'))}`,
|
|
659
|
+
`${chalk.gray(t('reason').d('Reason:'))} ${chalk.red(t('dir_already_exists').d('Target directory already exists'))}`,
|
|
660
|
+
`${chalk.gray(t('path').d('Path:'))} ${chalk.cyan(targetPath)}`,
|
|
661
|
+
chalk.gray(t('try').d('Try one of the following:')),
|
|
662
|
+
`- ${chalk.white(t('try_diff_name').d('Choose a different project name'))}`,
|
|
663
|
+
`- ${chalk.white(t('try_remove').d('Remove the directory:'))} ${chalk.yellow(`rm -rf "${name}”`)}`,
|
|
664
|
+
`- ${chalk.white(t('try_another_dir').d('Run the command in another directory'))}`
|
|
665
|
+
]);
|
|
666
|
+
logger.block();
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
yield fs.copy(selectedTemplatePath, targetPath);
|
|
670
|
+
projectConfig.name = name;
|
|
671
|
+
yield updateProjectConfigFile(projectConfig, targetPath);
|
|
672
|
+
yield preInstallDependencies(targetPath);
|
|
673
|
+
return { template: selectTemplate, targetPath };
|
|
674
|
+
});
|
|
675
|
+
}
|