esa-cli 0.0.2-beta.15 → 0.0.2-beta.18

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.
@@ -36,12 +36,15 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
36
36
  var _a;
37
37
  let code;
38
38
  const zip = new AdmZip();
39
+ const fileList = [];
40
+ const sourceList = [];
41
+ const dynamicSources = [];
39
42
  const projectConfig = getProjectConfig(projectPath);
40
43
  let assetsDirectory = assetsDir || ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
41
- assetsDirectory = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assetsDirectory !== null && assetsDirectory !== void 0 ? assetsDirectory : '');
42
44
  const routineType = checkEdgeRoutineType(scriptEntry, assetsDir, projectPath);
43
- if (!projectConfig) {
44
- throw new Error('Project config not found');
45
+ if (!projectConfig && !scriptEntry && !assetsDir) {
46
+ logger.error('esa.jsonc or esa.toml is not found and script entry or assets directory is not provided by command line');
47
+ exit(0);
45
48
  }
46
49
  // 参数优先:如果有参数则使用参数,否则使用配置文件中的值
47
50
  const entry = scriptEntry || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry);
@@ -50,11 +53,10 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
50
53
  chalk.red.bold('❌ File upload failed'),
51
54
  '',
52
55
  chalk.cyan('📋 Current configuration information:'),
