esa-cli 0.0.2-beta.4 → 0.0.2-beta.6
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/dev/ew2/devPack.js +1 -1
- package/dist/commands/dev/index.js +2 -1
- package/dist/commands/dev/mockWorker/devPack.js +1 -1
- package/dist/i18n/locales.json +24 -0
- package/dist/index.js +0 -8
- package/dist/utils/download.js +173 -0
- package/dist/utils/installDeno.js +6 -5
- package/package.json +3 -2
|
@@ -81,7 +81,7 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
|
|
|
81
81
|
const destPath = path.resolve(mockDevDir, file);
|
|
82
82
|
yield fs.promises.copyFile(srcPath, destPath);
|
|
83
83
|
}
|
|
84
|
-
return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry}'`));
|
|
84
|
+
return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`));
|
|
85
85
|
});
|
|
86
86
|
// 前期准备
|
|
87
87
|
const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -27,7 +27,8 @@ import checkAndInputPort from '../../utils/checkDevPort.js';
|
|
|
27
27
|
import { checkOS, Platforms } from '../../utils/checkOS.js';
|
|
28
28
|
let yargsIns;
|
|
29
29
|
const OS = checkOS();
|
|
30
|
-
const
|
|
30
|
+
const EW2OS = [Platforms.AppleArm, Platforms.AppleIntel, Platforms.LinuxX86];
|
|
31
|
+
const useEw2 = EW2OS.includes(OS);
|
|
31
32
|
const dev = {
|
|
32
33
|
command: 'dev [entry]',
|
|
33
34
|
describe: `💻 ${t('dev_describe').d('Start a local server for developing your routine')}`,
|
|
@@ -35,7 +35,7 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
|
|
|
35
35
|
const destPath = path.resolve(mockDevDir, file);
|
|
36
36
|
yield fs.promises.copyFile(srcPath, destPath);
|
|
37
37
|
}
|
|
38
|
-
return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry}'`));
|
|
38
|
+
return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`));
|
|
39
39
|
});
|
|
40
40
|
const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
41
|
const options = {};
|
package/dist/i18n/locales.json
CHANGED
|
@@ -894,5 +894,29 @@
|
|
|
894
894
|
"dev_url_invalid": {
|
|
895
895
|
"en": "Invalid URL: ${url}. Please enter a valid URL.",
|
|
896
896
|
"zh_CN": "不是正确的URL: ${url}. 请输入正确的URL."
|
|
897
|
+
},
|
|
898
|
+
"deno_download_failed": {
|
|
899
|
+
"en": "Download failed",
|
|
900
|
+
"zh_CN": "下载失败"
|
|
901
|
+
},
|
|
902
|
+
"deno_unzip_failed": {
|
|
903
|
+
"en": "Unzip failed",
|
|
904
|
+
"zh_CN": "解压失败"
|
|
905
|
+
},
|
|
906
|
+
"deno_add_path_failed": {
|
|
907
|
+
"en": "Add BinDir to Path failed",
|
|
908
|
+
"zh_CN": "添加环境变量失败"
|
|
909
|
+
},
|
|
910
|
+
"deno_install_success": {
|
|
911
|
+
"en": "Runtime install success!",
|
|
912
|
+
"zh_CN": "Runtime 安装成功!"
|
|
913
|
+
},
|
|
914
|
+
"deno_download_success": {
|
|
915
|
+
"en": "Download success",
|
|
916
|
+
"zh_CN": "下载成功"
|
|
917
|
+
},
|
|
918
|
+
"deno_install_success_tips": {
|
|
919
|
+
"en": "Please run ${dev} again",
|
|
920
|
+
"zh_CN": ""
|
|
897
921
|
}
|
|
898
922
|
}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,6 @@ import { getCliConfig } from './utils/fileUtils/index.js';
|
|
|
26
26
|
import { handleCheckVersion } from './utils/checkVersion.js';
|
|
27
27
|
import t from './i18n/index.js';
|
|
28
28
|
import site from './commands/site/index.js';
|
|
29
|
-
import { quickDeployRoutine } from './libs/service.js';
|
|
30
29
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
30
|
const argv = hideBin(process.argv);
|
|
32
31
|
const cliConfig = getCliConfig();
|
|
@@ -74,13 +73,6 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
74
73
|
esa.command(logout);
|
|
75
74
|
esa.command(config);
|
|
76
75
|
esa.command(lang);
|
|
77
|
-
esa.command('t', false, () => { }, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
-
const res = yield quickDeployRoutine({
|
|
79
|
-
name: 'test',
|
|
80
|
-
code: 'test'
|
|
81
|
-
});
|
|
82
|
-
// console.log(res);
|
|
83
|
-
}));
|
|
84
76
|
esa.group(['help', 'version'], 'Options:');
|
|
85
77
|
esa.parse();
|
|
86
78
|
});
|
|
@@ -0,0 +1,173 @@
|
|
|
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 fetch from 'node-fetch';
|
|
11
|
+
import * as fs from 'fs/promises';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import os from 'os';
|
|
14
|
+
import AdmZip from 'adm-zip';
|
|
15
|
+
import { exec } from 'child_process';
|
|
16
|
+
import { promisify } from 'util';
|
|
17
|
+
import t from '../i18n/index.js';
|
|
18
|
+
import logger from '../libs/logger.js';
|
|
19
|
+
import chalk from 'chalk';
|
|
20
|
+
const execAsync = promisify(exec);
|
|
21
|
+
function getBinDir() {
|
|
22
|
+
const home = os.homedir();
|
|
23
|
+
return path.join(home || '', '.deno', 'bin');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 下载文件
|
|
27
|
+
* @param url 远程文件URL
|
|
28
|
+
* @param dest 本地保存路径
|
|
29
|
+
*/
|
|
30
|
+
export function downloadFile(url, dest) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const response = yield fetch(url);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`Error downloading file: ${response.status} ${response.statusText}`);
|
|
35
|
+
}
|
|
36
|
+
const fileStream = yield fs.open(dest, 'w');
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
(_a = response.body) === null || _a === void 0 ? void 0 : _a.pipe(fileStream.createWriteStream());
|
|
40
|
+
(_b = response.body) === null || _b === void 0 ? void 0 : _b.on('error', (err) => {
|
|
41
|
+
fileStream.close();
|
|
42
|
+
reject(err);
|
|
43
|
+
});
|
|
44
|
+
fileStream.createWriteStream().on('finish', () => {
|
|
45
|
+
fileStream.close();
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 解压Zip文件 adm 是同步的
|
|
53
|
+
* @param zipPath Zip文件路径
|
|
54
|
+
* @param extractPath 解压目标目录
|
|
55
|
+
*/
|
|
56
|
+
export function unzipFile(zipPath, extractPath) {
|
|
57
|
+
const zip = new AdmZip(zipPath);
|
|
58
|
+
zip.extractAllTo(extractPath, true);
|
|
59
|
+
logger.info(`UnzipFile success: from ${zipPath} to ${extractPath}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 获取用户的 PATH 环境变量(win下专用)
|
|
63
|
+
* @returns 用户 PATH
|
|
64
|
+
*/
|
|
65
|
+
function getUserPath() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const { stdout } = yield execAsync('reg query "HKCU\\Environment" /v Path');
|
|
68
|
+
const match = stdout.match(/Path\s+REG_EXPAND_SZ\s+(.*)/i);
|
|
69
|
+
if (match && match[1]) {
|
|
70
|
+
return match[1].trim();
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 检查 BinDir 是否在用户的 PATH 中(win下专用)
|
|
77
|
+
* @param binDir BinDir 路径
|
|
78
|
+
* @returns 是否包含
|
|
79
|
+
*/
|
|
80
|
+
function isBinDirInPath(binDir) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const userPath = yield getUserPath();
|
|
83
|
+
return userPath
|
|
84
|
+
.split(';')
|
|
85
|
+
.map((p) => p.toLowerCase())
|
|
86
|
+
.includes(binDir.toLowerCase());
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 将 BinDir 添加到用户的 PATH 环境变量(win下专用)
|
|
91
|
+
* @param binDir BinDir 路径
|
|
92
|
+
*/
|
|
93
|
+
function addBinDirToPath(binDir) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
// 使用 setx 添加到 PATH
|
|
96
|
+
// setx 对 PATH 的长度有2047字符的限制
|
|
97
|
+
const command = `setx Path "%Path%;${binDir}"`;
|
|
98
|
+
try {
|
|
99
|
+
yield execAsync(command);
|
|
100
|
+
logger.info(`Path add success: ${binDir}`);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error(`Add BinDir to Path failed: ${error}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export function downloadRuntimeAndUnzipForWindows() {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
const BinDir = getBinDir();
|
|
111
|
+
const DenoZip = path.join(BinDir, 'deno.zip');
|
|
112
|
+
const Target = 'x86_64-pc-windows-msvc';
|
|
113
|
+
const DownloadUrl = `http://esa-runtime.myalicdn.com/runtime/deno-${Target}.zip`;
|
|
114
|
+
try {
|
|
115
|
+
yield fs.mkdir(BinDir, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const err = error;
|
|
119
|
+
logger.error(`mkdir error ${BinDir}: ${err.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
yield downloadFile(DownloadUrl, DenoZip);
|
|
124
|
+
logger.success(`${t('deno_download_success').d('Download success')}: ${DenoZip}`);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const err = error;
|
|
128
|
+
logger.error(`${t('deno_download_failed').d('Download failed')}: ${err.message}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
logger.info(`Unzip file to: ${BinDir}`);
|
|
132
|
+
try {
|
|
133
|
+
unzipFile(DenoZip, BinDir);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const err = error;
|
|
137
|
+
logger.error(`${t('deno_unzip_failed').d('Unzip failed')}: ${err.message}`);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
yield fs.unlink(DenoZip);
|
|
142
|
+
logger.info(`Delete temp file: ${DenoZip}`);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
logger.warn(`Delete temp file ${DenoZip} failed: ${error}`);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const inPath = yield isBinDirInPath(BinDir);
|
|
149
|
+
if (!inPath) {
|
|
150
|
+
logger.info(`${BinDir} not in PATH, adding...`);
|
|
151
|
+
yield addBinDirToPath(BinDir);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
logger.info(`${BinDir} in PATH already`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
const err = error;
|
|
159
|
+
logger.error(`${t('deno_add_path_failed').d('Add BinDir to Path failed')}: ${err.message}`);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
logger.success(t('deno_install_success').d('Runtime install success!'));
|
|
163
|
+
logger.block();
|
|
164
|
+
const dev = chalk.green('esa dev');
|
|
165
|
+
logger.log(t('deno_install_success_tips', { dev }).d(`Please run ${dev} again`));
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
const err = error;
|
|
169
|
+
logger.error(`Download Error: ${err.message}`);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { exec, execSync } from 'child_process';
|
|
11
11
|
import os from 'os';
|
|
12
|
-
import { getDirName } from './fileUtils/base.js';
|
|
13
|
-
import logger from '../libs/logger.js';
|
|
14
12
|
import path from 'path';
|
|
13
|
+
import logger from '../libs/logger.js';
|
|
14
|
+
import { getDirName } from './fileUtils/base.js';
|
|
15
|
+
import { downloadRuntimeAndUnzipForWindows } from './download.js';
|
|
15
16
|
import t from '../i18n/index.js';
|
|
16
17
|
export function preCheckDeno() {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
const command = yield checkDenoInstalled();
|
|
19
20
|
if (!command) {
|
|
20
21
|
logger.error(t('install_runtime_explain').d('Under the beta phase, we are temporarily using Deno as the local development runtime. It needs to be installed first.'));
|
|
21
|
-
installDeno();
|
|
22
|
+
yield installDeno();
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
24
25
|
return command;
|
|
@@ -57,8 +58,8 @@ export function installDeno() {
|
|
|
57
58
|
const p = path.join(__dirname, './install');
|
|
58
59
|
switch (os.platform()) {
|
|
59
60
|
case 'win32':
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
yield downloadRuntimeAndUnzipForWindows();
|
|
62
|
+
return true;
|
|
62
63
|
case 'darwin':
|
|
63
64
|
case 'linux':
|
|
64
65
|
installCommand = `sh ${p}/install.sh`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esa-cli",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.6",
|
|
4
4
|
"description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
|
|
5
5
|
"main": "bin/enter.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@testing-library/dom": "^10.4.0",
|
|
38
38
|
"@testing-library/jest-dom": "^6.5.0",
|
|
39
39
|
"@testing-library/react": "^16.0.1",
|
|
40
|
+
"@types/adm-zip": "^0.5.7",
|
|
40
41
|
"@types/babel__generator": "^7.6.8",
|
|
41
42
|
"@types/babel__traverse": "^7.20.6",
|
|
42
43
|
"@types/cli-table": "^0.3.4",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"@iarna/toml": "^2.2.5",
|
|
75
76
|
"@types/inquirer": "^9.0.7",
|
|
76
77
|
"@vitest/coverage-istanbul": "^2.0.4",
|
|
77
|
-
"
|
|
78
|
+
"adm-zip": "^0.5.16",
|
|
78
79
|
"chalk": "^5.3.0",
|
|
79
80
|
"chokidar": "^3.5.3",
|
|
80
81
|
"cli-table3": "^0.6.5",
|