esa-cli 0.0.2-beta.16 → 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 +91 -5
- package/dist/commands/init/index.js +2 -2
- 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/routeBuilder.js +68 -0
- package/dist/docs/Commands_en.md +34 -1
- package/dist/docs/Commands_zh_CN.md +38 -2
- 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)
|
|
@@ -212,12 +212,14 @@ export function getInitParamsFromArgv(argv) {
|
|
|
212
212
|
params.template = a.template;
|
|
213
213
|
params.framework = undefined;
|
|
214
214
|
params.language = undefined;
|
|
215
|
+
params.category = 'template';
|
|
215
216
|
}
|
|
216
217
|
else {
|
|
217
218
|
const fw = a.framework;
|
|
218
219
|
const lang = a.language;
|
|
219
220
|
if (fw) {
|
|
220
221
|
params.framework = fw;
|
|
222
|
+
params.category = 'framework';
|
|
221
223
|
}
|
|
222
224
|
if (lang) {
|
|
223
225
|
params.language = lang;
|
|
@@ -550,12 +552,14 @@ export const updateConfigFile = (initParams) => __awaiter(void 0, void 0, void 0
|
|
|
550
552
|
}
|
|
551
553
|
});
|
|
552
554
|
export const initGit = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
555
|
+
var _a;
|
|
553
556
|
const frameworkConfig = getFrameworkConfig(initParams.framework || '');
|
|
554
557
|
if ((frameworkConfig === null || frameworkConfig === void 0 ? void 0 : frameworkConfig.useGit) === false) {
|
|
555
558
|
log.step('Git skipped');
|
|
556
559
|
return true;
|
|
557
560
|
}
|
|
558
561
|
const gitInstalled = yield isGitInstalled();
|
|
562
|
+
console.log('gitInstalled', gitInstalled);
|
|
559
563
|
if (!gitInstalled) {
|
|
560
564
|
log.step('You have not installed Git, Git skipped');
|
|
561
565
|
return true;
|
|
@@ -581,13 +585,15 @@ export const initGit = (initParams) => __awaiter(void 0, void 0, void 0, functio
|
|
|
581
585
|
outro(`Git initialization failed`);
|
|
582
586
|
exit(1);
|
|
583
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);
|
|
584
590
|
}
|
|
585
591
|
return true;
|
|
586
592
|
});
|
|
587
593
|
export function getGitVersion() {
|
|
588
594
|
return __awaiter(this, void 0, void 0, function* () {
|
|
589
595
|
try {
|
|
590
|
-
|
|
596
|
+
let stdout = yield execCommand(['git', '--version'], {
|
|
591
597
|
useSpinner: false,
|
|
592
598
|
silent: true,
|
|
593
599
|
captureOutput: true
|
|
@@ -603,7 +609,87 @@ export function getGitVersion() {
|
|
|
603
609
|
}
|
|
604
610
|
export function isGitInstalled() {
|
|
605
611
|
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
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
|
+
}
|
|
607
693
|
});
|
|
608
694
|
}
|
|
609
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, checkAndUpdatePackage, 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')}`,
|
|
@@ -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 = {
|
|
@@ -18,37 +18,55 @@ const list = {
|
|
|
18
18
|
command: 'list',
|
|
19
19
|
describe: `📋 ${t('list_describe').d('List all your routines')}`,
|
|
20
20
|
builder: (yargs) => {
|
|
21
|
-
return yargs
|
|
21
|
+
return yargs
|
|
22
|
+
.option('keyword', {
|
|
23
|
+
alias: 'k',
|
|
24
|
+
describe: t('deploy_option_keyword').d('Keyword to search for routines'),
|
|
25
|
+
type: 'string'
|
|
26
|
+
})
|
|
27
|
+
.usage(`${t('common_usage').d('Usage')}: \$0 list [--keyword <keyword>]`);
|
|
22
28
|
},
|
|
23
29
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
30
|
handleList(argv);
|
|
25
31
|
})
|
|
26
32
|
};
|
|
27
33
|
export default list;
|
|
34
|
+
export function getAllRoutines(options) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a;
|
|
37
|
+
const server = yield ApiService.getInstance();
|
|
38
|
+
const allRoutines = [];
|
|
39
|
+
let pageNumber = 1;
|
|
40
|
+
const pageSize = (options === null || options === void 0 ? void 0 : options.PageSize) || 50;
|
|
41
|
+
while (true) {
|
|
42
|
+
const res = yield server.listUserRoutines({
|
|
43
|
+
RegionId: options === null || options === void 0 ? void 0 : options.RegionId,
|
|
44
|
+
PageNumber: pageNumber,
|
|
45
|
+
PageSize: pageSize,
|
|
46
|
+
SearchKeyWord: options === null || options === void 0 ? void 0 : options.SearchKeyWord
|
|
47
|
+
});
|
|
48
|
+
if (!((_a = res === null || res === void 0 ? void 0 : res.body) === null || _a === void 0 ? void 0 : _a.Routines)) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
allRoutines.push(...res.body.Routines);
|
|
52
|
+
const totalCount = res.body.TotalCount;
|
|
53
|
+
const currentCount = allRoutines.length;
|
|
54
|
+
if (currentCount >= totalCount) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
pageNumber++;
|
|
58
|
+
}
|
|
59
|
+
return allRoutines;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
28
62
|
export function handleList(argv) {
|
|
29
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
const { site } = argv;
|
|
32
64
|
const isSuccess = yield checkIsLoginSuccess();
|
|
33
65
|
if (!isSuccess)
|
|
34
66
|
return;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
SiteSearchType: 'fuzzy',
|
|
39
|
-
Status: 'active',
|
|
40
|
-
PageNumber: 1,
|
|
41
|
-
PageSize: 50
|
|
42
|
-
};
|
|
43
|
-
const res = yield server.listSites(req);
|
|
44
|
-
const siteList = (_a = res === null || res === void 0 ? void 0 : res.data.Sites) !== null && _a !== void 0 ? _a : [];
|
|
45
|
-
const siteNameList = siteList === null || siteList === void 0 ? void 0 : siteList.map((item) => item.SiteName);
|
|
46
|
-
logger.log(chalk.bold.bgGray(`📃 ${t('list_site_name_title').d('List all of site names')}:`));
|
|
47
|
-
logger.tree(siteNameList);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const res = yield server.listUserRoutines();
|
|
51
|
-
const routineList = (_b = res === null || res === void 0 ? void 0 : res.body) === null || _b === void 0 ? void 0 : _b.Routines;
|
|
67
|
+
const routineList = yield getAllRoutines({
|
|
68
|
+
SearchKeyWord: argv.keyword
|
|
69
|
+
});
|
|
52
70
|
if (routineList) {
|
|
53
71
|
logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of routine')}:`));
|
|
54
72
|
displayRoutineList(routineList);
|