esa-cli 0.0.2-beta.1 โ 0.0.2-beta.12
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 +34 -25
- package/dist/commands/common/constant.js +0 -19
- package/dist/commands/deploy/helper.js +10 -26
- package/dist/commands/deploy/index.js +49 -60
- package/dist/commands/deployments/delete.js +1 -16
- package/dist/commands/deployments/index.js +1 -1
- package/dist/commands/deployments/list.js +8 -15
- package/dist/commands/dev/ew2/cacheService.js +33 -0
- package/dist/commands/dev/ew2/devEntry.js +2 -1
- package/dist/commands/dev/ew2/devPack.js +13 -26
- package/dist/commands/dev/ew2/kvService.js +27 -0
- package/dist/commands/dev/ew2/mock/cache.js +99 -15
- package/dist/commands/dev/ew2/mock/kv.js +142 -21
- package/dist/commands/dev/ew2/server.js +152 -19
- package/dist/commands/dev/index.js +4 -4
- package/dist/commands/dev/mockWorker/devPack.js +16 -14
- package/dist/commands/domain/add.js +1 -1
- package/dist/commands/domain/delete.js +4 -4
- package/dist/commands/domain/index.js +1 -1
- package/dist/commands/domain/list.js +3 -3
- package/dist/commands/init/helper.js +137 -0
- package/dist/commands/init/index.js +183 -187
- package/dist/commands/login/index.js +49 -3
- package/dist/commands/logout.js +1 -1
- package/dist/commands/route/add.js +50 -52
- package/dist/commands/route/delete.js +29 -23
- package/dist/commands/route/helper.js +124 -0
- package/dist/commands/route/index.js +1 -1
- package/dist/commands/route/list.js +53 -14
- package/dist/commands/routine/index.js +1 -1
- package/dist/commands/routine/list.js +4 -5
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/utils.js +5 -5
- package/dist/components/mutiLevelSelect.js +44 -55
- package/dist/docs/Commands_en.md +27 -13
- package/dist/docs/Commands_zh_CN.md +14 -0
- package/dist/docs/Dev_en.md +0 -0
- package/dist/docs/Dev_zh_CN.md +0 -0
- package/dist/i18n/locales.json +144 -12
- package/dist/index.js +6 -9
- package/dist/libs/api.js +32 -9
- package/dist/libs/apiService.js +88 -78
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +1 -1
- package/dist/libs/templates/index.js +2 -1
- package/dist/utils/checkIsRoutineCreated.js +7 -12
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/download.js +182 -0
- package/dist/utils/fileUtils/base.js +1 -1
- package/dist/utils/installDeno.js +7 -7
- package/package.json +5 -5
|
@@ -36,10 +36,10 @@ export function handleListDomains(argv) {
|
|
|
36
36
|
yield validRoutine(projectConfig.name);
|
|
37
37
|
const server = yield ApiService.getInstance();
|
|
38
38
|
const req = { Name: projectConfig.name };
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
39
|
+
const res = yield server.listRoutineRelatedRecords(req);
|
|
40
|
+
if (!res)
|
|
41
41
|
return;
|
|
42
|
-
const relatedRecords = (_b = (_a =
|
|
42
|
+
const relatedRecords = (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
|
|
43
43
|
if (relatedRecords.length === 0) {
|
|
44
44
|
logger.log(`๐
${t('domain_list_empty').d('No related domains found')}`);
|
|
45
45
|
return;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import Template from '../../libs/templates/index.js';
|
|
13
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
14
|
+
import logger from '../../libs/logger.js';
|
|
15
|
+
import { execSync } from 'child_process';
|
|
16
|
+
import t from '../../i18n/index.js';
|
|
17
|
+
import chalk from 'chalk';
|
|
18
|
+
import inquirer from 'inquirer';
|
|
19
|
+
import { getDirName } from '../../utils/fileUtils/base.js';
|
|
20
|
+
export const getTemplateInstances = (templateHubPath) => {
|
|
21
|
+
return fs
|
|
22
|
+
.readdirSync(templateHubPath)
|
|
23
|
+
.filter((item) => {
|
|
24
|
+
const itemPath = path.join(templateHubPath, item);
|
|
25
|
+
return (fs.statSync(itemPath).isDirectory() &&
|
|
26
|
+
!['.git', 'node_modules', 'lib'].includes(item));
|
|
27
|
+
})
|
|
28
|
+
.map((item) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const projectPath = path.join(templateHubPath, item);
|
|
31
|
+
const projectConfig = getProjectConfig(projectPath);
|
|
32
|
+
const templateName = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '';
|
|
33
|
+
return new Template(projectPath, templateName);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const transferTemplatesToSelectItem = (configs, templateInstanceList, lang) => {
|
|
37
|
+
if (!configs)
|
|
38
|
+
return [];
|
|
39
|
+
return configs.map((config) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const title = config.Title_EN;
|
|
42
|
+
const value = (_b = (_a = templateInstanceList.find((template) => {
|
|
43
|
+
return title === template.title;
|
|
44
|
+
})) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '';
|
|
45
|
+
const children = transferTemplatesToSelectItem(config.children, templateInstanceList, lang);
|
|
46
|
+
return {
|
|
47
|
+
label: lang === 'en' ? config.Title_EN : config.Title_ZH,
|
|
48
|
+
value: value,
|
|
49
|
+
children
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
export const preInstallDependencies = (targetPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const packageJsonPath = path.join(targetPath, 'package.json');
|
|
55
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
56
|
+
logger.log(t('init_install_dependence').d('โ๏ธ Installing dependencies...'));
|
|
57
|
+
execSync('npm install', { stdio: 'inherit', cwd: targetPath });
|
|
58
|
+
logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
|
|
59
|
+
// Read and parse package.json to check for build script
|
|
60
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
61
|
+
if (packageJson.scripts && packageJson.scripts.build) {
|
|
62
|
+
logger.log(t('init_build_project').d('โ๏ธ Building project...'));
|
|
63
|
+
execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
|
|
64
|
+
logger.success(t('init_build_project_success').d('Project built successfully.'));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
logger.log(t('no_build_script').d('No build script found in package.json, skipping build step.'));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
export function checkAndUpdatePackage(packageName) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
// ่ทๅๅฝๅๅฎ่ฃ
็็ๆฌ
|
|
75
|
+
const __dirname = getDirName(import.meta.url);
|
|
76
|
+
const packageJsonPath = path.join(__dirname, '../../../');
|
|
77
|
+
let versionInfo;
|
|
78
|
+
try {
|
|
79
|
+
versionInfo = execSync(`npm list ${packageName}`, {
|
|
80
|
+
cwd: packageJsonPath
|
|
81
|
+
}).toString();
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
execSync(`rm -rf node_modules/${packageName}`, {
|
|
85
|
+
cwd: packageJsonPath
|
|
86
|
+
});
|
|
87
|
+
execSync(`npm install ${packageName}@latest`, {
|
|
88
|
+
cwd: packageJsonPath,
|
|
89
|
+
stdio: 'inherit'
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const match = versionInfo.match(new RegExp(`(${packageName})@([0-9.]+)`));
|
|
94
|
+
const currentVersion = match ? match[2] : '';
|
|
95
|
+
// ่ทๅๆๆฐ็ๆฌ
|
|
96
|
+
const latestVersion = execSync(`npm view ${packageName} version`, {
|
|
97
|
+
cwd: packageJsonPath
|
|
98
|
+
})
|
|
99
|
+
.toString()
|
|
100
|
+
.trim();
|
|
101
|
+
if (currentVersion !== latestVersion) {
|
|
102
|
+
logger.log(t('display_current_esa_template_version').d(`Current esa-template version:`) +
|
|
103
|
+
chalk.green(currentVersion) +
|
|
104
|
+
' ' +
|
|
105
|
+
t('display_latest_esa_template_version').d(`Latest esa-template version:`) +
|
|
106
|
+
chalk.green(latestVersion));
|
|
107
|
+
const { isUpdate } = yield inquirer.prompt({
|
|
108
|
+
type: 'confirm',
|
|
109
|
+
name: 'isUpdate',
|
|
110
|
+
message: t('is_update_to_latest_version').d('Do you want to update templates to latest version?')
|
|
111
|
+
});
|
|
112
|
+
if (isUpdate) {
|
|
113
|
+
execSync(`rm -rf node_modules/${packageName}`, {
|
|
114
|
+
cwd: packageJsonPath
|
|
115
|
+
});
|
|
116
|
+
execSync(`rm -rf package-lock.json`, {
|
|
117
|
+
cwd: packageJsonPath
|
|
118
|
+
});
|
|
119
|
+
execSync(`npm install ${packageName}@latest`, {
|
|
120
|
+
cwd: packageJsonPath,
|
|
121
|
+
stdio: 'inherit'
|
|
122
|
+
});
|
|
123
|
+
logger.log(t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
logger.log(t('esa_template_is_latest_version', { packageName }).d(`${packageName} is latest.`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.log(error);
|
|
132
|
+
if (error instanceof Error) {
|
|
133
|
+
logger.error('ๆฃๆตๅๆดๆฐๅ
ๆถๅ็้่ฏฏ๏ผ่ทณ่ฟๆดๆฐๆจก็');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -9,235 +9,231 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import fs from 'fs-extra';
|
|
11
11
|
import path from 'path';
|
|
12
|
+
import inquirer from 'inquirer';
|
|
13
|
+
import { exit } from 'process';
|
|
12
14
|
import Template from '../../libs/templates/index.js';
|
|
13
15
|
import { installGit } from '../../libs/git/index.js';
|
|
14
|
-
import
|
|
16
|
+
import multiLevelSelect from '../../components/mutiLevelSelect.js';
|
|
15
17
|
import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
16
18
|
import t from '../../i18n/index.js';
|
|
17
19
|
import logger from '../../libs/logger.js';
|
|
18
|
-
import SelectItems from '../../components/selectInput.js';
|
|
19
20
|
import { quickDeploy } from '../deploy/index.js';
|
|
20
|
-
import chalk from 'chalk';
|
|
21
21
|
import { ApiService } from '../../libs/apiService.js';
|
|
22
|
-
import { exit } from 'process';
|
|
23
22
|
import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
|
|
24
|
-
import { execSync } from 'child_process';
|
|
25
|
-
import MultiLevelSelect from '../../components/mutiLevelSelect.js';
|
|
26
|
-
import { getDirName } from '../../utils/fileUtils/base.js';
|
|
27
|
-
import { yesNoPromptAndExecute } from '../deploy/helper.js';
|
|
28
23
|
import { checkIsLoginSuccess } from '../utils.js';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.readdirSync(templateHubPath)
|
|
32
|
-
.filter((item) => {
|
|
33
|
-
const itemPath = path.join(templateHubPath, item);
|
|
34
|
-
return (fs.statSync(itemPath).isDirectory() &&
|
|
35
|
-
!['.git', 'node_modules', 'lib'].includes(item));
|
|
36
|
-
})
|
|
37
|
-
.map((item) => {
|
|
38
|
-
var _a;
|
|
39
|
-
const projectPath = path.join(templateHubPath, item);
|
|
40
|
-
const projectConfig = getProjectConfig(projectPath);
|
|
41
|
-
const templateName = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '';
|
|
42
|
-
return new Template(projectPath, templateName);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const secondSetOfItems = [
|
|
46
|
-
{ label: 'Yes', value: 'yesInstall' },
|
|
47
|
-
{ label: 'No', value: 'noInstall' }
|
|
48
|
-
];
|
|
24
|
+
import chalk from 'chalk';
|
|
25
|
+
import { checkAndUpdatePackage, getTemplateInstances, preInstallDependencies, transferTemplatesToSelectItem } from './helper.js';
|
|
49
26
|
const init = {
|
|
50
|
-
command: 'init',
|
|
27
|
+
command: 'init [name]',
|
|
51
28
|
describe: `๐ฅ ${t('init_describe').d('Initialize a routine with a template')}`,
|
|
52
29
|
builder: (yargs) => {
|
|
53
|
-
return yargs
|
|
30
|
+
return yargs
|
|
31
|
+
.positional('name', {
|
|
32
|
+
describe: t('init_project_name').d('Project name'),
|
|
33
|
+
type: 'string'
|
|
34
|
+
})
|
|
35
|
+
.option('template', {
|
|
36
|
+
alias: 't',
|
|
37
|
+
describe: t('init_template_name').d('Template name to use'),
|
|
38
|
+
type: 'string'
|
|
39
|
+
})
|
|
40
|
+
.option('config', {
|
|
54
41
|
alias: 'c',
|
|
55
42
|
describe: t('init_config_file').d('Generate a config file for your project'),
|
|
56
43
|
type: 'boolean'
|
|
44
|
+
})
|
|
45
|
+
.option('skip', {
|
|
46
|
+
alias: 's',
|
|
47
|
+
describe: t('init_skip').d('Skip the project git and deployment initialization'),
|
|
48
|
+
type: 'boolean',
|
|
49
|
+
default: false
|
|
57
50
|
});
|
|
58
51
|
},
|
|
59
52
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
53
|
yield handleInit(argv);
|
|
54
|
+
exit(0);
|
|
61
55
|
})
|
|
62
56
|
};
|
|
63
57
|
export default init;
|
|
64
|
-
export
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
export function findTemplatePathByName(templateName) {
|
|
59
|
+
const templateInstanceList = getTemplateInstances(templateHubPath);
|
|
60
|
+
const templateConfig = getTemplatesConfig();
|
|
61
|
+
// find template recursively
|
|
62
|
+
function findTemplateRecursive(configs) {
|
|
63
|
+
for (const config of configs) {
|
|
64
|
+
const title = config.Title_EN;
|
|
65
|
+
if (title === templateName) {
|
|
66
|
+
const template = templateInstanceList.find((template) => {
|
|
67
|
+
return config.Title_EN === template.title;
|
|
68
|
+
});
|
|
69
|
+
return (template === null || template === void 0 ? void 0 : template.path) || null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
76
73
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const value = (_b = (_a = templateInstanceList.find((template) => {
|
|
85
|
-
return name === template.title;
|
|
86
|
-
})) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '';
|
|
87
|
-
const children = transferTemplatesToSelectItem(config.children, templateInstanceList);
|
|
88
|
-
return {
|
|
89
|
-
label: lang === 'en' ? config.Title_EN : config.Title_ZH,
|
|
90
|
-
value: value,
|
|
91
|
-
key: name,
|
|
92
|
-
children
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
function checkAndUpdatePackage(packageName) {
|
|
74
|
+
return findTemplateRecursive(templateConfig);
|
|
75
|
+
}
|
|
76
|
+
export function validateProjectName(name) {
|
|
77
|
+
const regex = /^[a-z0-9-]{2,}$/;
|
|
78
|
+
return regex.test(name);
|
|
79
|
+
}
|
|
80
|
+
export function promptProjectName() {
|
|
97
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const latestVersion = execSync(`npm view ${packageName} version`)
|
|
109
|
-
.toString()
|
|
110
|
-
.trim();
|
|
111
|
-
if (currentVersion !== latestVersion) {
|
|
112
|
-
logger.log(t('display_current_esa_template_version').d(`Current esa-template version:`) +
|
|
113
|
-
chalk.green(currentVersion) +
|
|
114
|
-
' ' +
|
|
115
|
-
t('display_latest_esa_template_version').d(`Latest esa-template version:`) +
|
|
116
|
-
chalk.green(latestVersion));
|
|
117
|
-
yield yesNoPromptAndExecute(t('is_update_to_latest_version').d('Do you want to update templates to latest version?'), () => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
logger.log(t('updating_esa_template_to_latest_version', { packageName }).d(`Updating ${packageName} to the latest version...`));
|
|
119
|
-
execSync(`rm -rf node_modules/${packageName} &&rm -rf package-lock.json &&npm install ${packageName}@latest`, {
|
|
120
|
-
cwd: packageJsonPath
|
|
121
|
-
});
|
|
122
|
-
logger.log(t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`));
|
|
82
|
+
const { name } = yield inquirer.prompt([
|
|
83
|
+
{
|
|
84
|
+
type: 'input',
|
|
85
|
+
name: 'name',
|
|
86
|
+
message: `${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
|
|
87
|
+
validate: (input) => {
|
|
88
|
+
const regex = /^[a-z0-9-]{2,}$/;
|
|
89
|
+
if (!regex.test(input)) {
|
|
90
|
+
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.');
|
|
91
|
+
}
|
|
123
92
|
return true;
|
|
124
|
-
}
|
|
93
|
+
}
|
|
125
94
|
}
|
|
126
|
-
|
|
127
|
-
|
|
95
|
+
]);
|
|
96
|
+
return name;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export function prepareTemplateItems() {
|
|
100
|
+
var _a;
|
|
101
|
+
const templateInstanceList = getTemplateInstances(templateHubPath);
|
|
102
|
+
const templateConfig = getTemplatesConfig();
|
|
103
|
+
const cliConfig = getCliConfig();
|
|
104
|
+
const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
|
|
105
|
+
return transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
|
|
106
|
+
}
|
|
107
|
+
export function selectTemplate(items) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const selectedTemplatePath = yield multiLevelSelect(items, 'Select a template:');
|
|
110
|
+
if (!selectedTemplatePath) {
|
|
111
|
+
logger.log(t('init_cancel').d('User canceled the operation.'));
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return selectedTemplatePath;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export function initializeProject(selectedTemplatePath, name) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const selectTemplate = new Template(selectedTemplatePath, name);
|
|
120
|
+
const projectConfig = getProjectConfig(selectedTemplatePath);
|
|
121
|
+
if (!projectConfig) {
|
|
122
|
+
logger.notInProject();
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const targetPath = path.join(process.cwd(), name);
|
|
126
|
+
if (fs.existsSync(targetPath)) {
|
|
127
|
+
logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
yield fs.copy(selectedTemplatePath, targetPath);
|
|
131
|
+
projectConfig.name = name;
|
|
132
|
+
yield updateProjectConfigFile(projectConfig, targetPath);
|
|
133
|
+
yield preInstallDependencies(targetPath);
|
|
134
|
+
return { template: selectTemplate, targetPath };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export function handleGitInitialization(targetPath) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const { initGit } = yield inquirer.prompt([
|
|
140
|
+
{
|
|
141
|
+
type: 'list',
|
|
142
|
+
name: 'initGit',
|
|
143
|
+
message: t('init_git').d('Do you want to init git in your project?'),
|
|
144
|
+
choices: ['Yes', 'No']
|
|
128
145
|
}
|
|
146
|
+
]);
|
|
147
|
+
if (initGit === 'Yes') {
|
|
148
|
+
installGit(targetPath);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
logger.log(t('init_skip_git').d('Git installation was skipped.'));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
export function handleDeployment(targetPath, projectConfig) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
var _a, _b, _c;
|
|
158
|
+
const isLoginSuccess = yield checkIsLoginSuccess();
|
|
159
|
+
if (!isLoginSuccess) {
|
|
160
|
+
logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
|
|
161
|
+
return;
|
|
129
162
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
const { deploy } = yield inquirer.prompt([
|
|
164
|
+
{
|
|
165
|
+
type: 'list',
|
|
166
|
+
name: 'deploy',
|
|
167
|
+
message: t('auto_deploy').d('Do you want to deploy your project?'),
|
|
168
|
+
choices: ['Yes', 'No']
|
|
133
169
|
}
|
|
170
|
+
]);
|
|
171
|
+
if (deploy === 'Yes') {
|
|
172
|
+
yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
|
|
173
|
+
yield quickDeploy(targetPath, projectConfig);
|
|
174
|
+
const service = yield ApiService.getInstance();
|
|
175
|
+
const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
|
|
176
|
+
const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
|
|
177
|
+
const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
|
|
178
|
+
logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
|
|
179
|
+
logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
|
|
134
180
|
}
|
|
135
181
|
});
|
|
136
182
|
}
|
|
137
183
|
export function handleInit(argv) {
|
|
138
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
|
|
140
|
-
const { config } = argv;
|
|
141
|
-
// ๆดๆฐtemplate npmๅ
|
|
185
|
+
// Update the template package (currently commented out)
|
|
142
186
|
yield checkAndUpdatePackage('esa-template');
|
|
143
|
-
|
|
187
|
+
// If config option is provided, generate config file and exit
|
|
188
|
+
const config = getCliConfig();
|
|
189
|
+
if (config === undefined) {
|
|
144
190
|
yield generateConfigFile(String(config));
|
|
145
|
-
return;
|
|
146
191
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!
|
|
150
|
-
|
|
151
|
-
return;
|
|
192
|
+
// Handle project name parameter
|
|
193
|
+
let name = argv.name;
|
|
194
|
+
if (!name) {
|
|
195
|
+
name = yield promptProjectName();
|
|
152
196
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const firstSetOfItems = transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
|
|
158
|
-
let selectTemplate;
|
|
159
|
-
let targetPath;
|
|
160
|
-
let projectConfig;
|
|
161
|
-
const preInstallDependencies = () => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const packageJsonPath = path.join(targetPath, 'package.json');
|
|
163
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
164
|
-
logger.log('Install dependencies');
|
|
165
|
-
logger.log(t('init_install_dependence').d('โ๏ธ Installing dependencies...'));
|
|
166
|
-
execSync('npm install', { stdio: 'inherit', cwd: targetPath });
|
|
167
|
-
logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
|
|
168
|
-
logger.log(t('init_build_project').d('โ๏ธ Building project...'));
|
|
169
|
-
execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
|
|
170
|
-
logger.success(t('init_build_project_success').d('Project built successfully.'));
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
const handleFirstSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
if (item.key === 'exit') {
|
|
175
|
-
process.exit(0);
|
|
176
|
-
}
|
|
177
|
-
const configPath = item.value;
|
|
178
|
-
selectTemplate = new Template(configPath, name);
|
|
179
|
-
projectConfig = getProjectConfig(configPath);
|
|
180
|
-
if (!projectConfig)
|
|
181
|
-
return logger.notInProject();
|
|
182
|
-
const newPath = process.cwd() + '/' + name;
|
|
183
|
-
targetPath = newPath;
|
|
184
|
-
if (fs.existsSync(newPath)) {
|
|
185
|
-
logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
|
|
186
|
-
exit(0);
|
|
187
|
-
}
|
|
188
|
-
yield fs.copy(configPath, newPath);
|
|
189
|
-
projectConfig.name = name;
|
|
190
|
-
updateProjectConfigFile(projectConfig, newPath);
|
|
191
|
-
preInstallDependencies();
|
|
192
|
-
logger.log(t('init_git').d('Do you want to init git in your project?'));
|
|
193
|
-
SelectItems({
|
|
194
|
-
items: secondSetOfItems,
|
|
195
|
-
handleSelect: handleSecondSelection
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
const handleSecondSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
if (item.value === 'yesInstall') {
|
|
200
|
-
installGit(targetPath);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
logger.log(t('init_skip_git').d('Git installation was skipped.'));
|
|
197
|
+
else {
|
|
198
|
+
if (!validateProjectName(name)) {
|
|
199
|
+
logger.error(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.'));
|
|
200
|
+
return;
|
|
204
201
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
}
|
|
203
|
+
// Handle template name parameter
|
|
204
|
+
let selectedTemplatePath = null;
|
|
205
|
+
if (argv.template) {
|
|
206
|
+
const templateName = argv.template;
|
|
207
|
+
selectedTemplatePath = findTemplatePathByName(templateName);
|
|
208
|
+
if (!selectedTemplatePath) {
|
|
209
|
+
logger.error(t('init_template_not_found').d(`Template "${templateName}" not found. Please check the template name and try again.`));
|
|
210
|
+
return;
|
|
209
211
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
var _a, _b, _c;
|
|
218
|
-
// ้ๆฉ่ชๅจ็ๆ็ๆฌๅนถๅๅธ
|
|
219
|
-
if (item.value === 'yesInstall') {
|
|
220
|
-
yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
|
|
221
|
-
projectConfig && (yield quickDeploy(targetPath, projectConfig));
|
|
222
|
-
const service = yield ApiService.getInstance();
|
|
223
|
-
const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
|
|
224
|
-
const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
|
|
225
|
-
const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
|
|
226
|
-
logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
|
|
227
|
-
logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
const templateItems = prepareTemplateItems();
|
|
215
|
+
// Select a template
|
|
216
|
+
selectedTemplatePath = yield selectTemplate(templateItems);
|
|
217
|
+
if (!selectedTemplatePath) {
|
|
218
|
+
return;
|
|
228
219
|
}
|
|
229
|
-
selectTemplate.printSummary();
|
|
230
|
-
exit(0);
|
|
231
|
-
});
|
|
232
|
-
try {
|
|
233
|
-
MultiLevelSelect({
|
|
234
|
-
items: firstSetOfItems,
|
|
235
|
-
handleSelect: handleFirstSelection
|
|
236
|
-
});
|
|
237
220
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
221
|
+
// Initialize project files and configuration
|
|
222
|
+
const project = yield initializeProject(selectedTemplatePath, name);
|
|
223
|
+
if (!project) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const { template, targetPath } = project;
|
|
227
|
+
if (!argv.skip) {
|
|
228
|
+
// Handle Git initialization
|
|
229
|
+
yield handleGitInitialization(targetPath);
|
|
230
|
+
}
|
|
231
|
+
if (!argv.skip) {
|
|
232
|
+
// Handle deployment
|
|
233
|
+
const projectConfig = getProjectConfig(targetPath);
|
|
234
|
+
yield handleDeployment(targetPath, projectConfig);
|
|
241
235
|
}
|
|
236
|
+
template.printSummary();
|
|
237
|
+
return;
|
|
242
238
|
});
|
|
243
239
|
}
|
|
@@ -16,15 +16,35 @@ import logger from '../../libs/logger.js';
|
|
|
16
16
|
const login = {
|
|
17
17
|
command: 'login',
|
|
18
18
|
describe: `๐ ${t('login_describe').d('Login to the server')}`,
|
|
19
|
-
builder: {
|
|
19
|
+
builder: (yargs) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return yargs
|
|
22
|
+
.option('access-key-id', {
|
|
23
|
+
alias: 'ak',
|
|
24
|
+
describe: (_a = t('login_option_access_key_id')) === null || _a === void 0 ? void 0 : _a.d('AccessKey ID'),
|
|
25
|
+
type: 'string'
|
|
26
|
+
})
|
|
27
|
+
.option('access-key-secret', {
|
|
28
|
+
alias: 'sk',
|
|
29
|
+
describe: (_b = t('login_option_access_key_secret')) === null || _b === void 0 ? void 0 : _b.d('AccessKey Secret'),
|
|
30
|
+
type: 'string'
|
|
31
|
+
});
|
|
32
|
+
},
|
|
20
33
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
handleLogin();
|
|
34
|
+
handleLogin(argv);
|
|
22
35
|
})
|
|
23
36
|
};
|
|
24
37
|
export default login;
|
|
25
|
-
export function handleLogin() {
|
|
38
|
+
export function handleLogin(argv) {
|
|
26
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
40
|
generateDefaultConfig();
|
|
41
|
+
// Prioritize command line parameters
|
|
42
|
+
const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
|
|
43
|
+
const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
|
|
44
|
+
if (accessKeyId && accessKeySecret) {
|
|
45
|
+
yield handleLoginWithAKSK(accessKeyId, accessKeySecret);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
28
48
|
const cliConfig = getCliConfig();
|
|
29
49
|
if (!cliConfig)
|
|
30
50
|
return;
|
|
@@ -64,6 +84,32 @@ export function handleLogin() {
|
|
|
64
84
|
}
|
|
65
85
|
});
|
|
66
86
|
}
|
|
87
|
+
function handleLoginWithAKSK(accessKeyId, accessKeySecret) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
let apiConfig = getApiConfig();
|
|
90
|
+
apiConfig.auth = {
|
|
91
|
+
accessKeyId,
|
|
92
|
+
accessKeySecret
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
yield updateCliConfigFile({
|
|
96
|
+
auth: apiConfig.auth
|
|
97
|
+
});
|
|
98
|
+
const service = yield ApiService.getInstance();
|
|
99
|
+
service.updateConfig(apiConfig);
|
|
100
|
+
const loginStatus = yield service.checkLogin();
|
|
101
|
+
if (loginStatus.success) {
|
|
102
|
+
logger.success(t('login_success').d('Login success!'));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
logger.error(loginStatus.message || 'Login failed');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
logger.error(t('login_failed').d('An error occurred while trying to log in.'));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
67
113
|
export function getUserInputAuthInfo() {
|
|
68
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
115
|
const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
|
package/dist/commands/logout.js
CHANGED
|
@@ -12,7 +12,7 @@ import logger from '../libs/logger.js';
|
|
|
12
12
|
import t from '../i18n/index.js';
|
|
13
13
|
const logout = {
|
|
14
14
|
command: 'logout',
|
|
15
|
-
describe:
|
|
15
|
+
describe: `๐ช ${t('logout_describe').d('Logout')}`,
|
|
16
16
|
builder: (yargs) => {
|
|
17
17
|
return yargs;
|
|
18
18
|
},
|