esa-cli 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -149
- package/dist/commands/commit/index.js +49 -104
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/constant.js +4 -4
- package/dist/commands/common/utils.js +419 -0
- package/dist/commands/config.js +2 -2
- package/dist/commands/deploy/helper.js +43 -49
- package/dist/commands/deploy/index.js +51 -174
- package/dist/commands/deployments/delete.js +32 -22
- package/dist/commands/deployments/index.js +4 -4
- package/dist/commands/deployments/list.js +21 -34
- package/dist/commands/dev/build.js +3 -3
- package/dist/commands/dev/doProcess.js +5 -5
- 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 +31 -20
- package/dist/commands/dev/ew2/kvService.js +50 -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 +163 -28
- package/dist/commands/dev/index.js +17 -18
- package/dist/commands/dev/mockWorker/devPack.js +19 -10
- package/dist/commands/dev/mockWorker/server.js +7 -6
- package/dist/commands/domain/add.js +4 -4
- package/dist/commands/domain/delete.js +3 -3
- package/dist/commands/domain/index.js +4 -4
- package/dist/commands/domain/list.js +7 -7
- package/dist/commands/init/helper.js +654 -21
- package/dist/commands/init/index.js +88 -152
- package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
- package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
- package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
- package/dist/commands/init/template.jsonc +84 -0
- package/dist/commands/init/types.js +1 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +74 -34
- package/dist/commands/logout.js +6 -6
- package/dist/commands/route/add.js +101 -43
- package/dist/commands/route/delete.js +6 -6
- package/dist/commands/route/helper.js +9 -10
- package/dist/commands/route/index.js +4 -4
- package/dist/commands/route/list.js +4 -4
- package/dist/commands/routine/delete.js +9 -8
- package/dist/commands/routine/index.js +6 -5
- package/dist/commands/routine/list.js +45 -39
- package/dist/commands/site/index.js +3 -3
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +61 -25
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/filterSelector.js +1 -1
- package/dist/components/mutiLevelSelect.js +19 -20
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/routeBuilder.js +68 -0
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +164 -117
- package/dist/docs/Commands_zh_CN.md +155 -107
- package/dist/docs/Config_en.md +70 -0
- package/dist/docs/Config_zh_CN.md +68 -0
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +414 -82
- package/dist/index.js +28 -13
- package/dist/libs/api.js +3 -6
- package/dist/libs/apiService.js +192 -69
- package/dist/libs/git/index.js +86 -9
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +162 -10
- package/dist/libs/service.js +2 -2
- package/dist/libs/templates/index.js +1 -1
- package/dist/utils/checkAssetsExist.js +80 -0
- package/dist/utils/checkDevPort.js +5 -19
- package/dist/utils/checkEntryFileExist.js +10 -0
- package/dist/utils/checkIsRoutineCreated.js +27 -21
- package/dist/utils/checkVersion.js +119 -1
- package/dist/utils/command.js +149 -0
- package/dist/utils/compress.js +142 -0
- package/dist/utils/download.js +8 -8
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/index.js +136 -45
- package/dist/utils/installDeno.js +4 -4
- package/dist/utils/installEw2.js +9 -9
- package/dist/utils/openInBrowser.js +1 -1
- package/dist/utils/prompt.js +97 -0
- package/package.json +23 -12
- package/zh_CN.md +29 -154
|
@@ -7,29 +7,52 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import fs from 'fs-extra';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
import inquirer from 'inquirer';
|
|
13
10
|
import { exit } from 'process';
|
|
14
|
-
import
|
|
15
|
-
import { installGit } from '../../libs/git/index.js';
|
|
16
|
-
import multiLevelSelect from '../../components/mutiLevelSelect.js';
|
|
17
|
-
import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
18
|
-
import t from '../../i18n/index.js';
|
|
19
|
-
import logger from '../../libs/logger.js';
|
|
20
|
-
import { quickDeploy } from '../deploy/index.js';
|
|
21
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
22
|
-
import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
|
|
23
|
-
import { checkIsLoginSuccess } from '../utils.js';
|
|
11
|
+
import { intro, outro } from '@clack/prompts';
|
|
24
12
|
import chalk from 'chalk';
|
|
25
|
-
import
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
14
|
+
import { promptParameter } from '../../utils/prompt.js';
|
|
15
|
+
import { displayDeploySuccess } from '../common/utils.js';
|
|
16
|
+
import { applyFileEdits, buildProject, checkAndUpdatePackage, configCategory, configLanguage, configProjectName, configTemplate, createProject, deployProject, getInitParamsFromArgv, initGit, installDependencies, installESACli, updateConfigFile } from './helper.js';
|
|
26
17
|
const init = {
|
|
27
|
-
command: 'init',
|
|
28
|
-
describe: `📥 ${t('init_describe').d('Initialize a
|
|
18
|
+
command: 'init [name]',
|
|
19
|
+
describe: `📥 ${t('init_describe').d('Initialize a project with a template')}`,
|
|
29
20
|
builder: (yargs) => {
|
|
30
|
-
return yargs
|
|
31
|
-
|
|
32
|
-
describe: t('
|
|
21
|
+
return yargs
|
|
22
|
+
.positional('name', {
|
|
23
|
+
describe: t('init_project_name').d('Project name'),
|
|
24
|
+
type: 'string'
|
|
25
|
+
})
|
|
26
|
+
.option('framework', {
|
|
27
|
+
alias: 'f',
|
|
28
|
+
describe: 'Choose a frontend framework (react/vue/nextjs...)',
|
|
29
|
+
type: 'string'
|
|
30
|
+
})
|
|
31
|
+
.option('language', {
|
|
32
|
+
alias: 'l',
|
|
33
|
+
describe: 'Choose programming language (typescript/javascript)',
|
|
34
|
+
type: 'string',
|
|
35
|
+
choices: ['typescript', 'javascript']
|
|
36
|
+
})
|
|
37
|
+
.option('template', {
|
|
38
|
+
alias: 't',
|
|
39
|
+
describe: t('init_template_name').d('Template name to use'),
|
|
40
|
+
type: 'string'
|
|
41
|
+
})
|
|
42
|
+
.option('yes', {
|
|
43
|
+
alias: 'y',
|
|
44
|
+
describe: t('init_yes').d('Answer "Yes" to all prompts.'),
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: false
|
|
47
|
+
})
|
|
48
|
+
.option('git', {
|
|
49
|
+
alias: 'g',
|
|
50
|
+
describe: 'Initialize git repository',
|
|
51
|
+
type: 'boolean'
|
|
52
|
+
})
|
|
53
|
+
.option('deploy', {
|
|
54
|
+
alias: 'd',
|
|
55
|
+
describe: 'Deploy after initialization',
|
|
33
56
|
type: 'boolean'
|
|
34
57
|
});
|
|
35
58
|
},
|
|
@@ -39,137 +62,50 @@ const init = {
|
|
|
39
62
|
})
|
|
40
63
|
};
|
|
41
64
|
export default init;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const projectConfig = getProjectConfig(selectedTemplatePath);
|
|
83
|
-
if (!projectConfig) {
|
|
84
|
-
logger.notInProject();
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const targetPath = path.join(process.cwd(), name);
|
|
88
|
-
if (fs.existsSync(targetPath)) {
|
|
89
|
-
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.'));
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
yield fs.copy(selectedTemplatePath, targetPath);
|
|
93
|
-
projectConfig.name = name;
|
|
94
|
-
yield updateProjectConfigFile(projectConfig, targetPath);
|
|
95
|
-
yield preInstallDependencies(targetPath);
|
|
96
|
-
return { template: selectTemplate, targetPath };
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
export function handleGitInitialization(targetPath) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const { initGit } = yield inquirer.prompt([
|
|
102
|
-
{
|
|
103
|
-
type: 'list',
|
|
104
|
-
name: 'initGit',
|
|
105
|
-
message: t('init_git').d('Do you want to init git in your project?'),
|
|
106
|
-
choices: ['Yes', 'No']
|
|
107
|
-
}
|
|
108
|
-
]);
|
|
109
|
-
if (initGit === 'Yes') {
|
|
110
|
-
installGit(targetPath);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
logger.log(t('init_skip_git').d('Git installation was skipped.'));
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export function handleDeployment(targetPath, projectConfig) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
var _a, _b, _c;
|
|
120
|
-
const isLoginSuccess = yield checkIsLoginSuccess();
|
|
121
|
-
if (!isLoginSuccess) {
|
|
122
|
-
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.')));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const { deploy } = yield inquirer.prompt([
|
|
126
|
-
{
|
|
127
|
-
type: 'list',
|
|
128
|
-
name: 'deploy',
|
|
129
|
-
message: t('auto_deploy').d('Do you want to deploy your project?'),
|
|
130
|
-
choices: ['Yes', 'No']
|
|
131
|
-
}
|
|
132
|
-
]);
|
|
133
|
-
if (deploy === 'Yes') {
|
|
134
|
-
yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
|
|
135
|
-
yield quickDeploy(targetPath, projectConfig);
|
|
136
|
-
const service = yield ApiService.getInstance();
|
|
137
|
-
const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
|
|
138
|
-
const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
|
|
139
|
-
const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
|
|
140
|
-
logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
|
|
141
|
-
logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
export function handleInit(argv) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
// Update the template package (currently commented out)
|
|
148
|
-
yield checkAndUpdatePackage('esa-template');
|
|
149
|
-
// If config option is provided, generate config file and exit
|
|
150
|
-
const config = getCliConfig();
|
|
151
|
-
if (config === undefined) {
|
|
152
|
-
yield generateConfigFile(String(config));
|
|
153
|
-
}
|
|
154
|
-
const name = yield promptProjectName();
|
|
155
|
-
const templateItems = prepareTemplateItems();
|
|
156
|
-
// Select a template
|
|
157
|
-
const selectedTemplatePath = yield selectTemplate(templateItems);
|
|
158
|
-
if (!selectedTemplatePath) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
// Initialize project files and configuration
|
|
162
|
-
const project = yield initializeProject(selectedTemplatePath, name);
|
|
163
|
-
if (!project) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const { template, targetPath } = project;
|
|
167
|
-
// Handle Git initialization
|
|
168
|
-
yield handleGitInitialization(targetPath);
|
|
169
|
-
// Handle deployment
|
|
170
|
-
const projectConfig = getProjectConfig(targetPath);
|
|
171
|
-
yield handleDeployment(targetPath, projectConfig);
|
|
172
|
-
template.printSummary();
|
|
65
|
+
const handleInit = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
yield checkAndUpdatePackage('esa-template');
|
|
67
|
+
const initParams = getInitParamsFromArgv(argv);
|
|
68
|
+
yield create(initParams);
|
|
69
|
+
yield config(initParams);
|
|
70
|
+
yield deploy(initParams);
|
|
71
|
+
});
|
|
72
|
+
const create = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
intro(`Create an application with ESA ${chalk.gray('Step 1 of 3')}`);
|
|
74
|
+
yield configProjectName(initParams);
|
|
75
|
+
yield configCategory(initParams);
|
|
76
|
+
yield configTemplate(initParams);
|
|
77
|
+
if (initParams.category === 'framework') {
|
|
78
|
+
yield configLanguage(initParams);
|
|
79
|
+
}
|
|
80
|
+
yield createProject(initParams);
|
|
81
|
+
yield installDependencies(initParams);
|
|
82
|
+
outro(`Application created`);
|
|
83
|
+
});
|
|
84
|
+
const config = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
intro(`Configure an application with ESA ${chalk.gray('Step 2 of 3')}`);
|
|
86
|
+
yield applyFileEdits(initParams);
|
|
87
|
+
yield installESACli(initParams);
|
|
88
|
+
yield updateConfigFile(initParams);
|
|
89
|
+
yield initGit(initParams);
|
|
90
|
+
outro(`Project configured`);
|
|
91
|
+
});
|
|
92
|
+
const deploy = (initParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
intro(`Deploy an application with ESA ${chalk.gray('Step 3 of 3')}`);
|
|
94
|
+
if (!initParams.deploy) {
|
|
95
|
+
const deploy = (yield promptParameter({
|
|
96
|
+
type: 'confirm',
|
|
97
|
+
question: t('auto_deploy').d('Do you want to deploy your project?'),
|
|
98
|
+
label: 'Auto deploy',
|
|
99
|
+
defaultValue: false
|
|
100
|
+
}));
|
|
101
|
+
initParams.deploy = deploy;
|
|
102
|
+
}
|
|
103
|
+
if (!initParams.deploy) {
|
|
104
|
+
outro(`Deploy project skipped`);
|
|
173
105
|
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
106
|
+
}
|
|
107
|
+
yield buildProject(initParams);
|
|
108
|
+
yield deployProject(initParams);
|
|
109
|
+
outro(`Deploy project finished`);
|
|
110
|
+
yield displayDeploySuccess(initParams.name, true, true);
|
|
111
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"react": {
|
|
3
|
+
"label": "React",
|
|
4
|
+
"command": "npm create vite@7.1.3",
|
|
5
|
+
"useGit": true,
|
|
6
|
+
"language": {
|
|
7
|
+
"typescript": "-- --template react-ts",
|
|
8
|
+
"javascript": "-- --template react"
|
|
9
|
+
},
|
|
10
|
+
"interactive": false,
|
|
11
|
+
"assets": {
|
|
12
|
+
"directory": "./dist",
|
|
13
|
+
"notFoundStrategy": "singlePageApplication"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"vue": {
|
|
17
|
+
"label": "Vue",
|
|
18
|
+
"command": "npm create vite@7.1.3",
|
|
19
|
+
"useGit": true,
|
|
20
|
+
"language": {
|
|
21
|
+
"typescript": "-- --template vue-ts -- --use-npm",
|
|
22
|
+
"javascript": "-- --template vue"
|
|
23
|
+
},
|
|
24
|
+
"interactive": false,
|
|
25
|
+
"assets": {
|
|
26
|
+
"directory": "./dist",
|
|
27
|
+
"notFoundStrategy": "singlePageApplication"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"nextjs": {
|
|
31
|
+
"label": "Next.js",
|
|
32
|
+
"useGit": false,
|
|
33
|
+
"command": "npx create-next-app@latest",
|
|
34
|
+
"hint": "Only support static export",
|
|
35
|
+
"assets": {
|
|
36
|
+
"directory": "./out"
|
|
37
|
+
},
|
|
38
|
+
"fileEdits": [
|
|
39
|
+
{
|
|
40
|
+
"match": "next.config.ts",
|
|
41
|
+
"matchType": "exact",
|
|
42
|
+
"action": "overwrite",
|
|
43
|
+
"fromFile": "snippets/nextjs/next.config.ts",
|
|
44
|
+
"createIfMissing": true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"match": "next.config.mjs",
|
|
48
|
+
"matchType": "exact",
|
|
49
|
+
"action": "overwrite",
|
|
50
|
+
"fromFile": "snippets/nextjs/next.config.mjs",
|
|
51
|
+
"createIfMissing": true
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"astro": {
|
|
56
|
+
"label": "Astro",
|
|
57
|
+
"useGit": false,
|
|
58
|
+
"command": "npm create astro@4.13.1",
|
|
59
|
+
"params": "--no-install",
|
|
60
|
+
"assets": {
|
|
61
|
+
"directory": "./dist"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"react-router": {
|
|
65
|
+
"label": "React Router",
|
|
66
|
+
"useGit": false,
|
|
67
|
+
"command": "npx create-react-router",
|
|
68
|
+
"hint": "SPA mode",
|
|
69
|
+
"interactive": true,
|
|
70
|
+
"assets": {
|
|
71
|
+
"directory": "./build/client",
|
|
72
|
+
"notFoundStrategy": "singlePageApplication"
|
|
73
|
+
},
|
|
74
|
+
"fileEdits": [
|
|
75
|
+
{
|
|
76
|
+
"match": "react-router.config.ts",
|
|
77
|
+
"matchType": "exact",
|
|
78
|
+
"action": "overwrite",
|
|
79
|
+
"fromFile": "snippets/react-router/react-router.config.ts",
|
|
80
|
+
"createIfMissing": true
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/commands/lang.js
CHANGED
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import SelectItems from '../components/selectInput.js';
|
|
11
|
-
import { updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
12
|
-
import logger from '../libs/logger.js';
|
|
13
11
|
import t from '../i18n/index.js';
|
|
12
|
+
import logger from '../libs/logger.js';
|
|
13
|
+
import { updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
14
14
|
const docs = {
|
|
15
15
|
command: 'lang',
|
|
16
16
|
describe: `🌐 ${t('lang_describe').d('Set the language of the CLI')}`,
|
|
@@ -7,24 +7,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
11
|
-
import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
|
|
10
|
+
import { isCancel, select as clackSelect, text as clackText } from '@clack/prompts';
|
|
12
11
|
import chalk from 'chalk';
|
|
13
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
14
12
|
import t from '../../i18n/index.js';
|
|
13
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
15
14
|
import logger from '../../libs/logger.js';
|
|
15
|
+
import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.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
|
+
const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
|
|
42
|
+
const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
|
|
43
|
+
if (accessKeyId && accessKeySecret) {
|
|
44
|
+
yield handleLoginWithAKSK(accessKeyId, accessKeySecret);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (process.env.ESA_ACCESS_KEY_ID && process.env.ESA_ACCESS_KEY_SECRET) {
|
|
48
|
+
logger.log(`🔑 ${t('login_get_from_env').d(`Get AccessKey ID and AccessKey Secret from environment variables.`)}`);
|
|
49
|
+
yield handleLoginWithAKSK(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
28
52
|
const cliConfig = getCliConfig();
|
|
29
53
|
if (!cliConfig)
|
|
30
54
|
return;
|
|
@@ -33,21 +57,20 @@ export function handleLogin() {
|
|
|
33
57
|
cliConfig.auth.accessKeyId &&
|
|
34
58
|
cliConfig.auth.accessKeySecret) {
|
|
35
59
|
const service = yield ApiService.getInstance();
|
|
36
|
-
const loginStatus = yield service.checkLogin(
|
|
60
|
+
const loginStatus = yield service.checkLogin();
|
|
37
61
|
if (loginStatus.success) {
|
|
38
62
|
logger.warn(t('login_already').d('You are already logged in.'));
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (action.action === t('common_exit').d('Exit')) {
|
|
63
|
+
const selected = (yield clackSelect({
|
|
64
|
+
message: t('login_existing_credentials_message').d('Existing credentials found. What do you want to do?'),
|
|
65
|
+
options: [
|
|
66
|
+
{
|
|
67
|
+
label: t('login_existing_credentials_action_overwrite').d('Overwrite existing credentials'),
|
|
68
|
+
value: 'overwrite'
|
|
69
|
+
},
|
|
70
|
+
{ label: t('common_exit').d('Exit'), value: 'exit' }
|
|
71
|
+
]
|
|
72
|
+
}));
|
|
73
|
+
if (isCancel(selected) || selected === 'exit') {
|
|
51
74
|
return;
|
|
52
75
|
}
|
|
53
76
|
yield getUserInputAuthInfo();
|
|
@@ -64,28 +87,45 @@ export function handleLogin() {
|
|
|
64
87
|
}
|
|
65
88
|
});
|
|
66
89
|
}
|
|
90
|
+
function handleLoginWithAKSK(accessKeyId, accessKeySecret) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
let apiConfig = getApiConfig();
|
|
93
|
+
apiConfig.auth = {
|
|
94
|
+
accessKeyId,
|
|
95
|
+
accessKeySecret
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
yield updateCliConfigFile({
|
|
99
|
+
auth: apiConfig.auth
|
|
100
|
+
});
|
|
101
|
+
const service = yield ApiService.getInstance();
|
|
102
|
+
service.updateConfig(apiConfig);
|
|
103
|
+
const loginStatus = yield service.checkLogin();
|
|
104
|
+
if (loginStatus.success) {
|
|
105
|
+
logger.success(t('login_success').d('Login success!'));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
logger.error(loginStatus.message || 'Login failed');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
logger.error(t('login_failed').d('An error occurred while trying to log in.'));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
67
116
|
export function getUserInputAuthInfo() {
|
|
68
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
118
|
const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
|
|
70
119
|
logger.log(`🔑 ${chalk.underline(t('login_get_ak_sk').d(`Please go to the following link to get your account's AccessKey ID and AccessKey Secret`))}`);
|
|
71
120
|
logger.log(`👉 ${styledUrl}`);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
message: 'AccessKey ID:'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
type: 'password',
|
|
80
|
-
name: 'accessKeySecret',
|
|
81
|
-
message: 'AccessKey Secret:',
|
|
82
|
-
mask: '*'
|
|
83
|
-
}
|
|
84
|
-
]);
|
|
121
|
+
const accessKeyId = (yield clackText({ message: 'AccessKey ID:' }));
|
|
122
|
+
const accessKeySecret = (yield clackText({
|
|
123
|
+
message: 'AccessKey Secret:'
|
|
124
|
+
}));
|
|
85
125
|
let apiConfig = getApiConfig();
|
|
86
126
|
apiConfig.auth = {
|
|
87
|
-
accessKeyId
|
|
88
|
-
accessKeySecret
|
|
127
|
+
accessKeyId,
|
|
128
|
+
accessKeySecret
|
|
89
129
|
};
|
|
90
130
|
try {
|
|
91
131
|
yield updateCliConfigFile({
|
package/dist/commands/logout.js
CHANGED
|
@@ -7,21 +7,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
11
|
-
import logger from '../libs/logger.js';
|
|
12
10
|
import t from '../i18n/index.js';
|
|
11
|
+
import logger from '../libs/logger.js';
|
|
12
|
+
import { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/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
|
},
|
|
19
|
-
handler: (
|
|
20
|
-
handleLogout(
|
|
19
|
+
handler: () => {
|
|
20
|
+
handleLogout();
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export default logout;
|
|
24
|
-
export function handleLogout(
|
|
24
|
+
export function handleLogout() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
let cliConfig = getCliConfig();
|
|
27
27
|
if (!cliConfig) {
|