esa-cli 0.0.1-beta.1
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/LICENSE +21 -0
- package/README.md +175 -0
- package/bin/enter.cjs +52 -0
- package/dist/README.md +175 -0
- package/dist/bin/enter.cjs +52 -0
- package/dist/cliconfig.toml +6 -0
- package/dist/commands/commit/index.js +147 -0
- package/dist/commands/commit/prodBuild.js +50 -0
- package/dist/commands/common/constant.js +54 -0
- package/dist/commands/config.js +51 -0
- package/dist/commands/deploy/helper.js +108 -0
- package/dist/commands/deploy/index.js +217 -0
- package/dist/commands/deployments/delete.js +92 -0
- package/dist/commands/deployments/index.js +27 -0
- package/dist/commands/deployments/list.js +89 -0
- package/dist/commands/dev/config/devBuild.js +26 -0
- package/dist/commands/dev/config/devEntry.js +71 -0
- package/dist/commands/dev/config/mock/cache.js +31 -0
- package/dist/commands/dev/config/mock/kv.js +87 -0
- package/dist/commands/dev/devPack.js +113 -0
- package/dist/commands/dev/doProcess.js +73 -0
- package/dist/commands/dev/index.js +240 -0
- package/dist/commands/dev/server.js +100 -0
- package/dist/commands/domain/add.js +72 -0
- package/dist/commands/domain/delete.js +74 -0
- package/dist/commands/domain/index.js +29 -0
- package/dist/commands/domain/list.js +51 -0
- package/dist/commands/init/index.js +149 -0
- package/dist/commands/lang.js +32 -0
- package/dist/commands/login/index.js +108 -0
- package/dist/commands/logout.js +44 -0
- package/dist/commands/route/add.js +115 -0
- package/dist/commands/route/delete.js +74 -0
- package/dist/commands/route/index.js +29 -0
- package/dist/commands/route/list.js +63 -0
- package/dist/commands/routine/delete.js +54 -0
- package/dist/commands/routine/index.js +27 -0
- package/dist/commands/routine/list.js +101 -0
- package/dist/commands/site/index.js +25 -0
- package/dist/commands/site/list.js +47 -0
- package/dist/commands/utils.js +139 -0
- package/dist/components/descriptionInput.js +38 -0
- package/dist/components/filterSelector.js +132 -0
- package/dist/components/mutiSelectTable.js +95 -0
- package/dist/components/selectInput.js +17 -0
- package/dist/components/selectItem.js +6 -0
- package/dist/components/yesNoPrompt.js +9 -0
- package/dist/docs/Commands_en.md +224 -0
- package/dist/docs/Commands_zh_CN.md +224 -0
- package/dist/docs/dev.png +0 -0
- package/dist/i18n/index.js +27 -0
- package/dist/i18n/locales.json +766 -0
- package/dist/index.js +80 -0
- package/dist/libs/apiService.js +914 -0
- package/dist/libs/git/index.js +52 -0
- package/dist/libs/interface.js +21 -0
- package/dist/libs/logger.js +149 -0
- package/dist/libs/request.js +98 -0
- package/dist/libs/templates/index.js +16 -0
- package/dist/package.json +93 -0
- package/dist/utils/checkDevPort.js +113 -0
- package/dist/utils/checkIsRoutineCreated.js +56 -0
- package/dist/utils/checkVersion.js +26 -0
- package/dist/utils/debounce.js +18 -0
- package/dist/utils/fileUtils/index.js +219 -0
- package/dist/utils/fileUtils/interface.js +1 -0
- package/dist/utils/install/install.ps1 +33 -0
- package/dist/utils/install/install.sh +53 -0
- package/dist/utils/installRuntime.js +80 -0
- package/dist/utils/openInBrowser.js +24 -0
- package/dist/utils/sleep.js +6 -0
- package/dist/zh_CN.md +177 -0
- package/package.json +93 -0
|
@@ -0,0 +1,100 @@
|
|
|
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 spawn from 'cross-spawn';
|
|
11
|
+
import logger from '../../libs/logger.js';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
14
|
+
import { getDevConf, getRoot } from '../../utils/fileUtils/index.js';
|
|
15
|
+
class WorkerServer {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
this.instance = null;
|
|
18
|
+
this.restarting = false;
|
|
19
|
+
this.command = props.command || 'deno';
|
|
20
|
+
this.start();
|
|
21
|
+
}
|
|
22
|
+
start() {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
if (this.instance) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const root = getRoot();
|
|
28
|
+
const inspectPort = getDevConf('inspectPort', 'dev', 9229);
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const id = global.id || '';
|
|
31
|
+
let inspectOption = '--inspect';
|
|
32
|
+
if (inspectPort !== 9229) {
|
|
33
|
+
inspectOption = `--inspect=127.0.0.1:${inspectPort}`;
|
|
34
|
+
}
|
|
35
|
+
this.instance = spawn(this.command, [
|
|
36
|
+
'run',
|
|
37
|
+
'--no-lock',
|
|
38
|
+
'--allow-net',
|
|
39
|
+
'--allow-read',
|
|
40
|
+
'--allow-write',
|
|
41
|
+
inspectOption,
|
|
42
|
+
path.join(root, `.dev/index-${id}.js`),
|
|
43
|
+
id
|
|
44
|
+
], {
|
|
45
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
46
|
+
});
|
|
47
|
+
(_a = this.instance.stdout) === null || _a === void 0 ? void 0 : _a.setEncoding('utf8');
|
|
48
|
+
(_b = this.instance.stdout) === null || _b === void 0 ? void 0 : _b.on('data', this.stdoutHandler.bind(this));
|
|
49
|
+
(_c = this.instance.stderr) === null || _c === void 0 ? void 0 : _c.on('data', this.stderrHandler.bind(this));
|
|
50
|
+
this.instance.on('close', this.closeHandler.bind(this));
|
|
51
|
+
this.instance.on('error', this.errorHandler.bind(this));
|
|
52
|
+
}
|
|
53
|
+
stdoutHandler(chunk) {
|
|
54
|
+
logger.log(chunk.toString().trim());
|
|
55
|
+
}
|
|
56
|
+
stderrHandler(chunk) {
|
|
57
|
+
logger.subError(chunk.toString().trim());
|
|
58
|
+
}
|
|
59
|
+
errorHandler(err) {
|
|
60
|
+
console.log(err);
|
|
61
|
+
logger.error(err.message ? err.message : err);
|
|
62
|
+
this.instance && this.instance.kill();
|
|
63
|
+
}
|
|
64
|
+
closeHandler(code, signal) {
|
|
65
|
+
if (this.restarting) {
|
|
66
|
+
this.restarting = false;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
logger.info(t('dev_server_closed').d('Worker server closed'));
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
global.port = undefined;
|
|
72
|
+
}
|
|
73
|
+
runCommand(command) {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
(_b = (_a = this.instance) === null || _a === void 0 ? void 0 : _a.stdin) === null || _b === void 0 ? void 0 : _b.write(command);
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
if (!this.instance) {
|
|
80
|
+
resolve(0);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const onExit = (code, signal) => {
|
|
84
|
+
this.instance = null;
|
|
85
|
+
resolve(1);
|
|
86
|
+
};
|
|
87
|
+
this.instance.on('exit', onExit);
|
|
88
|
+
this.instance.kill('SIGTERM');
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
restart() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
this.restarting = true;
|
|
94
|
+
yield this.stop();
|
|
95
|
+
this.start();
|
|
96
|
+
logger.info(t('dev_server_restart').d('Worker server restarted'));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export default WorkerServer;
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { bindRoutineWithDomain, checkDirectory, checkIsLoginSuccess, validDomain, validName } from '../utils.js';
|
|
11
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
12
|
+
import t from '../../i18n/index.js';
|
|
13
|
+
import logger from '../../libs/logger.js';
|
|
14
|
+
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
15
|
+
const addDomain = {
|
|
16
|
+
command: 'add <domain>',
|
|
17
|
+
describe: `📥 ${t('domain_add_describe').d('Bind a domain to a routine')}`,
|
|
18
|
+
builder: (yargs) => {
|
|
19
|
+
return yargs
|
|
20
|
+
.positional('domain', {
|
|
21
|
+
describe: t('domain_add_positional_describe').d('The name of domain to add'),
|
|
22
|
+
type: 'string',
|
|
23
|
+
demandOption: true
|
|
24
|
+
})
|
|
25
|
+
.usage(`${t('common_usage').d('Usage')}: esa domain add <domain>`)
|
|
26
|
+
.option('help', {
|
|
27
|
+
alias: 'h',
|
|
28
|
+
describe: t('common_help').d('Help'),
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
default: false
|
|
31
|
+
})
|
|
32
|
+
.help()
|
|
33
|
+
.fail((msg, err, yargsIns) => {
|
|
34
|
+
console.log(msg, err);
|
|
35
|
+
if (err)
|
|
36
|
+
throw err;
|
|
37
|
+
if (msg) {
|
|
38
|
+
yargsIns.showHelp('log');
|
|
39
|
+
}
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
handleAddDomain(argv);
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
export default addDomain;
|
|
48
|
+
export function handleAddDomain(argv) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!checkDirectory()) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
54
|
+
if (!isSuccess)
|
|
55
|
+
return;
|
|
56
|
+
const projectConfig = getProjectConfig();
|
|
57
|
+
if (!projectConfig)
|
|
58
|
+
return logger.notInProject();
|
|
59
|
+
yield validRoutine(projectConfig.name);
|
|
60
|
+
const name = projectConfig.name;
|
|
61
|
+
const domain = argv.domain;
|
|
62
|
+
if (!validName(name)) {
|
|
63
|
+
logger.error(t('domain_add_invalid_name').d('Invalid name'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!domain || !validDomain(domain)) {
|
|
67
|
+
logger.error(t('domain_add_invalid_name').d('Invalid name'));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
yield bindRoutineWithDomain(name, domain);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
11
|
+
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
12
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
14
|
+
import logger from '../../libs/logger.js';
|
|
15
|
+
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
16
|
+
const deleteDomain = {
|
|
17
|
+
command: 'delete <domain>',
|
|
18
|
+
describe: `🗑 ${t('domain_delete_describe').d('Delete a related domain')}`,
|
|
19
|
+
builder: (yargs) => {
|
|
20
|
+
return yargs.positional('domains', {
|
|
21
|
+
describe: t('domain_delete_positional_describe').d('The names of the related domains to delete'),
|
|
22
|
+
type: 'string',
|
|
23
|
+
array: true,
|
|
24
|
+
demandOption: true
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
handleDeleteDomain(argv);
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
export default deleteDomain;
|
|
32
|
+
export function handleDeleteDomain(argv) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
if (!checkDirectory()) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const projectConfig = getProjectConfig();
|
|
39
|
+
if (!projectConfig)
|
|
40
|
+
return logger.notInProject();
|
|
41
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
42
|
+
if (!isSuccess)
|
|
43
|
+
return;
|
|
44
|
+
yield validRoutine(projectConfig.name);
|
|
45
|
+
const server = yield ApiService.getInstance();
|
|
46
|
+
const req = { Name: projectConfig.name || '' };
|
|
47
|
+
const routineDetail = yield server.getRoutine(req);
|
|
48
|
+
if (!routineDetail)
|
|
49
|
+
return;
|
|
50
|
+
const relatedRecords = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
|
|
51
|
+
const relatedDomain = argv.domain;
|
|
52
|
+
const matchedSite = relatedRecords.find((item) => {
|
|
53
|
+
return String(item.RecordName) === relatedDomain;
|
|
54
|
+
});
|
|
55
|
+
if (matchedSite === undefined) {
|
|
56
|
+
logger.error(t('domain_delete_not_found').d("Domain doesn't exist"));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const record = {
|
|
60
|
+
RecordName: matchedSite.RecordName,
|
|
61
|
+
Name: projectConfig.name || '',
|
|
62
|
+
SiteId: matchedSite.SiteId,
|
|
63
|
+
SiteName: matchedSite.SiteName,
|
|
64
|
+
RecordId: matchedSite.RecordId
|
|
65
|
+
};
|
|
66
|
+
const res = yield server.deleteRoutineRelatedRecord(record);
|
|
67
|
+
if ((res === null || res === void 0 ? void 0 : res.data.Status) === 'OK') {
|
|
68
|
+
logger.success(t('domain_delete_success').d('Delete domain success'));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
logger.error(t('domain_delete_failed').d('Delete domain failed'));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import addDomain from './add.js';
|
|
2
|
+
import listDomain from './list.js';
|
|
3
|
+
import deleteDomain from './delete.js';
|
|
4
|
+
import t from '../../i18n/index.js';
|
|
5
|
+
let yargsIns;
|
|
6
|
+
const domainCommand = {
|
|
7
|
+
command: 'domain [script]',
|
|
8
|
+
describe: `🚀 ${t('domain_describe').d('Manage the domain names bound to your routine')}`,
|
|
9
|
+
builder: (yargs) => {
|
|
10
|
+
yargsIns = yargs;
|
|
11
|
+
return yargs
|
|
12
|
+
.command(addDomain)
|
|
13
|
+
.command(listDomain)
|
|
14
|
+
.command(deleteDomain)
|
|
15
|
+
.option('help', {
|
|
16
|
+
alias: 'h',
|
|
17
|
+
describe: t('common_help').d('Help'),
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: false
|
|
20
|
+
})
|
|
21
|
+
.usage(`${t('common_usage').d('Usage')}: esa domain <add | list | delete>`);
|
|
22
|
+
},
|
|
23
|
+
handler: (argv) => {
|
|
24
|
+
if (yargsIns && (argv.help || argv._.length < 2)) {
|
|
25
|
+
yargsIns.showHelp('log');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export default domainCommand;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
11
|
+
import logger from '../../libs/logger.js';
|
|
12
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
13
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
14
|
+
import t from '../../i18n/index.js';
|
|
15
|
+
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
16
|
+
const listDomain = {
|
|
17
|
+
command: 'list',
|
|
18
|
+
describe: `🔍 ${t('domain_list_describe').d('List all related domains')}`,
|
|
19
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
handleListDomains(argv);
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
export default listDomain;
|
|
24
|
+
export function handleListDomains(argv) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (!checkDirectory()) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const projectConfig = getProjectConfig();
|
|
31
|
+
if (!projectConfig)
|
|
32
|
+
return logger.notInProject();
|
|
33
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
34
|
+
if (!isSuccess)
|
|
35
|
+
return;
|
|
36
|
+
yield validRoutine(projectConfig.name);
|
|
37
|
+
const server = yield ApiService.getInstance();
|
|
38
|
+
const req = { Name: projectConfig.name };
|
|
39
|
+
const routineDetail = yield server.getRoutine(req);
|
|
40
|
+
if (!routineDetail)
|
|
41
|
+
return;
|
|
42
|
+
const relatedRecords = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
|
|
43
|
+
if (relatedRecords.length === 0) {
|
|
44
|
+
logger.log(`🙅 ${t('domain_list_empty').d('No related domains found')}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const domainList = relatedRecords.map((record) => record.RecordName);
|
|
48
|
+
logger.log(`📃 ${t('domain_list_title').d('Related domains:')}`);
|
|
49
|
+
logger.tree(domainList);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 SelectItems from '../../components/selectInput.js';
|
|
11
|
+
import { rename } from 'fs/promises';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import Template from '../../libs/templates/index.js';
|
|
14
|
+
import { cloneRepository, installGit } from '../../libs/git/index.js';
|
|
15
|
+
import { descriptionInput } from '../../components/descriptionInput.js';
|
|
16
|
+
import { generateConfigFile, getProjectConfig, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
17
|
+
import t from '../../i18n/index.js';
|
|
18
|
+
import logger from '../../libs/logger.js';
|
|
19
|
+
import { quickDeploy } from '../deploy/index.js';
|
|
20
|
+
import chalk from 'chalk';
|
|
21
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
22
|
+
import { exit } from 'process';
|
|
23
|
+
import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
|
|
24
|
+
import path from 'path';
|
|
25
|
+
const secondSetOfItems = [
|
|
26
|
+
{ label: 'Yes', value: 'yesInstall' },
|
|
27
|
+
{ label: 'No', value: 'noInstall' }
|
|
28
|
+
];
|
|
29
|
+
const init = {
|
|
30
|
+
command: 'init',
|
|
31
|
+
describe: `📥 ${t('init_describe').d('Initialize a routine with a template')}`,
|
|
32
|
+
builder: (yargs) => {
|
|
33
|
+
return yargs.option('config', {
|
|
34
|
+
alias: 'c',
|
|
35
|
+
describe: t('init_config_file').d('Generate a config file for your project'),
|
|
36
|
+
type: 'boolean'
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
yield handleInit(argv);
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
export default init;
|
|
44
|
+
const downloadEntireTemplates = (entry) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
yield cloneRepository('https://github.com/aliyun/alibabacloud-esa-er-templates.git', entry);
|
|
46
|
+
});
|
|
47
|
+
export function handleInit(argv) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { config } = argv;
|
|
50
|
+
if (config !== undefined) {
|
|
51
|
+
yield generateConfigFile(String(config));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const name = yield descriptionInput(`🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`, true);
|
|
55
|
+
const regex = /^[a-z0-9-]{2,}$/;
|
|
56
|
+
if (!regex.test(name)) {
|
|
57
|
+
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.'));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let hiddenFolder = process.cwd() + '/.hidden';
|
|
61
|
+
// 删除隐藏文件夹
|
|
62
|
+
if (fs.existsSync(hiddenFolder)) {
|
|
63
|
+
fs.rmdirSync(hiddenFolder, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
// 下载所有模板到隐藏文件夹
|
|
66
|
+
yield downloadEntireTemplates(hiddenFolder);
|
|
67
|
+
//获取隐藏文件夹所有子目录
|
|
68
|
+
const templatePaths = fs.readdirSync(hiddenFolder).filter((item) => {
|
|
69
|
+
const itemPath = path.join(hiddenFolder, item);
|
|
70
|
+
const stats = fs.statSync(itemPath);
|
|
71
|
+
return stats.isDirectory() && item !== '.git';
|
|
72
|
+
});
|
|
73
|
+
const templateList = templatePaths.map((item) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const projectPath = hiddenFolder + '/' + item;
|
|
76
|
+
const projectConfig = getProjectConfig(projectPath);
|
|
77
|
+
const templateName = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '';
|
|
78
|
+
return new Template(projectPath, templateName);
|
|
79
|
+
});
|
|
80
|
+
const firstSetOfItems = templateList.map((template, index) => {
|
|
81
|
+
return { label: template.title, value: template.path };
|
|
82
|
+
});
|
|
83
|
+
let selectTemplate;
|
|
84
|
+
let targetPath;
|
|
85
|
+
let projectConfig;
|
|
86
|
+
const handleSecondSelection = (item) => {
|
|
87
|
+
if (item.value === 'yesInstall') {
|
|
88
|
+
installGit(targetPath);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
logger.info(t('init_skip_git').d('Git installation was skipped.'));
|
|
92
|
+
}
|
|
93
|
+
logger.info(t('auto_deploy').d('Do you want to deploy your project?'));
|
|
94
|
+
SelectItems({
|
|
95
|
+
items: secondSetOfItems,
|
|
96
|
+
handleSelect: handleThirdSelection
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const handleFirstSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const configPath = item.value;
|
|
101
|
+
selectTemplate = new Template(configPath, name);
|
|
102
|
+
projectConfig = getProjectConfig(configPath);
|
|
103
|
+
if (!projectConfig)
|
|
104
|
+
return logger.notInProject();
|
|
105
|
+
const newPath = process.cwd() + '/' + name;
|
|
106
|
+
targetPath = newPath;
|
|
107
|
+
if (fs.existsSync(newPath)) {
|
|
108
|
+
fs.rmdirSync(hiddenFolder, { recursive: true });
|
|
109
|
+
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.'));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
yield rename(configPath, newPath);
|
|
113
|
+
projectConfig.name = name;
|
|
114
|
+
updateProjectConfigFile(projectConfig, newPath);
|
|
115
|
+
logger.info(t('init_git').d('Do you want to init git in your project?'));
|
|
116
|
+
SelectItems({
|
|
117
|
+
items: secondSetOfItems,
|
|
118
|
+
handleSelect: handleSecondSelection
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const handleThirdSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
var _a, _b, _c;
|
|
123
|
+
// 选择自动生成版本并发布
|
|
124
|
+
if (item.value === 'yesInstall') {
|
|
125
|
+
yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
|
|
126
|
+
projectConfig && (yield quickDeploy(targetPath, projectConfig));
|
|
127
|
+
const service = yield ApiService.getInstance();
|
|
128
|
+
const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
|
|
129
|
+
const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
|
|
130
|
+
const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
|
|
131
|
+
logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
|
|
132
|
+
logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
|
|
133
|
+
}
|
|
134
|
+
selectTemplate.printSummary();
|
|
135
|
+
exit();
|
|
136
|
+
});
|
|
137
|
+
try {
|
|
138
|
+
SelectItems({
|
|
139
|
+
items: firstSetOfItems,
|
|
140
|
+
handleSelect: handleFirstSelection
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
logger.error(t('init_error').d('An error occurred while initializing.'));
|
|
145
|
+
console.log(error);
|
|
146
|
+
fs.rmdirSync(hiddenFolder, { recursive: true });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 SelectItems from '../components/selectInput.js';
|
|
11
|
+
import { updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
12
|
+
import logger from '../libs/logger.js';
|
|
13
|
+
import t from '../i18n/index.js';
|
|
14
|
+
const docs = {
|
|
15
|
+
command: 'lang',
|
|
16
|
+
describe: `🌐 ${t('lang_describe').d('Set the language of the CLI')}`,
|
|
17
|
+
handler: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
SelectItems({
|
|
19
|
+
items: [
|
|
20
|
+
{ label: 'English', value: 'en' },
|
|
21
|
+
{ label: '简体中文', value: 'zh_CN' }
|
|
22
|
+
],
|
|
23
|
+
handleSelect: (item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
yield updateCliConfigFile({
|
|
25
|
+
lang: item.value
|
|
26
|
+
});
|
|
27
|
+
logger.success(t('lang_success').d('Language switched'));
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
export default docs;
|
|
@@ -0,0 +1,108 @@
|
|
|
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 inquirer from 'inquirer';
|
|
11
|
+
import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
14
|
+
import t from '../../i18n/index.js';
|
|
15
|
+
import logger from '../../libs/logger.js';
|
|
16
|
+
const login = {
|
|
17
|
+
command: 'login',
|
|
18
|
+
describe: `🔑 ${t('login_describe').d('Login to the server')}`,
|
|
19
|
+
builder: {},
|
|
20
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
handleLogin();
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
export default login;
|
|
25
|
+
export function handleLogin() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
generateDefaultConfig();
|
|
28
|
+
const cliConfig = getCliConfig();
|
|
29
|
+
if (!cliConfig)
|
|
30
|
+
return;
|
|
31
|
+
if (cliConfig &&
|
|
32
|
+
cliConfig.auth &&
|
|
33
|
+
cliConfig.auth.accessKeyId &&
|
|
34
|
+
cliConfig.auth.accessKeySecret) {
|
|
35
|
+
const service = yield ApiService.getInstance();
|
|
36
|
+
const loginStatus = yield service.checkLogin(false);
|
|
37
|
+
if (loginStatus.success) {
|
|
38
|
+
logger.warn(t('login_already').d('You are already logged in.'));
|
|
39
|
+
const action = yield inquirer.prompt([
|
|
40
|
+
{
|
|
41
|
+
type: 'list',
|
|
42
|
+
name: 'action',
|
|
43
|
+
message: t('login_existing_credentials_message').d('Existing credentials found. What do you want to do?'),
|
|
44
|
+
choices: [
|
|
45
|
+
t('login_existing_credentials_action_overwrite').d('Overwrite existing credentials'),
|
|
46
|
+
t('common_exit').d('Exit')
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]);
|
|
50
|
+
if (action.action === t('common_exit').d('Exit')) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
yield getUserInputAuthInfo();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logger.error(t('pre_login_failed').d('The previously entered Access Key ID (AK) and Secret Access Key (SK) are incorrect. Please enter them again.'));
|
|
57
|
+
logger.info(`${t('login_logging').d('Logging in')}...`);
|
|
58
|
+
yield getUserInputAuthInfo();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger.info(`${t('login_logging').d('Logging in')}...`);
|
|
63
|
+
yield getUserInputAuthInfo();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function getUserInputAuthInfo() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
|
|
70
|
+
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
|
+
logger.log(`👉 ${styledUrl}`);
|
|
72
|
+
const answers = yield inquirer.prompt([
|
|
73
|
+
{
|
|
74
|
+
type: 'input',
|
|
75
|
+
name: 'accessKeyId',
|
|
76
|
+
message: 'AccessKey ID:'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'password',
|
|
80
|
+
name: 'accessKeySecret',
|
|
81
|
+
message: 'AccessKey Secret:',
|
|
82
|
+
mask: '*'
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
let apiConfig = getApiConfig();
|
|
86
|
+
apiConfig.auth = {
|
|
87
|
+
accessKeyId: answers.accessKeyId,
|
|
88
|
+
accessKeySecret: answers.accessKeySecret
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
yield updateCliConfigFile({
|
|
92
|
+
auth: apiConfig.auth
|
|
93
|
+
});
|
|
94
|
+
const service = yield ApiService.getInstance();
|
|
95
|
+
service.updateConfig(apiConfig);
|
|
96
|
+
const loginStatus = yield service.checkLogin();
|
|
97
|
+
if (loginStatus.success) {
|
|
98
|
+
logger.success(t('login_success').d('Login success!'));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
logger.error(loginStatus.message || 'Login failed');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
logger.error(t('login_failed').d('An error occurred while trying to log in.'));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
11
|
+
import { checkIsLoginSuccess } from './utils.js';
|
|
12
|
+
import logger from '../libs/logger.js';
|
|
13
|
+
import t from '../i18n/index.js';
|
|
14
|
+
const logout = {
|
|
15
|
+
command: 'logout',
|
|
16
|
+
describe: `📥 ${t('logout_describe').d('Logout')}`,
|
|
17
|
+
builder: (yargs) => {
|
|
18
|
+
return yargs;
|
|
19
|
+
},
|
|
20
|
+
handler: (argv) => {
|
|
21
|
+
handleLogout(argv);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export default logout;
|
|
25
|
+
export function handleLogout(argv) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
let cliConfig = getCliConfig();
|
|
28
|
+
if (!cliConfig) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
32
|
+
if (!isSuccess)
|
|
33
|
+
return;
|
|
34
|
+
if (!cliConfig.auth) {
|
|
35
|
+
cliConfig.auth = { accessKeyId: '', accessKeySecret: '' };
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
cliConfig.auth.accessKeyId = '';
|
|
39
|
+
cliConfig.auth.accessKeySecret = '';
|
|
40
|
+
}
|
|
41
|
+
yield updateCliConfigFile(cliConfig);
|
|
42
|
+
logger.success(t('logout_success').d('Logout successfully'));
|
|
43
|
+
});
|
|
44
|
+
}
|