esa-cli 0.0.2-beta.16 → 0.0.2-beta.19

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.
@@ -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.16",
3
+ "version": "0.0.2-beta.19",
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"