esa-cli 0.0.2-beta.15 → 0.0.2-beta.18
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 +4 -4
- package/dist/commands/common/utils.js +108 -11
- package/dist/commands/deploy/helper.js +11 -11
- package/dist/commands/deploy/index.js +9 -10
- package/dist/commands/init/helper.js +106 -8
- package/dist/commands/init/index.js +3 -3
- package/dist/commands/init/template.jsonc +1 -1
- package/dist/commands/route/add.js +19 -51
- package/dist/commands/routine/list.js +38 -20
- package/dist/components/mutiLevelSelect.js +2 -1
- package/dist/components/routeBuilder.js +68 -0
- package/dist/docs/Commands_en.md +34 -1
- package/dist/docs/Commands_zh_CN.md +40 -6
- package/dist/i18n/locales.json +72 -0
- package/dist/index.js +11 -1
- package/dist/libs/apiService.js +4 -2
- package/dist/libs/logger.js +41 -2
- package/dist/utils/checkIsRoutineCreated.js +1 -8
- package/dist/utils/checkVersion.js +118 -0
- package/dist/utils/compress.js +27 -9
- package/dist/utils/fileUtils/index.js +36 -13
- package/package.json +10 -11
|
@@ -8,12 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { exit } from 'process';
|
|
11
|
-
import t from '../../i18n/index.js';
|
|
12
|
-
import { validateAndInitializeProject, generateCodeVersion } from '../common/utils.js';
|
|
13
11
|
import { intro, outro } from '@clack/prompts';
|
|
14
|
-
import promptParameter from '../../utils/prompt.js';
|
|
15
|
-
import logger from '../../libs/logger.js';
|
|
16
12
|
import chalk from 'chalk';
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
14
|
+
import logger from '../../libs/logger.js';
|
|
15
|
+
import promptParameter from '../../utils/prompt.js';
|
|
16
|
+
import { validateAndInitializeProject, generateCodeVersion } from '../common/utils.js';
|
|
17
17
|
const commit = {
|
|
18
18
|
command: 'commit [entry]',
|
|
19
19
|
describe: `📥 ${t('commit_describe').d('Commit your code, save as a new version')}`,
|
|
@@ -11,10 +11,10 @@ import chalk from 'chalk';
|
|
|
11
11
|
import t from '../../i18n/index.js';
|
|
12
12
|
import { ApiService } from '../../libs/apiService.js';
|
|
13
13
|
import logger from '../../libs/logger.js';
|
|
14
|
+
import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
|
|
14
15
|
import compress from '../../utils/compress.js';
|
|
15
16
|
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
16
17
|
import sleep from '../../utils/sleep.js';
|
|
17
|
-
import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
|
|
18
18
|
import { checkIsLoginSuccess } from '../utils.js';
|
|
19
19
|
function normalizeNotFoundStrategy(value) {
|
|
20
20
|
if (!value)
|
|
@@ -83,12 +83,15 @@ export function commitRoutineWithAssets(requestParams, zipBuffer) {
|
|
|
83
83
|
export function validateAndInitializeProject(name, projectPath) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
85
|
const projectConfig = getProjectConfig(projectPath);
|
|
86
|
-
|
|
86
|
+
// allow missing config, derive name from cwd when not provided
|
|
87
|
+
const projectName = name ||
|
|
88
|
+
(projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) ||
|
|
89
|
+
process.cwd().split(/[\\/]/).pop();
|
|
90
|
+
if (!projectName) {
|
|
87
91
|
logger.notInProject();
|
|
88
92
|
return null;
|
|
89
93
|
}
|
|
90
|
-
|
|
91
|
-
logger.startSubStep('Checking login status abc');
|
|
94
|
+
logger.startSubStep('Checking login status');
|
|
92
95
|
const isSuccess = yield checkIsLoginSuccess();
|
|
93
96
|
if (!isSuccess) {
|
|
94
97
|
logger.endSubStep('You are not logged in');
|
|
@@ -96,7 +99,7 @@ export function validateAndInitializeProject(name, projectPath) {
|
|
|
96
99
|
}
|
|
97
100
|
logger.endSubStep('Logged in');
|
|
98
101
|
yield ensureRoutineExists(projectName);
|
|
99
|
-
return { projectConfig, projectName };
|
|
102
|
+
return { projectConfig: projectConfig || null, projectName };
|
|
100
103
|
});
|
|
101
104
|
}
|
|
102
105
|
/**
|
|
@@ -116,9 +119,104 @@ export function getRoutineDetails(projectName) {
|
|
|
116
119
|
export function generateCodeVersion(projectName_1, description_1, entry_1, assets_1) {
|
|
117
120
|
return __awaiter(this, arguments, void 0, function* (projectName, description, entry, assets, minify = false, projectPath) {
|
|
118
121
|
var _a;
|
|
119
|
-
const zip = yield compress(entry, assets, minify, projectPath);
|
|
122
|
+
const { zip, sourceList, dynamicSources } = yield compress(entry, assets, minify, projectPath);
|
|
123
|
+
try {
|
|
124
|
+
// Pretty print upload directory tree
|
|
125
|
+
const buildTree = (paths, decorateTopLevel) => {
|
|
126
|
+
const root = { children: new Map(), isFile: false };
|
|
127
|
+
const sorted = [...paths].sort((a, b) => a.localeCompare(b));
|
|
128
|
+
for (const p of sorted) {
|
|
129
|
+
const parts = p.split('/').filter(Boolean);
|
|
130
|
+
let node = root;
|
|
131
|
+
for (let i = 0; i < parts.length; i++) {
|
|
132
|
+
const part = parts[i];
|
|
133
|
+
if (!node.children.has(part)) {
|
|
134
|
+
node.children.set(part, { children: new Map(), isFile: false });
|
|
135
|
+
}
|
|
136
|
+
const child = node.children.get(part);
|
|
137
|
+
if (i === parts.length - 1)
|
|
138
|
+
child.isFile = true;
|
|
139
|
+
node = child;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const lines = [];
|
|
143
|
+
const render = (node, prefix, depth) => {
|
|
144
|
+
const entries = [...node.children.entries()];
|
|
145
|
+
entries.forEach(([_name, _child], idx) => {
|
|
146
|
+
const isLast = idx === entries.length - 1;
|
|
147
|
+
const connector = isLast ? '└ ' : '├ ';
|
|
148
|
+
const nextPrefix = prefix + (isLast ? ' ' : '│ ');
|
|
149
|
+
const displayName = depth === 0 ? decorateTopLevel(_name) : _name;
|
|
150
|
+
lines.push(prefix + connector + displayName);
|
|
151
|
+
render(_child, nextPrefix, depth + 1);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
render(root, '', 0);
|
|
155
|
+
return lines.length ? lines : ['-'];
|
|
156
|
+
};
|
|
157
|
+
const header = chalk.hex('#22c55e')('UPLOAD') + ' Files to be uploaded (source paths)';
|
|
158
|
+
logger.block();
|
|
159
|
+
logger.log(header);
|
|
160
|
+
const dynamicSet = new Set(dynamicSources);
|
|
161
|
+
const LIMIT = 300;
|
|
162
|
+
const staticPaths = sourceList
|
|
163
|
+
.filter((p) => !dynamicSet.has(p))
|
|
164
|
+
.sort((a, b) => a.localeCompare(b));
|
|
165
|
+
const dynamicPaths = sourceList
|
|
166
|
+
.filter((p) => dynamicSet.has(p))
|
|
167
|
+
.sort((a, b) => a.localeCompare(b));
|
|
168
|
+
let omitted = 0;
|
|
169
|
+
let shownStatic = staticPaths;
|
|
170
|
+
if (staticPaths.length > LIMIT) {
|
|
171
|
+
shownStatic = staticPaths.slice(0, LIMIT);
|
|
172
|
+
omitted = staticPaths.length - LIMIT;
|
|
173
|
+
}
|
|
174
|
+
// Compute top-level markers based on whether a top-level bucket contains dynamic/static files
|
|
175
|
+
const topLevelStats = new Map();
|
|
176
|
+
const addStat = (p, isDynamic) => {
|
|
177
|
+
const top = p.split('/')[0] || p;
|
|
178
|
+
const stat = topLevelStats.get(top) || {
|
|
179
|
+
hasDynamic: false,
|
|
180
|
+
hasStatic: false
|
|
181
|
+
};
|
|
182
|
+
if (isDynamic)
|
|
183
|
+
stat.hasDynamic = true;
|
|
184
|
+
else
|
|
185
|
+
stat.hasStatic = true;
|
|
186
|
+
topLevelStats.set(top, stat);
|
|
187
|
+
};
|
|
188
|
+
dynamicPaths.forEach((p) => addStat(p, true));
|
|
189
|
+
shownStatic.forEach((p) => addStat(p, false));
|
|
190
|
+
const dynamicMarker = chalk.bold.yellowBright(' (dynamic)');
|
|
191
|
+
const staticMarker = chalk.bold.greenBright(' (static)');
|
|
192
|
+
const decorateTopLevel = (name) => {
|
|
193
|
+
const stat = topLevelStats.get(name);
|
|
194
|
+
if (!stat)
|
|
195
|
+
return name;
|
|
196
|
+
if (stat.hasDynamic && stat.hasStatic) {
|
|
197
|
+
return `${name}${dynamicMarker}${staticMarker}`;
|
|
198
|
+
}
|
|
199
|
+
if (stat.hasDynamic)
|
|
200
|
+
return `${name}${dynamicMarker}`;
|
|
201
|
+
if (stat.hasStatic)
|
|
202
|
+
return `${name}${staticMarker}`;
|
|
203
|
+
return name;
|
|
204
|
+
};
|
|
205
|
+
const combined = [...dynamicPaths, ...shownStatic];
|
|
206
|
+
const treeLines = buildTree(combined, decorateTopLevel);
|
|
207
|
+
for (const line of treeLines) {
|
|
208
|
+
logger.log(line);
|
|
209
|
+
}
|
|
210
|
+
if (omitted > 0) {
|
|
211
|
+
const note = chalk.gray(`仅展示前 ${LIMIT} 个静态文件,已省略 ${omitted} 个`);
|
|
212
|
+
logger.log(note);
|
|
213
|
+
}
|
|
214
|
+
logger.block();
|
|
215
|
+
}
|
|
216
|
+
catch (_b) { }
|
|
120
217
|
const projectConfig = getProjectConfig(projectPath);
|
|
121
218
|
const notFoundStrategy = normalizeNotFoundStrategy((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.notFoundStrategy);
|
|
219
|
+
logger.startSubStep('Generating code version');
|
|
122
220
|
const requestParams = {
|
|
123
221
|
Name: projectName,
|
|
124
222
|
CodeDescription: description,
|
|
@@ -165,19 +263,18 @@ export function commitAndDeployVersion(projectName_1, scriptEntry_1, assets_1) {
|
|
|
165
263
|
return __awaiter(this, arguments, void 0, function* (projectName, scriptEntry, assets, description = '', projectPath, env = 'production', minify = false, version) {
|
|
166
264
|
var _a, _b, _c;
|
|
167
265
|
const projectInfo = yield validateAndInitializeProject(projectName, projectPath);
|
|
168
|
-
if (!projectInfo
|
|
266
|
+
if (!projectInfo) {
|
|
169
267
|
return false;
|
|
170
268
|
}
|
|
171
269
|
const { projectConfig } = projectInfo;
|
|
172
270
|
// 2) Use existing version or generate a new one
|
|
173
271
|
if (version) {
|
|
174
272
|
logger.startSubStep(`Using existing version ${version}`);
|
|
175
|
-
const deployed = yield deployToEnvironments(
|
|
273
|
+
const deployed = yield deployToEnvironments(projectInfo.projectName, version, env);
|
|
176
274
|
logger.endSubStep(deployed ? 'Deploy finished' : 'Deploy failed');
|
|
177
275
|
return deployed;
|
|
178
276
|
}
|
|
179
|
-
|
|
180
|
-
const res = yield generateCodeVersion(projectConfig.name, description, scriptEntry || projectConfig.entry, assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || projectConfig.minify, projectPath);
|
|
277
|
+
const res = yield generateCodeVersion(projectInfo.projectName, description, scriptEntry || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry), assets || ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.minify), projectPath);
|
|
181
278
|
const isCommitSuccess = res === null || res === void 0 ? void 0 : res.isSuccess;
|
|
182
279
|
if (!isCommitSuccess) {
|
|
183
280
|
logger.endSubStep('Generate version failed');
|
|
@@ -190,7 +287,7 @@ export function commitAndDeployVersion(projectName_1, scriptEntry_1, assets_1) {
|
|
|
190
287
|
}
|
|
191
288
|
logger.endSubStep(`Version generated: ${codeVersion}`);
|
|
192
289
|
// 3) Deploy to specified environment(s)
|
|
193
|
-
const deployed = yield deployToEnvironments(
|
|
290
|
+
const deployed = yield deployToEnvironments(projectInfo.projectName, codeVersion, env);
|
|
194
291
|
return deployed;
|
|
195
292
|
});
|
|
196
293
|
}
|
|
@@ -10,21 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
import moment from 'moment';
|
|
12
12
|
import SelectItems from '../../components/selectInput.js';
|
|
13
|
-
import { yesNoPrompt } from '../../components/yesNoPrompt.js';
|
|
14
13
|
import t from '../../i18n/index.js';
|
|
15
14
|
import { PublishType } from '../../libs/interface.js';
|
|
16
15
|
import logger from '../../libs/logger.js';
|
|
16
|
+
import promptParameter from '../../utils/prompt.js';
|
|
17
17
|
export function yesNoPromptAndExecute(message, execute) {
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const confirmed = (yield promptParameter({
|
|
20
|
+
type: 'confirm',
|
|
21
|
+
question: message,
|
|
22
|
+
label: 'Confirm',
|
|
23
|
+
defaultValue: true
|
|
24
|
+
}));
|
|
25
|
+
if (!confirmed)
|
|
26
|
+
return false;
|
|
27
|
+
return yield execute();
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
export function promptSelectVersion(versionList) {
|
|
@@ -8,11 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { exit } from 'process';
|
|
11
|
+
import { intro, outro } from '@clack/prompts';
|
|
11
12
|
import t from '../../i18n/index.js';
|
|
12
13
|
import { getRoot } from '../../utils/fileUtils/base.js';
|
|
13
|
-
import { commitAndDeployVersion, displayDeploySuccess } from '../common/utils.js';
|
|
14
|
-
import { intro, outro } from '@clack/prompts';
|
|
15
14
|
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
15
|
+
import { commitAndDeployVersion, displayDeploySuccess } from '../common/utils.js';
|
|
16
16
|
const deploy = {
|
|
17
17
|
command: 'deploy [entry]',
|
|
18
18
|
builder: (yargs) => {
|
|
@@ -41,7 +41,7 @@ const deploy = {
|
|
|
41
41
|
.option('assets', {
|
|
42
42
|
alias: 'a',
|
|
43
43
|
describe: t('deploy_option_assets').d('Deploy assets'),
|
|
44
|
-
type: '
|
|
44
|
+
type: 'string'
|
|
45
45
|
})
|
|
46
46
|
.option('description', {
|
|
47
47
|
alias: 'd',
|
|
@@ -52,11 +52,6 @@ const deploy = {
|
|
|
52
52
|
alias: 'm',
|
|
53
53
|
describe: t('deploy_option_minify').d('Minify the code'),
|
|
54
54
|
type: 'boolean'
|
|
55
|
-
})
|
|
56
|
-
.option('minify', {
|
|
57
|
-
alias: 'm',
|
|
58
|
-
describe: t('deploy_option_minify').d('Minify the code'),
|
|
59
|
-
type: 'boolean'
|
|
60
55
|
});
|
|
61
56
|
},
|
|
62
57
|
describe: `🚀 ${t('deploy_describe').d('Deploy your project')}`,
|
|
@@ -67,14 +62,18 @@ const deploy = {
|
|
|
67
62
|
};
|
|
68
63
|
export function handleDeploy(argv) {
|
|
69
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a;
|
|
70
66
|
const entry = argv.entry;
|
|
71
|
-
const assets = argv.assets;
|
|
67
|
+
const assets = (_a = argv.assets) !== null && _a !== void 0 ? _a : undefined;
|
|
72
68
|
intro(`Deploy an application with ESA`);
|
|
73
69
|
const success = yield commitAndDeployVersion(argv.name || undefined, entry, assets, argv.description || '', getRoot(), argv.environment || 'all', argv.minify, argv.version);
|
|
74
70
|
outro(success ? 'Deploy finished' : 'Deploy failed');
|
|
75
71
|
if (success) {
|
|
76
72
|
const projectConfig = getProjectConfig(getRoot());
|
|
77
|
-
yield displayDeploySuccess(argv.name ||
|
|
73
|
+
yield displayDeploySuccess(argv.name ||
|
|
74
|
+
(projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) ||
|
|
75
|
+
getRoot().split(/[\\/]/).pop() ||
|
|
76
|
+
'', true, true);
|
|
78
77
|
}
|
|
79
78
|
});
|
|
80
79
|
}
|
|
@@ -9,19 +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 { exit } from 'process';
|
|
12
13
|
import { confirm as clackConfirm, isCancel, log, outro } from '@clack/prompts';
|
|
13
14
|
import chalk from 'chalk';
|
|
14
15
|
import fs from 'fs-extra';
|
|
16
|
+
import Haikunator from 'haikunator';
|
|
15
17
|
import t from '../../i18n/index.js';
|
|
16
18
|
import logger from '../../libs/logger.js';
|
|
17
19
|
import Template from '../../libs/templates/index.js';
|
|
20
|
+
import { execCommand } from '../../utils/command.js';
|
|
18
21
|
import { getDirName } from '../../utils/fileUtils/base.js';
|
|
19
22
|
import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
20
|
-
import { execCommand } from '../../utils/command.js';
|
|
21
23
|
import promptParameter from '../../utils/prompt.js';
|
|
22
|
-
import Haikunator from 'haikunator';
|
|
23
24
|
import { commitAndDeployVersion } from '../common/utils.js';
|
|
24
|
-
import { exit } from 'process';
|
|
25
25
|
export const getTemplateInstances = (templateHubPath) => {
|
|
26
26
|
return fs
|
|
27
27
|
.readdirSync(templateHubPath)
|
|
@@ -51,6 +51,7 @@ export const transferTemplatesToSelectItem = (configs, templateInstanceList, lan
|
|
|
51
51
|
return {
|
|
52
52
|
label: lang === 'en' ? config.Title_EN : config.Title_ZH,
|
|
53
53
|
value: value,
|
|
54
|
+
hint: lang === 'en' ? config.Desc_EN : config.Desc_ZH,
|
|
54
55
|
children
|
|
55
56
|
};
|
|
56
57
|
});
|
|
@@ -211,12 +212,14 @@ export function getInitParamsFromArgv(argv) {
|
|
|
211
212
|
params.template = a.template;
|
|
212
213
|
params.framework = undefined;
|
|
213
214
|
params.language = undefined;
|
|
215
|
+
params.category = 'template';
|
|
214
216
|
}
|
|
215
217
|
else {
|
|
216
218
|
const fw = a.framework;
|
|
217
219
|
const lang = a.language;
|
|
218
220
|
if (fw) {
|
|
219
221
|
params.framework = fw;
|
|
222
|
+
params.category = 'framework';
|
|
220
223
|
}
|
|
221
224
|
if (lang) {
|
|
222
225
|
params.language = lang;
|
|
@@ -234,11 +237,19 @@ export const configProjectName = (initParams) => __awaiter(void 0, void 0, void
|
|
|
234
237
|
log.step(`Project name configured ${initParams.name}`);
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
240
|
+
const HaikunatorCtor = Haikunator;
|
|
241
|
+
const haikunator = new HaikunatorCtor();
|
|
242
|
+
const defaultName = haikunator.haikunate();
|
|
237
243
|
const name = (yield promptParameter({
|
|
238
244
|
type: 'text',
|
|
239
245
|
question: `${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
|
|
240
246
|
label: 'Project name',
|
|
247
|
+
defaultValue: defaultName,
|
|
241
248
|
validate: (input) => {
|
|
249
|
+
if (input === '' || input === undefined) {
|
|
250
|
+
initParams.name = defaultName;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
242
253
|
const regex = /^[a-z0-9-]{2,}$/;
|
|
243
254
|
if (!regex.test(input)) {
|
|
244
255
|
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.');
|
|
@@ -373,8 +384,8 @@ export const createProject = (initParams) => __awaiter(void 0, void 0, void 0, f
|
|
|
373
384
|
const full = `${command} ${initParams.name} ${templateFlag} ${extraParams}`.trim();
|
|
374
385
|
const res = yield execCommand(['sh', '-lc', full], {
|
|
375
386
|
interactive: true,
|
|
376
|
-
startText: `Starting to execute framework command
|
|
377
|
-
doneText: `Framework command executed
|
|
387
|
+
startText: `Starting to execute framework command ${chalk.gray(full)}`,
|
|
388
|
+
doneText: `Framework command executed ${chalk.gray(full)}`
|
|
378
389
|
});
|
|
379
390
|
if (!res.success) {
|
|
380
391
|
outro(`Framework command execution failed`);
|
|
@@ -541,12 +552,14 @@ export const updateConfigFile = (initParams) => __awaiter(void 0, void 0, void 0
|
|
|
541
552
|
}
|
|
542
553
|
});
|
|
543
554
|
export const initGit = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
555
|
+
var _a;
|
|
544
556
|
const frameworkConfig = getFrameworkConfig(initParams.framework || '');
|
|
545
557
|
if ((frameworkConfig === null || frameworkConfig === void 0 ? void 0 : frameworkConfig.useGit) === false) {
|
|
546
558
|
log.step('Git skipped');
|
|
547
559
|
return true;
|
|
548
560
|
}
|
|
549
561
|
const gitInstalled = yield isGitInstalled();
|
|
562
|
+
console.log('gitInstalled', gitInstalled);
|
|
550
563
|
if (!gitInstalled) {
|
|
551
564
|
log.step('You have not installed Git, Git skipped');
|
|
552
565
|
return true;
|
|
@@ -563,19 +576,24 @@ export const initGit = (initParams) => __awaiter(void 0, void 0, void 0, functio
|
|
|
563
576
|
if (initParams.git) {
|
|
564
577
|
const targetPath = path.join(process.cwd(), initParams.name);
|
|
565
578
|
const res = yield execCommand(['git', 'init'], {
|
|
566
|
-
cwd: targetPath
|
|
579
|
+
cwd: targetPath,
|
|
580
|
+
silent: true,
|
|
581
|
+
startText: 'Initializing git',
|
|
582
|
+
doneText: 'Git initialized'
|
|
567
583
|
});
|
|
568
584
|
if (!res.success) {
|
|
569
585
|
outro(`Git initialization failed`);
|
|
570
586
|
exit(1);
|
|
571
587
|
}
|
|
588
|
+
// Ensure .gitignore exists and has sensible defaults
|
|
589
|
+
yield ensureGitignore(targetPath, (_a = frameworkConfig === null || frameworkConfig === void 0 ? void 0 : frameworkConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
|
|
572
590
|
}
|
|
573
591
|
return true;
|
|
574
592
|
});
|
|
575
593
|
export function getGitVersion() {
|
|
576
594
|
return __awaiter(this, void 0, void 0, function* () {
|
|
577
595
|
try {
|
|
578
|
-
|
|
596
|
+
let stdout = yield execCommand(['git', '--version'], {
|
|
579
597
|
useSpinner: false,
|
|
580
598
|
silent: true,
|
|
581
599
|
captureOutput: true
|
|
@@ -591,7 +609,87 @@ export function getGitVersion() {
|
|
|
591
609
|
}
|
|
592
610
|
export function isGitInstalled() {
|
|
593
611
|
return __awaiter(this, void 0, void 0, function* () {
|
|
594
|
-
return (yield getGitVersion()) !==
|
|
612
|
+
return (yield getGitVersion()) !== '';
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Create or update .gitignore in project root with sensible defaults.
|
|
617
|
+
* - Preserves existing entries and comments
|
|
618
|
+
* - Avoids duplicates
|
|
619
|
+
* - Adds framework assets directory if provided
|
|
620
|
+
*/
|
|
621
|
+
function ensureGitignore(projectRoot, assetsDirectory) {
|
|
622
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
623
|
+
try {
|
|
624
|
+
const gitignorePath = path.join(projectRoot, '.gitignore');
|
|
625
|
+
const defaults = [
|
|
626
|
+
'# Logs',
|
|
627
|
+
'logs',
|
|
628
|
+
'*.log',
|
|
629
|
+
'npm-debug.log*',
|
|
630
|
+
'yarn-debug.log*',
|
|
631
|
+
'yarn-error.log*',
|
|
632
|
+
'pnpm-debug.log*',
|
|
633
|
+
'',
|
|
634
|
+
'# Node modules',
|
|
635
|
+
'node_modules/',
|
|
636
|
+
'',
|
|
637
|
+
'# Build output',
|
|
638
|
+
'dist/',
|
|
639
|
+
'build/',
|
|
640
|
+
'out/',
|
|
641
|
+
'.next/',
|
|
642
|
+
'.nuxt/',
|
|
643
|
+
'coverage/',
|
|
644
|
+
'.vite/',
|
|
645
|
+
'',
|
|
646
|
+
'# Env files',
|
|
647
|
+
'.env',
|
|
648
|
+
'.env.local',
|
|
649
|
+
'.env.development.local',
|
|
650
|
+
'.env.test.local',
|
|
651
|
+
'.env.production.local',
|
|
652
|
+
'',
|
|
653
|
+
'# IDE/editor',
|
|
654
|
+
'.DS_Store',
|
|
655
|
+
'.idea/',
|
|
656
|
+
'.vscode/',
|
|
657
|
+
'',
|
|
658
|
+
'# Misc caches',
|
|
659
|
+
'.eslintcache',
|
|
660
|
+
'.parcel-cache/',
|
|
661
|
+
'.turbo/',
|
|
662
|
+
'.cache/'
|
|
663
|
+
];
|
|
664
|
+
// Include assets directory if provided and not a common default
|
|
665
|
+
if (assetsDirectory &&
|
|
666
|
+
!['dist', 'build', 'out'].includes(assetsDirectory.replace(/\/$/, ''))) {
|
|
667
|
+
defaults.push('', '# Project assets output', `${assetsDirectory}/`);
|
|
668
|
+
}
|
|
669
|
+
let existingContent = '';
|
|
670
|
+
if (fs.existsSync(gitignorePath)) {
|
|
671
|
+
existingContent = fs.readFileSync(gitignorePath, 'utf-8');
|
|
672
|
+
}
|
|
673
|
+
const existingLines = new Set(existingContent.split(/\r?\n/).map((l) => l.trimEnd()));
|
|
674
|
+
const toAppend = [];
|
|
675
|
+
for (const line of defaults) {
|
|
676
|
+
if (!existingLines.has(line)) {
|
|
677
|
+
toAppend.push(line);
|
|
678
|
+
existingLines.add(line);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
// If nothing to add, keep as is
|
|
682
|
+
if (!toAppend.length)
|
|
683
|
+
return;
|
|
684
|
+
const newContent = existingContent
|
|
685
|
+
? `${existingContent.replace(/\n$/, '')}\n${toAppend.join('\n')}\n`
|
|
686
|
+
: `${toAppend.join('\n')}\n`;
|
|
687
|
+
fs.writeFileSync(gitignorePath, newContent, 'utf-8');
|
|
688
|
+
logger.log('Updated .gitignore');
|
|
689
|
+
}
|
|
690
|
+
catch (_a) {
|
|
691
|
+
// Do not fail init due to .gitignore issues
|
|
692
|
+
}
|
|
595
693
|
});
|
|
596
694
|
}
|
|
597
695
|
export const buildProject = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { exit } from 'process';
|
|
11
11
|
import { intro, outro } from '@clack/prompts';
|
|
12
|
+
import chalk from 'chalk';
|
|
12
13
|
import t from '../../i18n/index.js';
|
|
13
14
|
import { promptParameter } from '../../utils/prompt.js';
|
|
14
|
-
import { applyFileEdits, buildProject, configCategory, configLanguage, configProjectName, configTemplate, createProject, deployProject, getInitParamsFromArgv, initGit, installDependencies, installESACli, updateConfigFile } from './helper.js';
|
|
15
15
|
import { displayDeploySuccess } from '../common/utils.js';
|
|
16
|
-
import
|
|
16
|
+
import { applyFileEdits, buildProject, checkAndUpdatePackage, configCategory, configLanguage, configProjectName, configTemplate, createProject, deployProject, getInitParamsFromArgv, initGit, installDependencies, installESACli, updateConfigFile } from './helper.js';
|
|
17
17
|
const init = {
|
|
18
18
|
command: 'init [name]',
|
|
19
19
|
describe: `📥 ${t('init_describe').d('Initialize a routine with a template')}`,
|
|
@@ -63,7 +63,7 @@ const init = {
|
|
|
63
63
|
};
|
|
64
64
|
export default init;
|
|
65
65
|
const handleInit = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
|
|
66
|
+
yield checkAndUpdatePackage('esa-template');
|
|
67
67
|
const initParams = getInitParamsFromArgv(argv);
|
|
68
68
|
yield create(initParams);
|
|
69
69
|
yield config(initParams);
|
|
@@ -14,6 +14,7 @@ import logger from '../../libs/logger.js';
|
|
|
14
14
|
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
15
15
|
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
16
16
|
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
17
|
+
import { routeBuilder } from '../../components/routeBuilder.js';
|
|
17
18
|
import { transferRouteToRuleString } from './helper.js';
|
|
18
19
|
const addRoute = {
|
|
19
20
|
command: 'add',
|
|
@@ -99,35 +100,18 @@ export function handlerAddRoute(argv) {
|
|
|
99
100
|
let siteName = argv.site;
|
|
100
101
|
let siteId;
|
|
101
102
|
if (!siteName) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
type: 'list',
|
|
110
|
-
name: 'routeSite',
|
|
111
|
-
message: t('create_route_site').d('Select a site that is active in your account:'),
|
|
112
|
-
choices: siteList
|
|
113
|
-
}
|
|
114
|
-
]);
|
|
115
|
-
siteId = response.routeSite;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// 根据站点名称查找对应的站点ID
|
|
119
|
-
const matchedSite = siteList.find((site) => site.name === siteName);
|
|
120
|
-
if (matchedSite) {
|
|
121
|
-
siteId = matchedSite.value;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
|
|
125
|
-
return;
|
|
103
|
+
const response = yield inquirer.prompt([
|
|
104
|
+
{
|
|
105
|
+
type: 'list',
|
|
106
|
+
name: 'routeSite',
|
|
107
|
+
message: t('create_route_site').d('Select a site that is active in your account:'),
|
|
108
|
+
choices: siteList
|
|
126
109
|
}
|
|
127
|
-
|
|
110
|
+
]);
|
|
111
|
+
siteId = response.routeSite;
|
|
128
112
|
}
|
|
129
113
|
else {
|
|
130
|
-
//
|
|
114
|
+
// Find corresponding site ID by site name
|
|
131
115
|
const matchedSite = siteList.find((site) => site.name === siteName);
|
|
132
116
|
if (matchedSite) {
|
|
133
117
|
siteId = matchedSite.value;
|
|
@@ -137,40 +121,24 @@ export function handlerAddRoute(argv) {
|
|
|
137
121
|
return;
|
|
138
122
|
}
|
|
139
123
|
}
|
|
140
|
-
// 获取路由值,支持直接通过参数传入
|
|
141
124
|
let inputRoute = argv.route;
|
|
142
125
|
if (!inputRoute) {
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (!
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
type: 'input',
|
|
152
|
-
name: 'inputRoute',
|
|
153
|
-
message: t('create_route_route').d('Enter a Route (e.g., example.com/*):'),
|
|
154
|
-
validate: (input) => {
|
|
155
|
-
if (!input) {
|
|
156
|
-
return t('route_input_required').d('Route is required');
|
|
157
|
-
}
|
|
158
|
-
if (!input.includes('*') && !input.includes('/')) {
|
|
159
|
-
return t('route_format_invalid').d('Route format is invalid. Please include wildcard (*) or path (/)');
|
|
160
|
-
}
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
]);
|
|
165
|
-
inputRoute = response.inputRoute;
|
|
126
|
+
// Get selected site name for route building
|
|
127
|
+
const selectedSite = siteList.find((site) => site.value === siteId);
|
|
128
|
+
const displaySiteName = selectedSite ? selectedSite.name : siteName;
|
|
129
|
+
// Use route builder
|
|
130
|
+
const builtRoute = yield routeBuilder(displaySiteName);
|
|
131
|
+
if (!builtRoute) {
|
|
132
|
+
logger.info(t('route_build_cancelled').d('Route building cancelled'));
|
|
133
|
+
return;
|
|
166
134
|
}
|
|
135
|
+
inputRoute = builtRoute;
|
|
167
136
|
}
|
|
168
137
|
const rule = transferRouteToRuleString(inputRoute);
|
|
169
138
|
if (!rule) {
|
|
170
139
|
logger.error(t('route_format_invalid').d('Invalid route format'));
|
|
171
140
|
return;
|
|
172
141
|
}
|
|
173
|
-
// 获取站点名称用于显示
|
|
174
142
|
const selectedSite = siteList.find((site) => site.value === siteId);
|
|
175
143
|
const displaySiteName = selectedSite ? selectedSite.name : siteName;
|
|
176
144
|
const req = {
|