cloudcc-cli 1.7.4 → 1.7.5
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/README.md +12 -0
- package/package.json +2 -2
- package/src/classes/create.js +3 -1
- package/src/classes/publish.js +7 -5
- package/src/object/get.js +1 -1
- package/src/plugin/create1.js +12 -20
- package/src/plugin/publish1.js +93 -42
- package/src/plugin/readme.md +7 -0
- package/src/script/publish.js +4 -15
- package/src/timer/create.js +3 -1
- package/src/timer/publish.js +8 -4
- package/src/triggers/create.js +3 -1
- package/src/triggers/publish.js +8 -4
- package/template/gitignore +7 -4
- package/utils/cache.js +31 -0
- package/utils/checkVersion.js +20 -3
- package/utils/utils.js +58 -5
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# ReleaseV1.7.5
|
|
2
|
+
#### 发布日期:2025-1-13
|
|
3
|
+
#### 发布范围:全量
|
|
4
|
+
#### 发布内容
|
|
5
|
+
* 优化
|
|
6
|
+
* 调整查到data逻辑。
|
|
7
|
+
* 调整创建组件和发布组件获取配置信息的逻辑。
|
|
8
|
+
* 调整setup服务前缀名称。
|
|
9
|
+
* 增加token缓存策略。
|
|
10
|
+
* 调整忽略文件。
|
|
11
|
+
* 自定义类/timer/triggers添加源码标识:// @SOURCE_CONTENT_START // @SOURCE_CONTENT_END
|
|
12
|
+
|
|
1
13
|
# ReleaseV1.7.4
|
|
2
14
|
#### 发布日期:2025-1-7
|
|
3
15
|
#### 发布范围:全量
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcc-cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "cloudcc-cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudcc",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"cc-pull": "git fetch --tags -f && git pull",
|
|
19
|
-
"publish-lib": "npm --proxy http://127.0.0.1:33210/ publish --registry https://registry.npmjs.org && curl https://npmmirror.com/sync/cloudcc-cli"
|
|
19
|
+
"publish-lib": "npm --proxy http://127.0.0.1:33210/ publish --registry https://registry.npmjs.org && git add . && git commit -m '发布新版' && git push && curl https://npmmirror.com/sync/cloudcc-cli"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"axios": "^0.21.4",
|
package/src/classes/create.js
CHANGED
|
@@ -10,7 +10,8 @@ async function create(name) {
|
|
|
10
10
|
try {
|
|
11
11
|
fs.mkdirSync(classesPath, { recursive: true })
|
|
12
12
|
const javaTmp =
|
|
13
|
-
|
|
13
|
+
`// @SOURCE_CONTENT_START
|
|
14
|
+
public class ${name}{
|
|
14
15
|
private UserInfo userInfo;
|
|
15
16
|
|
|
16
17
|
public ${name}(UserInfo userInfo){
|
|
@@ -23,6 +24,7 @@ async function create(name) {
|
|
|
23
24
|
return str;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
// @SOURCE_CONTENT_END
|
|
26
28
|
`
|
|
27
29
|
fs.writeFileSync(path.join(classesPath, name + ".java"), javaTmp)
|
|
28
30
|
fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"3"}`)
|
package/src/classes/publish.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
2
|
const fs = require("fs");
|
|
4
3
|
const path = require("path")
|
|
@@ -14,22 +13,25 @@ async function publish(name) {
|
|
|
14
13
|
console.log(chalk.green('Posting, please wait...'));
|
|
15
14
|
console.log();
|
|
16
15
|
const classPath = path.join(process.cwd(), `classes/${name}/`);
|
|
17
|
-
let
|
|
16
|
+
let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
|
|
17
|
+
|
|
18
|
+
const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
|
|
19
|
+
let classContent = sourceMatch ? sourceMatch[1] : fullContent;
|
|
18
20
|
let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
|
|
19
|
-
|
|
21
|
+
|
|
20
22
|
if (await getBusToken()) {
|
|
21
23
|
let body = {
|
|
22
24
|
"id": configContent.id,
|
|
23
25
|
"name": name,
|
|
24
|
-
"version": configContent.version,
|
|
25
26
|
"source": encodeURI(classContent),
|
|
27
|
+
"version": configContent.version,
|
|
26
28
|
"folderId": "wgd"
|
|
27
29
|
}
|
|
28
30
|
let res = await postNormal(global.setupSvc + "/api/ccfag/save", body)
|
|
29
31
|
if (res.result) {
|
|
30
32
|
console.log(chalk.green('Success!'));
|
|
31
33
|
console.log();
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
if (!configContent.id) {
|
|
34
36
|
configContent.id = res.data
|
|
35
37
|
fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
|
package/src/object/get.js
CHANGED
package/src/plugin/create1.js
CHANGED
|
@@ -8,33 +8,25 @@ const chalk = require("chalk")
|
|
|
8
8
|
|
|
9
9
|
async function create(name) {
|
|
10
10
|
const temp = `<template>
|
|
11
|
-
<div class="cc-container">
|
|
12
|
-
|
|
13
|
-
</div>
|
|
11
|
+
<div class="cc-container">
|
|
12
|
+
<div>{{ CloudCC }}</div>
|
|
13
|
+
</div>
|
|
14
14
|
</template>
|
|
15
15
|
|
|
16
16
|
<script>
|
|
17
17
|
export default {
|
|
18
|
-
data() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
compName: "${name}",
|
|
25
|
-
|
|
26
|
-
compDesc: "Component description information",
|
|
27
|
-
},
|
|
28
|
-
isLock: false,
|
|
29
|
-
};
|
|
30
|
-
},
|
|
18
|
+
data() {
|
|
19
|
+
return {
|
|
20
|
+
CloudCC: "Hello CloudCC",
|
|
21
|
+
};
|
|
22
|
+
},
|
|
31
23
|
};
|
|
32
24
|
</script>
|
|
33
25
|
<style lang="scss" scoped>
|
|
34
26
|
.cc-container {
|
|
35
|
-
text-align: center;
|
|
36
|
-
padding: 8px;
|
|
37
|
-
background: goldenrod;
|
|
27
|
+
text-align: center;
|
|
28
|
+
padding: 8px;
|
|
29
|
+
background: goldenrod;
|
|
38
30
|
}
|
|
39
31
|
</style>`
|
|
40
32
|
let res = await checkUpdate();
|
|
@@ -44,7 +36,7 @@ background: goldenrod;
|
|
|
44
36
|
try {
|
|
45
37
|
fs.mkdirSync(pluginPath, { recursive: true })
|
|
46
38
|
fs.writeFileSync(path.join(pluginPath, name + ".vue"), temp)
|
|
47
|
-
fs.writeFileSync(path.join(pluginPath, "config.json"), `{"name":"${name}"}`)
|
|
39
|
+
fs.writeFileSync(path.join(pluginPath, "config.json"), `{"component":"${name}","compName":"${name}","compDesc":"Description"}`)
|
|
48
40
|
console.log()
|
|
49
41
|
console.log(chalk.green("Successfully Created:" + name))
|
|
50
42
|
console.log()
|
package/src/plugin/publish1.js
CHANGED
|
@@ -3,7 +3,7 @@ const { post } = require('../../utils/http');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require("path")
|
|
5
5
|
const chalk = require("chalk")
|
|
6
|
-
const
|
|
6
|
+
const { readCache, writeCache } = require("../../utils/cache") // 添加缓存模块引入
|
|
7
7
|
|
|
8
8
|
const { checkUpdate } = require("../../utils/checkVersion")
|
|
9
9
|
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
@@ -13,9 +13,11 @@ const { getPackageJson } = require("../../utils/config.js")
|
|
|
13
13
|
class Builder {
|
|
14
14
|
constructor() {
|
|
15
15
|
this.options = {
|
|
16
|
-
|
|
17
16
|
devConsoleConfig: {
|
|
18
17
|
},
|
|
18
|
+
pluginConfig: {
|
|
19
|
+
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
this.plugin = process.argv.splice(2)[0]
|
|
21
23
|
}
|
|
@@ -23,33 +25,57 @@ class Builder {
|
|
|
23
25
|
let res = await checkUpdate();
|
|
24
26
|
if (!res) {
|
|
25
27
|
this.options.devConsoleConfig = getPackageJson();
|
|
28
|
+
this.options.pluginConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), `plugins/${name}/config.json`), 'utf8'));
|
|
26
29
|
let config = this.options.devConsoleConfig
|
|
27
|
-
|
|
28
|
-
if ("private" != this.options.devConsoleConfig.version) {
|
|
30
|
+
|
|
31
|
+
if ("private" != this.options.devConsoleConfig.version) {
|
|
29
32
|
config = { "accessToken": await this.getToken(config) };
|
|
30
33
|
}
|
|
31
|
-
|
|
34
|
+
|
|
32
35
|
let answers = { buildFileName: `${name}/${name}.vue` }
|
|
33
|
-
|
|
36
|
+
|
|
34
37
|
if ("*.vue" == answers.buildFileName) {
|
|
35
38
|
let dirs = fs.readdirSync("plugins")
|
|
36
39
|
for (let i = 0; i < dirs.length; i++) {
|
|
37
40
|
let item = dirs[i]
|
|
38
41
|
let obj = this.getVueValue(item);
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
if (obj) {
|
|
43
|
+
this.initPluginFile(item, obj.component, "plginTemp" + i);
|
|
44
|
+
this.build(obj, config, "plginTemp" + i)
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
} else {
|
|
43
48
|
let obj = this.getVueValue(answers.buildFileName);
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
if (obj) {
|
|
50
|
+
this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
|
|
51
|
+
this.build(obj, config, "plginTemp")
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
|
-
|
|
56
|
+
|
|
50
57
|
async getToken(devConsoleConfig) {
|
|
58
|
+
const cache = readCache();
|
|
59
|
+
const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`; // 使用orgId确保唯一性
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const oneHour = 60 * 60 * 1000;
|
|
62
|
+
|
|
63
|
+
// 检查缓存是否有效
|
|
64
|
+
if (cache[cacheKey] &&
|
|
65
|
+
cache[cacheKey].token &&
|
|
66
|
+
cache[cacheKey].timestamp &&
|
|
67
|
+
(now - cache[cacheKey].timestamp) < oneHour) {
|
|
68
|
+
return cache[cacheKey].token;
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
|
|
52
72
|
if (res.returnCode == 200) {
|
|
73
|
+
// 更新缓存
|
|
74
|
+
cache[cacheKey] = {
|
|
75
|
+
token: res.data.accessToken,
|
|
76
|
+
timestamp: now
|
|
77
|
+
};
|
|
78
|
+
writeCache(cache);
|
|
53
79
|
return res.data.accessToken;
|
|
54
80
|
} else {
|
|
55
81
|
console.error(chalk.red(`Login failed`, JSON.stringify(res)));
|
|
@@ -57,35 +83,43 @@ class Builder {
|
|
|
57
83
|
}
|
|
58
84
|
}
|
|
59
85
|
|
|
60
|
-
|
|
61
86
|
getVueValue(buildFileName) {
|
|
62
87
|
let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
|
|
63
88
|
let vueData = vueContent + ""
|
|
64
|
-
|
|
65
89
|
if (!vueContent.includes("scoped")) {
|
|
66
|
-
|
|
67
90
|
console.log()
|
|
68
91
|
console.log(chalk.yellow("Warning: The scoped attribute is missing in style, which may cause global style pollution. It is recommended to fix it。"));
|
|
69
92
|
console.log()
|
|
70
93
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
vueData = vueData.match(/data\s*\(\s*\)\s*{\s*return\s*({[\s\S]*?})\s*;?\s*}/);
|
|
95
|
+
if (vueData && vueData.length > 0) {
|
|
96
|
+
vueData = vueData[1]
|
|
97
|
+
}
|
|
98
|
+
let data = {};
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
data = eval(`(${vueData})`) || {};
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.log();
|
|
104
|
+
console.log(chalk.red(
|
|
105
|
+
"Error: Failed to parse data() in component. \n" +
|
|
106
|
+
"Please check if there are any reference type variable in your data(). \n" +
|
|
107
|
+
"Suggestion: Initialize external variables in created() lifecycle hook instead."
|
|
108
|
+
));
|
|
109
|
+
console.log();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
79
113
|
if (!data.propObj) {
|
|
80
114
|
data.propObj = {};
|
|
81
115
|
data.propOption = {};
|
|
82
116
|
}
|
|
83
|
-
|
|
117
|
+
|
|
84
118
|
if (!data.events) {
|
|
85
119
|
data.events = {};
|
|
86
120
|
data.eventsOption = {};
|
|
87
121
|
}
|
|
88
|
-
|
|
122
|
+
|
|
89
123
|
if (!data.style) {
|
|
90
124
|
data.style = {
|
|
91
125
|
unit: "px",
|
|
@@ -142,20 +176,38 @@ class Builder {
|
|
|
142
176
|
},
|
|
143
177
|
};
|
|
144
178
|
}
|
|
145
|
-
let component
|
|
146
|
-
let compName
|
|
179
|
+
let component;
|
|
180
|
+
let compName;
|
|
181
|
+
let bizType;
|
|
182
|
+
let compDesc;
|
|
183
|
+
let category;
|
|
184
|
+
let loadModel = "lazy";
|
|
185
|
+
let belongOrgFlag = this.options.devConsoleConfig.belongOrgFlag || "custom"
|
|
186
|
+
if (data.componentInfo) {
|
|
187
|
+
component = data.componentInfo.component
|
|
188
|
+
compName = data.componentInfo.compName
|
|
189
|
+
bizType = data.componentInfo.bizType
|
|
190
|
+
compDesc = data.componentInfo.compDesc
|
|
191
|
+
category = data.componentInfo.category
|
|
192
|
+
loadModel = data.componentInfo.loadModel
|
|
193
|
+
belongOrgFlag = data.componentInfo.belongOrgFlag
|
|
194
|
+
} else {
|
|
195
|
+
component = this.options.pluginConfig.component
|
|
196
|
+
compName = this.options.pluginConfig.compName
|
|
197
|
+
bizType = this.options.pluginConfig.bizType
|
|
198
|
+
compDesc = this.options.pluginConfig.compDesc
|
|
199
|
+
category = this.options.pluginConfig.category
|
|
200
|
+
loadModel = this.options.pluginConfig.loadModel
|
|
201
|
+
belongOrgFlag = this.options.pluginConfig.belongOrgFlag
|
|
202
|
+
}
|
|
147
203
|
vueData = JSON.stringify(data);
|
|
148
|
-
|
|
149
|
-
let compDesc = data.componentInfo.compDesc
|
|
150
|
-
let category = data.componentInfo.category
|
|
151
|
-
let loadModel = data.componentInfo.loadModel
|
|
152
|
-
return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
|
|
204
|
+
return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel, belongOrgFlag }
|
|
153
205
|
};
|
|
154
|
-
|
|
206
|
+
|
|
155
207
|
initPluginFile(buildFileName, component, plginTemp) {
|
|
156
208
|
this.initPluginFile1(buildFileName, component, plginTemp)
|
|
157
209
|
}
|
|
158
|
-
|
|
210
|
+
|
|
159
211
|
initPluginFile1(buildFileName, component, plginTemp) {
|
|
160
212
|
let newContent =
|
|
161
213
|
`
|
|
@@ -164,13 +216,12 @@ class Builder {
|
|
|
164
216
|
Vue.use(VueCustomElement);
|
|
165
217
|
|
|
166
218
|
import index from "./` + buildFileName + `"
|
|
167
|
-
Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
|
|
219
|
+
Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.pluginConfig.destroyTimeout || this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
|
|
168
220
|
`
|
|
169
|
-
|
|
170
221
|
fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
|
|
171
222
|
}
|
|
172
223
|
|
|
173
|
-
|
|
224
|
+
|
|
174
225
|
initPluginFile2(buildFileName, component, plginTemp) {
|
|
175
226
|
let newContent =
|
|
176
227
|
`
|
|
@@ -189,7 +240,7 @@ class Builder {
|
|
|
189
240
|
fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
|
|
190
241
|
}
|
|
191
242
|
|
|
192
|
-
|
|
243
|
+
|
|
193
244
|
build(obj, config, plginTemp) {
|
|
194
245
|
console.log(chalk.green('Compiling, Please Wait...'));
|
|
195
246
|
exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugins/${plginTemp}.js`, async (error, stdout, stderr) => {
|
|
@@ -205,7 +256,7 @@ class Builder {
|
|
|
205
256
|
}
|
|
206
257
|
})
|
|
207
258
|
}
|
|
208
|
-
|
|
259
|
+
|
|
209
260
|
async upload(obj, header) {
|
|
210
261
|
console.log(chalk.green('Posting, please wait...'));
|
|
211
262
|
let jsContent = "";
|
|
@@ -224,10 +275,10 @@ class Builder {
|
|
|
224
275
|
"bizType": obj.bizType,
|
|
225
276
|
"compDesc": obj.compDesc,
|
|
226
277
|
"category": obj.category,
|
|
227
|
-
"loadModel": obj.loadModel
|
|
228
|
-
"belongOrgFlag":
|
|
278
|
+
"loadModel": obj.loadModel,
|
|
279
|
+
"belongOrgFlag": obj.belongOrgFlag
|
|
229
280
|
}
|
|
230
|
-
|
|
281
|
+
|
|
231
282
|
let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
|
|
232
283
|
let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
|
|
233
284
|
body, header);
|
|
@@ -241,7 +292,7 @@ class Builder {
|
|
|
241
292
|
return res;
|
|
242
293
|
}
|
|
243
294
|
|
|
244
|
-
|
|
295
|
+
|
|
245
296
|
getVueContent(buildFileName) {
|
|
246
297
|
const jsPath = "plugins";
|
|
247
298
|
return path.join(jsPath, buildFileName);
|
package/src/script/publish.js
CHANGED
|
@@ -6,6 +6,7 @@ const chalk = require("chalk")
|
|
|
6
6
|
const { post } = require("../../utils/http")
|
|
7
7
|
const { getPackageJson } = require("../../utils/config.js")
|
|
8
8
|
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
9
|
+
const { getBusToken } = require("../../utils/utils")
|
|
9
10
|
|
|
10
11
|
async function publish(argvs) {
|
|
11
12
|
let name = argvs[2]
|
|
@@ -18,9 +19,9 @@ async function publish(argvs) {
|
|
|
18
19
|
|
|
19
20
|
if (classContent) {
|
|
20
21
|
let devConsoleConfig = getPackageJson()
|
|
21
|
-
|
|
22
|
+
|
|
22
23
|
if ("private" != devConsoleConfig.version) {
|
|
23
|
-
devConsoleConfig = { "accessToken": await
|
|
24
|
+
devConsoleConfig = { "accessToken": await getBusToken() };
|
|
24
25
|
}
|
|
25
26
|
console.log(chalk.green('Posting, please wait...'));
|
|
26
27
|
configContent.scriptContent = classContent
|
|
@@ -29,7 +30,7 @@ async function publish(argvs) {
|
|
|
29
30
|
console.log();
|
|
30
31
|
console.log(chalk.green('Success!'));
|
|
31
32
|
console.log();
|
|
32
|
-
|
|
33
|
+
|
|
33
34
|
if (!configContentOld.id) {
|
|
34
35
|
configContentOld.id = res.data
|
|
35
36
|
fs.writeFileSync(path.join(srcPath, "config.json"), JSON.stringify(configContentOld))
|
|
@@ -47,16 +48,4 @@ async function publish(argvs) {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
async function getToken(devConsoleConfig) {
|
|
53
|
-
let res = await post(devConsoleConfig.baseUrl || BaseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
|
|
54
|
-
if (res.returnCode == 200) {
|
|
55
|
-
return res.data.accessToken;
|
|
56
|
-
} else {
|
|
57
|
-
console.error(chalk.red(`Login failed`, JSON.stringify(res)));
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
51
|
module.exports = publish;
|
package/src/timer/create.js
CHANGED
|
@@ -9,7 +9,9 @@ async function create(name) {
|
|
|
9
9
|
const timerPath = path.join(process.cwd(), "timer/" + name);
|
|
10
10
|
try {
|
|
11
11
|
fs.mkdirSync(timerPath, { recursive: true })
|
|
12
|
-
const javaTmp =
|
|
12
|
+
const javaTmp = `// @SOURCE_CONTENT_START
|
|
13
|
+
System.out.print("hello CloudCC");
|
|
14
|
+
// @SOURCE_CONTENT_END`
|
|
13
15
|
fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
|
|
14
16
|
fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"3"}`)
|
|
15
17
|
console.log()
|
package/src/timer/publish.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
2
|
const fs = require("fs");
|
|
4
3
|
const path = require("path")
|
|
@@ -14,9 +13,14 @@ async function publish(name) {
|
|
|
14
13
|
console.log(chalk.green('Posting, please wait...'));
|
|
15
14
|
console.log();
|
|
16
15
|
const timerPath = path.join(process.cwd(), `timer/${name}/`);
|
|
17
|
-
let
|
|
16
|
+
let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
|
|
17
|
+
|
|
18
|
+
// 提取标记之间的内容
|
|
19
|
+
const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
|
|
20
|
+
let classContent = sourceMatch ? sourceMatch[1] : fullContent;
|
|
21
|
+
|
|
18
22
|
let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
|
|
19
|
-
|
|
23
|
+
|
|
20
24
|
if (await getBusToken()) {
|
|
21
25
|
let body = {
|
|
22
26
|
"id": configContent.id,
|
|
@@ -29,7 +33,7 @@ async function publish(name) {
|
|
|
29
33
|
if (res.result) {
|
|
30
34
|
console.log(chalk.green('Success!'));
|
|
31
35
|
console.log();
|
|
32
|
-
|
|
36
|
+
|
|
33
37
|
if (!configContent.id) {
|
|
34
38
|
configContent.id = res.data
|
|
35
39
|
fs.writeFileSync(path.join(timerPath, "config.json"), JSON.stringify(configContent))
|
package/src/triggers/create.js
CHANGED
|
@@ -10,7 +10,9 @@ async function create(argvs) {
|
|
|
10
10
|
const triggersPath = path.join(process.cwd(), "triggers/" + body.name);
|
|
11
11
|
try {
|
|
12
12
|
fs.mkdirSync(triggersPath, { recursive: true })
|
|
13
|
-
const javaTmp =
|
|
13
|
+
const javaTmp = `// @SOURCE_CONTENT_START
|
|
14
|
+
System.out.print("hello CloudCC");
|
|
15
|
+
// @SOURCE_CONTENT_END`
|
|
14
16
|
fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp)
|
|
15
17
|
fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(body))
|
|
16
18
|
console.log()
|
package/src/triggers/publish.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
2
|
const fs = require("fs");
|
|
4
3
|
const path = require("path")
|
|
@@ -14,9 +13,14 @@ async function publish(argvs) {
|
|
|
14
13
|
console.log(chalk.green('Posting, please wait...'));
|
|
15
14
|
console.log();
|
|
16
15
|
const triggersPath = path.join(process.cwd(), `triggers/${name}/`);
|
|
17
|
-
let
|
|
16
|
+
let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
|
|
17
|
+
|
|
18
|
+
// 提取标记之间的内容
|
|
19
|
+
const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
|
|
20
|
+
let classContent = sourceMatch ? sourceMatch[1] : fullContent;
|
|
21
|
+
|
|
18
22
|
let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
|
|
19
|
-
|
|
23
|
+
|
|
20
24
|
if (await getBusToken()) {
|
|
21
25
|
let body = {
|
|
22
26
|
"id": configContent.id,
|
|
@@ -33,7 +37,7 @@ async function publish(argvs) {
|
|
|
33
37
|
if (res.result) {
|
|
34
38
|
console.log(chalk.green('Success!'));
|
|
35
39
|
console.log();
|
|
36
|
-
|
|
40
|
+
|
|
37
41
|
if (!configContent.id) {
|
|
38
42
|
configContent.id = res.data.id
|
|
39
43
|
configContent.apiname = res.data.apiname
|
package/template/gitignore
CHANGED
package/utils/cache.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function getCachePath() {
|
|
5
|
+
return path.join(process.cwd(), '.cloudcc-cache.json');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function readCache() {
|
|
9
|
+
try {
|
|
10
|
+
const cachePath = getCachePath();
|
|
11
|
+
if (!fs.existsSync(cachePath)) {
|
|
12
|
+
fs.writeFileSync(cachePath, JSON.stringify({}, null, 2));
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const cacheContent = fs.readFileSync(cachePath, 'utf8');
|
|
16
|
+
return JSON.parse(cacheContent);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function writeCache(data) {
|
|
23
|
+
try {
|
|
24
|
+
const cachePath = getCachePath();
|
|
25
|
+
fs.writeFileSync(cachePath, JSON.stringify(data, null, 2));
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error('Failed to write cache:', error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { readCache, writeCache };
|
package/utils/checkVersion.js
CHANGED
|
@@ -2,7 +2,7 @@ const config = require("../package.json")
|
|
|
2
2
|
const inquirer = require("inquirer")
|
|
3
3
|
const exec = require('child_process').execSync;
|
|
4
4
|
const chalk = require("chalk")
|
|
5
|
-
|
|
5
|
+
const { readCache, writeCache } = require("./cache")
|
|
6
6
|
|
|
7
7
|
function checkNpmVersion() {
|
|
8
8
|
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
@@ -66,13 +66,32 @@ function update(onlineVersion) {
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
async function checkUpdate() {
|
|
69
|
+
// 检查缓存
|
|
70
|
+
const cache = readCache();
|
|
71
|
+
const cacheKey = 'version_check';
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
const oneHour = 60 * 60 * 1000;
|
|
74
|
+
|
|
75
|
+
// 如果缓存有效,跳过版本检查
|
|
76
|
+
if (cache[cacheKey] &&
|
|
77
|
+
cache[cacheKey].timestamp &&
|
|
78
|
+
(now - cache[cacheKey].timestamp) < oneHour) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
let onlineVersion;
|
|
70
83
|
try {
|
|
71
84
|
onlineVersion = checkNpmVersion();
|
|
85
|
+
// 更新缓存
|
|
86
|
+
cache[cacheKey] = {
|
|
87
|
+
timestamp: now
|
|
88
|
+
};
|
|
89
|
+
writeCache(cache);
|
|
72
90
|
} catch (error) {
|
|
73
91
|
console.log("error", error)
|
|
74
92
|
onlineVersion = false;
|
|
75
93
|
}
|
|
94
|
+
|
|
76
95
|
if (onlineVersion) {
|
|
77
96
|
let res = await askUpdate()
|
|
78
97
|
if ("Yes" == res.update) {
|
|
@@ -80,11 +99,9 @@ async function checkUpdate() {
|
|
|
80
99
|
return true;
|
|
81
100
|
} else {
|
|
82
101
|
return false
|
|
83
|
-
|
|
84
102
|
}
|
|
85
103
|
}
|
|
86
104
|
return false
|
|
87
105
|
}
|
|
88
106
|
|
|
89
|
-
|
|
90
107
|
module.exports = { checkUpdate }
|
package/utils/utils.js
CHANGED
|
@@ -1,26 +1,71 @@
|
|
|
1
1
|
const { getParams, postNormal } = require("./http")
|
|
2
2
|
const chalk = require("chalk")
|
|
3
3
|
const { getPackageJson } = require("./config")
|
|
4
|
+
const { readCache, writeCache } = require("./cache")
|
|
4
5
|
|
|
5
6
|
async function getBaseUrl(devConfig) {
|
|
7
|
+
const cache = readCache();
|
|
8
|
+
const cacheKey = devConfig.secretKey;
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
const oneHour = 60 * 60 * 1000;
|
|
11
|
+
|
|
12
|
+
// Check if cache is valid
|
|
13
|
+
if (cache[cacheKey] &&
|
|
14
|
+
cache[cacheKey].apiSvc &&
|
|
15
|
+
cache[cacheKey].setupSvc &&
|
|
16
|
+
cache[cacheKey].timestamp &&
|
|
17
|
+
(now - cache[cacheKey].timestamp) < oneHour) {
|
|
18
|
+
global.apiSvc = cache[cacheKey].apiSvc;
|
|
19
|
+
global.setupSvc = cache[cacheKey].setupSvc;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
if ('private' == devConfig.version) {
|
|
7
24
|
global.apiSvc = devConfig.baseUrl + (devConfig.apiSvcPrefix || "/apitfs")
|
|
8
|
-
global.setupSvc = devConfig.baseUrl + (devConfig.setupSvcPrefix || "/
|
|
25
|
+
global.setupSvc = devConfig.baseUrl + (devConfig.setupSvcPrefix || "/setup")
|
|
9
26
|
} else {
|
|
10
27
|
let u = "https://developer.apis.cloudcc.cn/oauth/apidomain?scope=cloudccCRM&orgId=" + devConfig.orgId
|
|
11
28
|
let res = await getParams(u)
|
|
12
29
|
global.apiSvc = res.orgapi_address
|
|
13
|
-
global.setupSvc = new URL(res.orgapi_address).origin + (devConfig.setupSvcPrefix || "/
|
|
30
|
+
global.setupSvc = new URL(res.orgapi_address).origin + (devConfig.setupSvcPrefix || "/setup")
|
|
14
31
|
}
|
|
32
|
+
|
|
33
|
+
// Update cache with apiSvc and setupSvc
|
|
34
|
+
cache[cacheKey] = {
|
|
35
|
+
...(cache[cacheKey] || {}),
|
|
36
|
+
apiSvc: global.apiSvc,
|
|
37
|
+
setupSvc: global.setupSvc,
|
|
38
|
+
timestamp: now
|
|
39
|
+
};
|
|
40
|
+
writeCache(cache);
|
|
15
41
|
}
|
|
16
42
|
|
|
17
|
-
async function getBusToken(path) {
|
|
43
|
+
async function getBusToken(path = process.cwd()) {
|
|
18
44
|
let devConfig = getPackageJson(path);
|
|
19
45
|
if (!devConfig.username || !devConfig.safetyMark || !devConfig.clientId || !devConfig.openSecretKey || !devConfig.orgId) {
|
|
20
46
|
console.log(chalk.red('The security tag configuration is incorrect. Please check the documentation for configuration.'));
|
|
21
47
|
console.log();
|
|
22
48
|
return false;
|
|
23
49
|
}
|
|
50
|
+
|
|
51
|
+
const cache = readCache();
|
|
52
|
+
const cacheKey = devConfig.secretKey;
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
const oneHour = 60 * 60 * 1000;
|
|
55
|
+
|
|
56
|
+
// Check if cache is valid
|
|
57
|
+
if (cache[cacheKey] &&
|
|
58
|
+
cache[cacheKey].token &&
|
|
59
|
+
cache[cacheKey].apiSvc &&
|
|
60
|
+
cache[cacheKey].setupSvc &&
|
|
61
|
+
cache[cacheKey].timestamp &&
|
|
62
|
+
(now - cache[cacheKey].timestamp) < oneHour) {
|
|
63
|
+
global.accessToken = cache[cacheKey].token;
|
|
64
|
+
global.apiSvc = cache[cacheKey].apiSvc;
|
|
65
|
+
global.setupSvc = cache[cacheKey].setupSvc;
|
|
66
|
+
return cache[cacheKey].token;
|
|
67
|
+
}
|
|
68
|
+
|
|
24
69
|
let body = {
|
|
25
70
|
username: devConfig.username,
|
|
26
71
|
safetyMark: devConfig.safetyMark,
|
|
@@ -31,10 +76,18 @@ async function getBusToken(path) {
|
|
|
31
76
|
await getBaseUrl(devConfig)
|
|
32
77
|
let res = await postNormal(global.apiSvc + "/api/cauth/token", body)
|
|
33
78
|
if (res.result) {
|
|
34
|
-
global.accessToken = res.data.accessToken
|
|
79
|
+
global.accessToken = res.data.accessToken;
|
|
80
|
+
// Update cache
|
|
81
|
+
cache[cacheKey] = {
|
|
82
|
+
token: res.data.accessToken,
|
|
83
|
+
apiSvc: global.apiSvc,
|
|
84
|
+
setupSvc: global.setupSvc,
|
|
85
|
+
timestamp: now
|
|
86
|
+
};
|
|
87
|
+
writeCache(cache);
|
|
35
88
|
return res.data.accessToken;
|
|
36
89
|
}
|
|
37
|
-
return false
|
|
90
|
+
return false;
|
|
38
91
|
}
|
|
39
92
|
|
|
40
93
|
module.exports = { getBusToken }
|