53
- `${chalk.white(' 📁 Project path:')} ${chalk.yellow(projectPath || chalk.gray(t('compress_not_specified').d('Not specified')))}`,
54
- `${chalk.white(' 📄 Entry file:')} ${chalk.yellow(scriptEntry ||
56
+ `${chalk.white(` 📄 Entry file ${chalk.yellow('(dynamic)')} :`)} ${chalk.yellow(scriptEntry ||
55
57
  (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry) ||
56
58
  chalk.gray(t('compress_not_configured').d('Not configured')))}`,
57
- `${chalk.white(' 🗂️ Assets directory:')} ${chalk.yellow(assetsDirectory || chalk.gray(t('compress_not_configured').d('Not configured')))}`,
59
+ `${chalk.white(` 🗂️ Assets directory ${chalk.yellow('(static)')} :`)} ${chalk.yellow(assetsDirectory || chalk.gray(t('compress_not_configured').d('Not configured')))}`,
58
60
  '',
59
61
  chalk.cyan('🔍 Possible issue causes:'),
60
62
  chalk.white(' 1. Entry file path is incorrect or file does not exist'),
@@ -70,7 +72,7 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
70
72
  : []),
71
73
  ...(assetsDirectory
72
74
  ? [
73
- `${chalk.white(' 🗂️ Assets directory:')} ${chalk.cyan.bold(path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assetsDirectory))} ${chalk.gray(t('compress_check_directory_exists').d('(Check if directory exists)'))}`
75
+ `${chalk.white(' 🗂️ Assets directory:')} ${chalk.cyan.bold(path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assetsDirectory))} ${chalk.gray(t('compress_check_directory_exists').d('(Check if directory exists)'))}`
74
76
  ]
75
77
  : []),
76
78
  ...(!scriptEntry && !(projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry) && !assetsDirectory
@@ -89,6 +91,13 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
89
91
  yield prodBuild(minify, buildEntry, projectPath);
90
92
  code = readEdgeRoutineFile(projectPath);
91
93
  zip.addFile(`routine/index.js`, Buffer.from(code || ''));
94
+ fileList.push('routine/index.js');
95
+ const relativeEntry = path
96
+ .relative(projectPath !== null && projectPath !== void 0 ? projectPath : '', buildEntry)
97
+ .split(path.sep)
98
+ .join('/');
99
+ sourceList.push(relativeEntry);
100
+ dynamicSources.push(relativeEntry);
92
101
  }
93
102
  assetsDirectory = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assetsDirectory !== null && assetsDirectory !== void 0 ? assetsDirectory : '');
94
103
  // Add all files in the assets directory to the /assets directory
@@ -106,13 +115,22 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
106
115
  }
107
116
  else {
108
117
  const fileContent = fs.readFileSync(fullPath);
109
- const relativePath = path.relative(assetsDirectory, fullPath);
118
+ const relativePath = path
119
+ .relative(assetsDirectory, fullPath)
120
+ .split(path.sep)
121
+ .join('/');
110
122
  zip.addFile(`assets/${relativePath}`, fileContent);
123
+ fileList.push(`assets/${relativePath}`);
124
+ const relativeSrcPath = path
125
+ .relative(projectPath !== null && projectPath !== void 0 ? projectPath : '', fullPath)
126
+ .split(path.sep)
127
+ .join('/');
128
+ sourceList.push(relativeSrcPath);
111
129
  }
112
130
  }
113
131
  };
114
132
  addDirectoryToZip(assetsDirectory, 'assets');
115
133
  }
116
- return zip;
134
+ return { zip, fileList, sourceList, dynamicSources };
117
135
  });
118
136
  export default compress;
@@ -19,6 +19,17 @@ const __dirname = getDirName(import.meta.url);
19
19
  const root = getRoot();
20
20
  export const projectConfigPath = path.join(root, projectConfigFile);
21
21
  export const cliConfigPath = path.join(os.homedir(), '.esa/config/default.toml');
22
+ // Function to get the actual config file path (supports both .toml and .jsonc)
23
+ export const getCliConfigPath = () => {
24
+ const configDir = path.join(os.homedir(), '.esa/config');
25
+ const jsoncPath = path.join(configDir, 'default.jsonc');
26
+ const tomlPath = path.join(configDir, 'default.toml');
27
+ // Check if JSONC file exists first, then fallback to TOML
28
+ if (fs.existsSync(jsoncPath)) {
29
+ return jsoncPath;
30
+ }
31
+ return tomlPath;
32
+ };
22
33
  export const hiddenConfigDir = path.join(os.homedir(), '.esa/config');
23
34
  export const generateHiddenConfigDir = () => {
24
35
  if (!fs.existsSync(hiddenConfigDir)) {
@@ -37,7 +48,8 @@ export const generateToml = (path) => {
37
48
  };
38
49
  export const generateDefaultConfig = () => {
39
50
  generateHiddenConfigDir();
40
- generateToml(cliConfigPath);
51
+ const configPath = getCliConfigPath();
52
+ generateToml(configPath);
41
53
  };
42
54
  export function updateProjectConfigFile(configUpdate_1) {
43
55
  return __awaiter(this, arguments, void 0, function* (configUpdate, filePath = root) {
@@ -58,16 +70,30 @@ export function updateProjectConfigFile(configUpdate_1) {
58
70
  export function updateCliConfigFile(configUpdate) {
59
71
  return __awaiter(this, void 0, void 0, function* () {
60
72
  try {
61
- let configFileContent = yield fsPromises.readFile(cliConfigPath, 'utf8');
62
- let config = toml.parse(configFileContent);
63
- config = Object.assign(Object.assign({}, config), configUpdate);
64
- const updatedConfigString = toml.stringify(config);
65
- yield fsPromises.writeFile(cliConfigPath, updatedConfigString);
73
+ const configPath = getCliConfigPath();
74
+ let configFileContent = yield fsPromises.readFile(configPath, 'utf8');
75
+ let config;
76
+ let updatedConfigString;
77
+ // Detect file format based on file extension
78
+ if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
79
+ // Handle JSONC format
80
+ const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
81
+ config = JSON.parse(jsonContent);
82
+ config = Object.assign(Object.assign({}, config), configUpdate);
83
+ updatedConfigString = JSON.stringify(config, null, 2) + '\n';
84
+ }
85
+ else {
86
+ // Handle TOML format (default)
87
+ config = toml.parse(configFileContent);
88
+ config = Object.assign(Object.assign({}, config), configUpdate);
89
+ updatedConfigString = toml.stringify(config);
90
+ }
91
+ yield fsPromises.writeFile(configPath, updatedConfigString);
66
92
  }
67
93
  catch (error) {
68
- logger.error(`Error updating TOML file: ${error}`);
94
+ logger.error(`Error updating config file: ${error}`);
69
95
  logger.pathEacces(__dirname);
70
- throw new Error('Login error');
96
+ throw new Error('Config update error');
71
97
  }
72
98
  });
73
99
  }
@@ -96,7 +122,8 @@ export function readConfigFile(configPath) {
96
122
  return null;
97
123
  }
98
124
  export function getCliConfig() {
99
- const res = readConfigFile(cliConfigPath);
125
+ const configPath = getCliConfigPath();
126
+ const res = readConfigFile(configPath);
100
127
  if (!res) {
101
128
  return null;
102
129
  }
@@ -115,10 +142,6 @@ export function getProjectConfig(filePath = root) {
115
142
  return null;
116
143
  }
117
144
  export function readEdgeRoutineFile(projectPath = root) {
118
- const projectConfig = getProjectConfig(projectPath);
119
- if (!projectConfig) {
120
- return null;
121
- }
122
145
  const pubFilePath = `.dev/pub.js`;
123
146
  const edgeRoutinePath = path.join(projectPath, pubFilePath);
124
147
  if (fs.existsSync(edgeRoutinePath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "0.0.2-beta.15",
3
+ "version": "0.0.2-beta.18",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
@@ -15,8 +15,9 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "rm -rf ./dist && rm -rf ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
18
- "watch": "tsc --watch",
18
+ "dev": "tsc --watch",
19
19
  "eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
20
+ "prepare": "husky install",
20
21
  "lint-staged": "lint-staged",
21
22
  "test": "vitest --coverage",
22
23
  "coverage": "vitest --coverage",
@@ -53,13 +54,6 @@
53
54
  "@types/yargs": "^17.0.32",
54
55
  "@typescript-eslint/eslint-plugin": "^6.21.0",
55
56
  "@typescript-eslint/parser": "^6.9.1",
56
- "eslint": "^8.52.0",
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",
61
- "eslint-plugin-react": "^7.33.2",
62
- "eslint-plugin-react-hooks": "^4.6.0",
63
57
  "husky": "^8.0.3",
64
58
  "jsdom": "^25.0.1",
65
59
  "lint-staged": "^15.0.2",
@@ -72,12 +66,12 @@
72
66
  "vitest": "^2.0.4"
73
67
  },
74
68
  "dependencies": {
75
- "@clack/prompts": "1.0.0-alpha.4",
76
69
  "@alicloud/esa20240910": "2.25.0",
77
70
  "@alicloud/openapi-client": "^0.4.7",
78
71
  "@babel/generator": "^7.26.3",
79
72
  "@babel/parser": "^7.24.4",
80
73
  "@babel/traverse": "^7.24.1",
74
+ "@clack/prompts": "1.0.0-alpha.4",
81
75
  "@iarna/toml": "^2.2.5",
82
76
  "@types/inquirer": "^9.0.7",
83
77
  "@vitest/coverage-istanbul": "^2.0.4",
@@ -86,7 +80,7 @@
86
80
  "chokidar": "^3.5.3",
87
81
  "cli-table3": "^0.6.5",
88
82
  "cross-spawn": "^7.0.3",
89
- "esa-template": "^0.0.7",
83
+ "esa-template": "0.0.9",
90
84
  "esbuild": "^0.21.1",
91
85
  "esbuild-plugin-less": "^1.3.8",
92
86
  "form-data": "^4.0.0",
@@ -108,6 +102,11 @@
108
102
  "winston-daily-rotate-file": "^5.0.0",
109
103
  "yargs": "^17.7.2"
110
104
  },
105
+ "lint-staged": {
106
+ "src/**/*.{ts,tsx,js,jsx}": [
107
+ "eslint --fix"
108
+ ]
109
+ },
111
110
  "repository": {
112
111
  "type": "git",
113
112
  "url": "git+ssh://git@github.com/aliyun/alibabacloud-esa-cli.git"