esa-cli 0.0.2-beta.10 → 0.0.2-beta.13
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 +26 -115
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/routineUtils.js +276 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/deploy/helper.js +40 -61
- package/dist/commands/deploy/index.js +90 -188
- package/dist/commands/deployments/delete.js +32 -22
- package/dist/commands/deployments/index.js +2 -2
- package/dist/commands/deployments/list.js +22 -38
- 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 +22 -11
- 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 +162 -27
- package/dist/commands/dev/index.js +14 -15
- package/dist/commands/dev/mockWorker/devPack.js +16 -7
- package/dist/commands/dev/mockWorker/server.js +7 -6
- package/dist/commands/domain/add.js +2 -2
- package/dist/commands/domain/delete.js +7 -7
- package/dist/commands/domain/index.js +2 -2
- package/dist/commands/domain/list.js +10 -10
- package/dist/commands/init/helper.js +87 -13
- package/dist/commands/init/index.js +461 -57
- package/dist/commands/init/template.jsonc +34 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +57 -7
- package/dist/commands/logout.js +5 -5
- package/dist/commands/route/add.js +138 -49
- package/dist/commands/route/delete.js +33 -27
- package/dist/commands/route/helper.js +124 -0
- package/dist/commands/route/index.js +2 -2
- package/dist/commands/route/list.js +56 -17
- package/dist/commands/routine/delete.js +2 -2
- package/dist/commands/routine/index.js +2 -2
- package/dist/commands/routine/list.js +9 -21
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +55 -19
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +25 -15
- package/dist/docs/Commands_zh_CN.md +12 -2
- package/dist/docs/eslint-config-en.md +1 -0
- package/dist/docs/eslint-config.md +73 -0
- package/dist/docs/init-command-quick-test.md +208 -0
- package/dist/docs/init-command-test-guide.md +598 -0
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +261 -17
- package/dist/index.js +17 -12
- package/dist/libs/api.js +32 -9
- package/dist/libs/apiService.js +258 -85
- package/dist/libs/git/index.js +8 -4
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +63 -7
- 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 +3 -17
- package/dist/utils/checkEntryFileExist.js +10 -0
- package/dist/utils/checkIsRoutineCreated.js +16 -31
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/compress.js +80 -0
- package/dist/utils/download.js +5 -5
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/index.js +71 -22
- package/dist/utils/installDeno.js +3 -3
- package/dist/utils/installEw2.js +7 -7
- package/dist/utils/openInBrowser.js +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getProjectConfig } from './fileUtils/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check if the assets directory exists in the project config
|
|
6
|
+
* @returns {boolean} true if the assets directory exists, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
const checkConfigAssetsExist = () => {
|
|
9
|
+
var _a;
|
|
10
|
+
const projectConfig = getProjectConfig();
|
|
11
|
+
if (!projectConfig) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const directory = (_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory;
|
|
15
|
+
if (!directory) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
export var EDGE_ROUTINE_TYPE;
|
|
21
|
+
(function (EDGE_ROUTINE_TYPE) {
|
|
22
|
+
EDGE_ROUTINE_TYPE["ASSETS_ONLY"] = "assets_only";
|
|
23
|
+
EDGE_ROUTINE_TYPE["JS_ONLY"] = "js_only";
|
|
24
|
+
EDGE_ROUTINE_TYPE["JS_AND_ASSETS"] = "js_and_assets";
|
|
25
|
+
EDGE_ROUTINE_TYPE["NOT_EXIST"] = "not_exist";
|
|
26
|
+
})(EDGE_ROUTINE_TYPE || (EDGE_ROUTINE_TYPE = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Check if a path exists and is valid
|
|
29
|
+
* @param filePath - The path to check
|
|
30
|
+
* @param isDirectory - Whether the path should be a directory
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
const isValidPath = (filePath, isDirectory = false) => {
|
|
34
|
+
if (!filePath || typeof filePath !== 'string' || filePath.trim() === '') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const resolvedPath = path.isAbsolute(filePath)
|
|
39
|
+
? filePath
|
|
40
|
+
: path.resolve(filePath);
|
|
41
|
+
const exists = fs.existsSync(resolvedPath);
|
|
42
|
+
if (!exists) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (isDirectory) {
|
|
46
|
+
return fs.statSync(resolvedPath).isDirectory();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return fs.statSync(resolvedPath).isFile();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export const checkEdgeRoutineType = (scriptEntry, assetsDirectory, projectPath) => {
|
|
57
|
+
var _a;
|
|
58
|
+
const projectConfig = getProjectConfig(projectPath);
|
|
59
|
+
const entry = scriptEntry || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry);
|
|
60
|
+
const assets = assetsDirectory || ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
|
|
61
|
+
const entryPath = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', entry !== null && entry !== void 0 ? entry : '');
|
|
62
|
+
const assetsPath = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assets !== null && assets !== void 0 ? assets : '');
|
|
63
|
+
const hasAssets = isValidPath(assetsPath, true) && assets;
|
|
64
|
+
const hasEntry = isValidPath(entryPath, false) && entry;
|
|
65
|
+
// Both assets and entry exist
|
|
66
|
+
if (hasAssets && hasEntry) {
|
|
67
|
+
return EDGE_ROUTINE_TYPE.JS_AND_ASSETS;
|
|
68
|
+
}
|
|
69
|
+
// Only assets exist
|
|
70
|
+
if (hasAssets && !hasEntry) {
|
|
71
|
+
return EDGE_ROUTINE_TYPE.ASSETS_ONLY;
|
|
72
|
+
}
|
|
73
|
+
// Only entry exists
|
|
74
|
+
if (!hasAssets && hasEntry) {
|
|
75
|
+
return EDGE_ROUTINE_TYPE.JS_ONLY;
|
|
76
|
+
}
|
|
77
|
+
// Neither exists
|
|
78
|
+
return EDGE_ROUTINE_TYPE.NOT_EXIST;
|
|
79
|
+
};
|
|
80
|
+
export default checkConfigAssetsExist;
|
|
@@ -7,12 +7,11 @@ 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 SelectItems from '../components/selectInput.js';
|
|
10
|
+
import chalk from 'chalk';
|
|
12
11
|
import inquirer from 'inquirer';
|
|
13
|
-
import
|
|
12
|
+
import portscanner from 'portscanner';
|
|
14
13
|
import t from '../i18n/index.js';
|
|
15
|
-
import
|
|
14
|
+
import logger from '../libs/logger.js';
|
|
16
15
|
export const checkPort = (port) => {
|
|
17
16
|
return new Promise((resolve) => {
|
|
18
17
|
portscanner.checkPortStatus(port, '127.0.0.1', (error, status) => {
|
|
@@ -28,19 +27,6 @@ export const checkPort = (port) => {
|
|
|
28
27
|
});
|
|
29
28
|
});
|
|
30
29
|
};
|
|
31
|
-
const ask = () => {
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
SelectItems({
|
|
34
|
-
items: [
|
|
35
|
-
{ label: 'Yes', value: 'yes' },
|
|
36
|
-
{ label: 'No', value: 'no' }
|
|
37
|
-
],
|
|
38
|
-
handleSelect: (item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
resolve(item.value === 'yes');
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
30
|
const findAvailablePort = (startPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
31
|
return yield portscanner.findAPortNotInUse(startPort, 65535);
|
|
46
32
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { getProjectConfig } from './fileUtils/index.js';
|
|
3
|
+
export const checkEntryFileExist = () => {
|
|
4
|
+
const projectConfig = getProjectConfig();
|
|
5
|
+
const entry = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry;
|
|
6
|
+
if (!entry) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return fs.existsSync(entry);
|
|
10
|
+
};
|
|
@@ -7,16 +7,11 @@ 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 path from 'path';
|
|
11
|
-
import { createEdgeRoutine } from '../commands/commit/index.js';
|
|
12
|
-
import { displaySelectSpec } from '../commands/deploy/index.js';
|
|
13
|
-
import { ApiService } from '../libs/apiService.js';
|
|
14
|
-
import { readEdgeRoutineFile } from './fileUtils/index.js';
|
|
15
|
-
import logger from '../libs/logger.js';
|
|
16
|
-
import t from '../i18n/index.js';
|
|
17
|
-
import prodBuild from '../commands/commit/prodBuild.js';
|
|
18
10
|
import { exit } from 'process';
|
|
19
11
|
import chalk from 'chalk';
|
|
12
|
+
import t from '../i18n/index.js';
|
|
13
|
+
import { ApiService } from '../libs/apiService.js';
|
|
14
|
+
import logger from '../libs/logger.js';
|
|
20
15
|
export function isRoutineExist(name) {
|
|
21
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
17
|
const server = yield ApiService.getInstance();
|
|
@@ -34,38 +29,28 @@ export function validRoutine(name) {
|
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Ensure routine exists, if not, create a new routine
|
|
34
|
+
* @param name - Routine name
|
|
35
|
+
*/
|
|
36
|
+
export function ensureRoutineExists(name) {
|
|
38
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!
|
|
38
|
+
const isExist = yield isRoutineExist(name);
|
|
39
|
+
// If routine does not exist, create a new routine
|
|
40
|
+
if (!isExist) {
|
|
42
41
|
logger.log(t('first_deploy').d('This is the first time to deploy, we will create a new routine for you.'));
|
|
43
|
-
const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
|
|
44
|
-
yield prodBuild(false, entryFile, entry);
|
|
45
|
-
const code = readEdgeRoutineFile(entry) || '';
|
|
46
42
|
const server = yield ApiService.getInstance();
|
|
47
|
-
const
|
|
48
|
-
if (item.IsAvailable) {
|
|
49
|
-
acc.push(item.SpecName);
|
|
50
|
-
}
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
const spec = yield displaySelectSpec(specList);
|
|
54
|
-
console.log({
|
|
55
|
-
name: name,
|
|
56
|
-
specName: spec,
|
|
57
|
-
code: code
|
|
58
|
-
});
|
|
59
|
-
const res = yield createEdgeRoutine({
|
|
43
|
+
const createRes = yield server.createRoutine({
|
|
60
44
|
name: name,
|
|
61
|
-
|
|
62
|
-
code: code
|
|
45
|
+
description: ''
|
|
63
46
|
});
|
|
64
|
-
|
|
47
|
+
const isSuccess = (createRes === null || createRes === void 0 ? void 0 : createRes.data.Status) === 'OK';
|
|
48
|
+
if (isSuccess) {
|
|
65
49
|
logger.success(t('routine_create_success').d('Routine created successfully.'));
|
|
66
50
|
}
|
|
67
51
|
else {
|
|
68
52
|
logger.error(t('routine_create_fail').d('Routine created failed.'));
|
|
53
|
+
exit();
|
|
69
54
|
}
|
|
70
55
|
}
|
|
71
56
|
});
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { promises as fs } from 'fs';
|
|
11
|
-
import { getDirName } from '../utils/fileUtils/base.js';
|
|
12
11
|
import path from 'path';
|
|
12
|
+
import { getDirName } from '../utils/fileUtils/base.js';
|
|
13
13
|
export function handleCheckVersion() {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const __dirname = getDirName(import.meta.url);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Toml Example:
|
|
3
|
+
name = "DeepSeek model invocation"
|
|
4
|
+
description = 'How to invoke DeepSeek series models through API calls on the BaiLian platform.'
|
|
5
|
+
entry = "src/index.js"
|
|
6
|
+
assets = ["src/assets"]
|
|
7
|
+
codeVersions = [ ]
|
|
8
|
+
|
|
9
|
+
[assets]
|
|
10
|
+
directory = './assets/'
|
|
11
|
+
|
|
12
|
+
[dev]
|
|
13
|
+
port = 18080
|
|
14
|
+
localUpstream = ''
|
|
15
|
+
*/
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
import fs from 'fs';
|
|
26
|
+
import path from 'path';
|
|
27
|
+
import AdmZip from 'adm-zip';
|
|
28
|
+
import prodBuild from '../commands/commit/prodBuild.js';
|
|
29
|
+
import { checkEdgeRoutineType, EDGE_ROUTINE_TYPE } from './checkAssetsExist.js';
|
|
30
|
+
import { getProjectConfig, readEdgeRoutineFile } from './fileUtils/index.js';
|
|
31
|
+
const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [scriptEntry_1, assetsDir_1, ...args_1], void 0, function* (scriptEntry, assetsDir, minify = false, projectPath) {
|
|
32
|
+
var _a;
|
|
33
|
+
let code;
|
|
34
|
+
const zip = new AdmZip();
|
|
35
|
+
const projectConfig = getProjectConfig(projectPath);
|
|
36
|
+
const routineType = checkEdgeRoutineType(scriptEntry, assetsDir, projectPath);
|
|
37
|
+
if (!projectConfig) {
|
|
38
|
+
throw new Error('Project config not found');
|
|
39
|
+
}
|
|
40
|
+
// 参数优先:如果有参数则使用参数,否则使用配置文件中的值
|
|
41
|
+
const entry = scriptEntry || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry);
|
|
42
|
+
let assetsDirectory = assetsDir || ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
|
|
43
|
+
if (routineType === EDGE_ROUTINE_TYPE.NOT_EXIST) {
|
|
44
|
+
throw new Error('Entry file not found in project config');
|
|
45
|
+
}
|
|
46
|
+
if (routineType === EDGE_ROUTINE_TYPE.JS_ONLY ||
|
|
47
|
+
routineType === EDGE_ROUTINE_TYPE.JS_AND_ASSETS) {
|
|
48
|
+
const buildEntry = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', entry !== null && entry !== void 0 ? entry : '');
|
|
49
|
+
yield prodBuild(minify, buildEntry, projectPath);
|
|
50
|
+
code = readEdgeRoutineFile(projectPath);
|
|
51
|
+
zip.addFile(`routine/index.js`, Buffer.from(code || ''));
|
|
52
|
+
}
|
|
53
|
+
assetsDirectory = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assetsDirectory !== null && assetsDirectory !== void 0 ? assetsDirectory : '');
|
|
54
|
+
// Add all files in the assets directory to the /assets directory
|
|
55
|
+
if ((routineType === EDGE_ROUTINE_TYPE.JS_AND_ASSETS ||
|
|
56
|
+
routineType === EDGE_ROUTINE_TYPE.ASSETS_ONLY) &&
|
|
57
|
+
assetsDirectory &&
|
|
58
|
+
fs.existsSync(assetsDirectory)) {
|
|
59
|
+
const addDirectoryToZip = (dirPath, zipPath) => {
|
|
60
|
+
const files = fs.readdirSync(dirPath);
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const fullPath = path.join(dirPath, file);
|
|
63
|
+
const stat = fs.statSync(fullPath);
|
|
64
|
+
if (stat.isDirectory()) {
|
|
65
|
+
addDirectoryToZip(fullPath, path.join(zipPath, file));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const fileContent = fs.readFileSync(fullPath);
|
|
69
|
+
const relativePath = path.relative(assetsDirectory, fullPath);
|
|
70
|
+
zip.addFile(`assets/${relativePath}`, fileContent);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
addDirectoryToZip(assetsDirectory, 'assets');
|
|
75
|
+
}
|
|
76
|
+
//输出zip
|
|
77
|
+
zip.writeZip('testassets.zip');
|
|
78
|
+
return zip;
|
|
79
|
+
});
|
|
80
|
+
export default compress;
|
package/dist/utils/download.js
CHANGED
|
@@ -7,16 +7,16 @@ 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
|
|
10
|
+
import { exec } from 'child_process';
|
|
11
11
|
import * as fs from 'fs/promises';
|
|
12
|
-
import * as path from 'path';
|
|
13
12
|
import os from 'os';
|
|
14
|
-
import
|
|
15
|
-
import { exec } from 'child_process';
|
|
13
|
+
import * as path from 'path';
|
|
16
14
|
import { promisify } from 'util';
|
|
15
|
+
import AdmZip from 'adm-zip';
|
|
16
|
+
import chalk from 'chalk';
|
|
17
|
+
import fetch from 'node-fetch';
|
|
17
18
|
import t from '../i18n/index.js';
|
|
18
19
|
import logger from '../libs/logger.js';
|
|
19
|
-
import chalk from 'chalk';
|
|
20
20
|
const execAsync = promisify(exec);
|
|
21
21
|
function getBinDir() {
|
|
22
22
|
const home = os.homedir();
|
package/dist/utils/fileMd5.js
CHANGED
|
@@ -7,14 +7,13 @@ 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';
|
|
10
|
+
import fs, { promises as fsPromises } from 'fs';
|
|
11
11
|
import os from 'os';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import toml from '@iarna/toml';
|
|
14
|
-
import { promises as fsPromises } from 'fs';
|
|
15
|
-
import { getDirName, getRoot } from './base.js';
|
|
16
|
-
import logger from '../../libs/logger.js';
|
|
17
14
|
import t from '../../i18n/index.js';
|
|
15
|
+
import logger from '../../libs/logger.js';
|
|
16
|
+
import { getDirName, getRoot } from './base.js';
|
|
18
17
|
const projectConfigFile = 'esa.toml';
|
|
19
18
|
const __dirname = getDirName(import.meta.url);
|
|
20
19
|
const root = getRoot();
|
|
@@ -76,11 +75,20 @@ export function readConfigFile(configPath) {
|
|
|
76
75
|
if (fs.existsSync(configPath)) {
|
|
77
76
|
const configFileContent = fs.readFileSync(configPath, 'utf-8');
|
|
78
77
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
|
|
79
|
+
// Remove comments for JSON parsing
|
|
80
|
+
const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
|
|
81
|
+
const config = JSON.parse(jsonContent);
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// TOML format
|
|
86
|
+
const config = toml.parse(configFileContent);
|
|
87
|
+
return config;
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
catch (error) {
|
|
83
|
-
logger.error(`Error parsing
|
|
91
|
+
logger.error(`Error parsing config file: ${error}`);
|
|
84
92
|
return null;
|
|
85
93
|
}
|
|
86
94
|
}
|
|
@@ -94,11 +102,16 @@ export function getCliConfig() {
|
|
|
94
102
|
return res;
|
|
95
103
|
}
|
|
96
104
|
export function getProjectConfig(filePath = root) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
// Try to find config file in order of preference: .jsonc, .toml
|
|
106
|
+
const configFormats = ['esa.jsonc', 'esa.toml'];
|
|
107
|
+
for (const format of configFormats) {
|
|
108
|
+
const configPath = path.join(filePath, format);
|
|
109
|
+
const config = readConfigFile(configPath);
|
|
110
|
+
if (config) {
|
|
111
|
+
return config;
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
|
-
return
|
|
114
|
+
return null;
|
|
102
115
|
}
|
|
103
116
|
export function readEdgeRoutineFile(projectPath = root) {
|
|
104
117
|
const projectConfig = getProjectConfig(projectPath);
|
|
@@ -122,26 +135,62 @@ export function getConfigurations() {
|
|
|
122
135
|
return [null, null];
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
|
-
export function generateConfigFile(
|
|
126
|
-
return __awaiter(this,
|
|
127
|
-
var _a;
|
|
128
|
-
const
|
|
129
|
-
const currentDirName = path.basename(
|
|
130
|
-
const entry = (
|
|
138
|
+
export function generateConfigFile(projectName_1, initConfigs_1, targetDir_1) {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* (projectName, initConfigs, targetDir, configFormat = 'toml', isSinglePageApplication = false) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const outputDir = targetDir !== null && targetDir !== void 0 ? targetDir : process.cwd();
|
|
142
|
+
const currentDirName = path.basename(outputDir);
|
|
143
|
+
const entry = (_a = initConfigs === null || initConfigs === void 0 ? void 0 : initConfigs.dev) === null || _a === void 0 ? void 0 : _a.entry;
|
|
131
144
|
const port = (initConfigs === null || initConfigs === void 0 ? void 0 : initConfigs.port) || 18080;
|
|
132
145
|
const name = projectName || currentDirName;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
const assetsDirectory = (_b = initConfigs === null || initConfigs === void 0 ? void 0 : initConfigs.assets) === null || _b === void 0 ? void 0 : _b.directory;
|
|
147
|
+
let newFilePath;
|
|
148
|
+
let genConfig;
|
|
149
|
+
if (configFormat === 'jsonc') {
|
|
150
|
+
newFilePath = path.join(outputDir, 'esa.jsonc');
|
|
151
|
+
const assetsBlock = assetsDirectory
|
|
152
|
+
? `,
|
|
153
|
+
"assets": {
|
|
154
|
+
"directory": "${assetsDirectory}"
|
|
155
|
+
${isSinglePageApplication
|
|
156
|
+
? `,
|
|
157
|
+
"notFoundStrategy": "singlePageApplication"`
|
|
158
|
+
: ''}
|
|
159
|
+
}`
|
|
160
|
+
: '';
|
|
161
|
+
const entryBlock = entry
|
|
162
|
+
? `,
|
|
163
|
+
"entry": "${entry}"`
|
|
164
|
+
: '';
|
|
165
|
+
genConfig = `{
|
|
166
|
+
"name": "${name}"${entryBlock}${assetsBlock},
|
|
167
|
+
"dev": {
|
|
168
|
+
"port": ${port}
|
|
169
|
+
}
|
|
170
|
+
}`;
|
|
136
171
|
}
|
|
137
172
|
else {
|
|
138
|
-
|
|
173
|
+
// Default to TOML format
|
|
174
|
+
newFilePath = path.join(outputDir, 'esa.toml');
|
|
175
|
+
const assetsBlock = assetsDirectory
|
|
176
|
+
? `
|
|
177
|
+
[assets]
|
|
178
|
+
directory = "${assetsDirectory}"
|
|
179
|
+
`
|
|
180
|
+
: '';
|
|
181
|
+
genConfig = `name = "${name}"
|
|
139
182
|
entry = "${entry}"
|
|
183
|
+
${assetsBlock}${isSinglePageApplication ? 'notFoundStrategy = "singlePageApplication"' : ''}
|
|
140
184
|
[dev]
|
|
141
185
|
port = ${port}
|
|
142
186
|
`;
|
|
187
|
+
}
|
|
188
|
+
if (fs.existsSync(newFilePath)) {
|
|
189
|
+
logger.error(t('generate_config_error').d(`${path.basename(newFilePath)} already exists`));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
143
193
|
yield fsPromises.writeFile(newFilePath, genConfig, 'utf-8');
|
|
144
|
-
logger.success(t('generate_config_success').d('Generated esa.toml'));
|
|
145
194
|
}
|
|
146
195
|
});
|
|
147
196
|
}
|
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { exec, execSync } from 'child_process';
|
|
11
11
|
import os from 'os';
|
|
12
12
|
import path from 'path';
|
|
13
|
+
import t from '../i18n/index.js';
|
|
13
14
|
import logger from '../libs/logger.js';
|
|
14
|
-
import { getDirName } from './fileUtils/base.js';
|
|
15
15
|
import { downloadRuntimeAndUnzipForWindows } from './download.js';
|
|
16
|
-
import
|
|
16
|
+
import { getDirName } from './fileUtils/base.js';
|
|
17
17
|
export function preCheckDeno() {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const command = yield checkDenoInstalled();
|
|
@@ -45,7 +45,7 @@ export function checkDenoInstalled() {
|
|
|
45
45
|
.then((res) => {
|
|
46
46
|
resolve(res);
|
|
47
47
|
})
|
|
48
|
-
.catch((
|
|
48
|
+
.catch(() => {
|
|
49
49
|
resolve(false);
|
|
50
50
|
});
|
|
51
51
|
});
|
package/dist/utils/installEw2.js
CHANGED
|
@@ -7,17 +7,17 @@ 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 { execSync } from 'child_process';
|
|
11
|
+
import https from 'https';
|
|
10
12
|
import os from 'os';
|
|
11
|
-
import fs from 'fs-extra';
|
|
12
13
|
import path from 'path';
|
|
13
14
|
import util from 'util';
|
|
14
|
-
import
|
|
15
|
-
import { execSync } from 'child_process';
|
|
16
|
-
import logger from '../libs/logger.js';
|
|
17
|
-
import { getDirName } from './fileUtils/base.js';
|
|
15
|
+
import fs from 'fs-extra';
|
|
18
16
|
import t from '../i18n/index.js';
|
|
19
|
-
import
|
|
17
|
+
import logger from '../libs/logger.js';
|
|
20
18
|
import { checkOS } from './checkOS.js';
|
|
19
|
+
import { calculateFileMD5 } from './fileMd5.js';
|
|
20
|
+
import { getDirName } from './fileUtils/base.js';
|
|
21
21
|
export const EW2DirName = '.ew2';
|
|
22
22
|
export const EW2BinName = 'edgeworker2';
|
|
23
23
|
export const EW2Path = path.join(os.homedir(), EW2DirName);
|
|
@@ -79,7 +79,7 @@ export function fetchRemoteManifest() {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
})
|
|
82
|
-
.on('error', (
|
|
82
|
+
.on('error', () => reject);
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
export function checkManifest() {
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import open from 'open';
|
|
11
|
-
import logger from '../libs/logger.js';
|
|
12
11
|
import t from '../i18n/index.js';
|
|
12
|
+
import logger from '../libs/logger.js';
|
|
13
13
|
/**
|
|
14
14
|
* Open url in browser
|
|
15
15
|
* @param {string} url
|
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.13",
|
|
4
4
|
"description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
|
|
5
5
|
"main": "bin/enter.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"watch": "tsc --watch",
|
|
19
19
|
"eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
20
20
|
"lint-staged": "lint-staged",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
21
|
+
"test": "vitest --coverage",
|
|
22
|
+
"coverage": "vitest --coverage",
|
|
23
|
+
"lint": "eslint src/",
|
|
24
|
+
"lint:fix": "eslint src/ --fix"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
26
27
|
"cli",
|
|
@@ -50,9 +51,13 @@
|
|
|
50
51
|
"@types/portscanner": "^2.1.4",
|
|
51
52
|
"@types/react": "^18.2.47",
|
|
52
53
|
"@types/yargs": "^17.0.32",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
53
55
|
"@typescript-eslint/parser": "^6.9.1",
|
|
54
56
|
"eslint": "^8.52.0",
|
|
55
57
|
"eslint-config-prettier": "^9.0.0",
|
|
58
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
59
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
60
|
+
"eslint-plugin-import": "^2.32.0",
|
|
56
61
|
"eslint-plugin-react": "^7.33.2",
|
|
57
62
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
58
63
|
"husky": "^8.0.3",
|
|
@@ -67,7 +72,7 @@
|
|
|
67
72
|
"vitest": "^2.0.4"
|
|
68
73
|
},
|
|
69
74
|
"dependencies": {
|
|
70
|
-
"@alicloud/esa20240910": "2.
|
|
75
|
+
"@alicloud/esa20240910": "2.25.0",
|
|
71
76
|
"@alicloud/openapi-client": "^0.4.7",
|
|
72
77
|
"@babel/generator": "^7.26.3",
|
|
73
78
|
"@babel/parser": "^7.24.4",
|
|
@@ -80,7 +85,7 @@
|
|
|
80
85
|
"chokidar": "^3.5.3",
|
|
81
86
|
"cli-table3": "^0.6.5",
|
|
82
87
|
"cross-spawn": "^7.0.3",
|
|
83
|
-
"esa-template": "^0.0.
|
|
88
|
+
"esa-template": "^0.0.7",
|
|
84
89
|
"esbuild": "^0.21.1",
|
|
85
90
|
"esbuild-plugin-less": "^1.3.8",
|
|
86
91
|
"form-data": "^4.0.0",
|