cloudcc-cli 1.6.0 → 1.6.2

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.
Files changed (50) hide show
  1. package/README.md +1147 -1128
  2. package/bin/cc.js +48 -48
  3. package/bin/plugin.js +5 -5
  4. package/bin/project.js +5 -5
  5. package/package.json +34 -34
  6. package/src/classes/create.js +43 -43
  7. package/src/classes/index.js +8 -8
  8. package/src/classes/publish.js +48 -47
  9. package/src/config/get.js +22 -0
  10. package/src/config/index.js +8 -0
  11. package/src/config/use.js +16 -0
  12. package/src/object/get.js +16 -0
  13. package/src/object/index.js +7 -0
  14. package/src/plugin/create.js +80 -80
  15. package/src/plugin/create1.js +66 -67
  16. package/src/plugin/index.js +8 -8
  17. package/src/plugin/publish.js +298 -305
  18. package/src/plugin/publish1.js +286 -293
  19. package/src/project/create.js +89 -89
  20. package/src/project/create1.js +111 -94
  21. package/src/project/index.js +7 -7
  22. package/src/recordType/get.js +16 -0
  23. package/src/recordType/index.js +7 -0
  24. package/src/script/create.js +33 -0
  25. package/src/script/index.js +8 -0
  26. package/src/script/publish.js +69 -0
  27. package/src/timer/create.js +29 -29
  28. package/src/timer/index.js +8 -8
  29. package/src/timer/publish.js +47 -47
  30. package/src/token/get.js +13 -0
  31. package/src/token/index.js +7 -0
  32. package/src/triggers/create.js +35 -35
  33. package/src/triggers/index.js +8 -8
  34. package/src/triggers/publish.js +51 -51
  35. package/template/Appvue +29 -29
  36. package/template/babelconfigjs +5 -5
  37. package/template/cloudcc-cli.configjs +1 -0
  38. package/template/demojava +14 -14
  39. package/template/gitignore +11 -0
  40. package/template/index.js +57 -52
  41. package/template/indexhtml +21 -21
  42. package/template/indexvue +34 -34
  43. package/template/javaconfigjson +2 -2
  44. package/template/mainjs +13 -13
  45. package/template/package-lockjson +12115 -12115
  46. package/template/packagejson +42 -46
  47. package/template/vueconfigjs +26 -26
  48. package/utils/checkVersion.js +105 -105
  49. package/utils/http.js +122 -122
  50. package/utils/utils.js +54 -44
@@ -1,293 +1,286 @@
1
- const { exec } = require('child_process');
2
- const { post } = require('../../utils/http');
3
- const fs = require('fs');
4
- const path = require("path")
5
- const chalk = require("chalk")
6
- const inquirer = require("inquirer")
7
- // 检查cli版本更新功能
8
- const { checkUpdate } = require("../../utils/checkVersion")
9
- const BaseUrl = "https://developer.apis.cloudcc.cn"
10
-
11
- /**
12
- * 自定义组件,组件打包命令,将组件打包发布到服务器。
13
- */
14
- class Builder {
15
- constructor() {
16
- this.options = {
17
- // 开发配置信息
18
- devConsoleConfig: {
19
- },
20
- }
21
- this.plugin = process.argv.splice(2)[0]
22
- }
23
- async publish(name) {
24
- let res = await checkUpdate();
25
- if (!res) {
26
- this.options.devConsoleConfig = this.getPackageJson();
27
- let config = this.options.devConsoleConfig
28
- // 如果不是私有化部署,那么需要获取token
29
- if ("private" != this.options.devConsoleConfig.version) { // private私有化
30
- config = { "accessToken": await this.getToken(config) };
31
- }
32
- // 获得用户输入
33
- let answers = { buildFileName: `${name}/${name}.vue` }
34
- // 如果输入的是*.vue,那么表示编译全部文件
35
- if ("*.vue" == answers.buildFileName) {
36
- let dirs = fs.readdirSync("plugin")
37
- for (let i = 0; i < dirs.length; i++) {
38
- let item = dirs[i]
39
- let obj = this.getVueValue(item);
40
- this.initPluginFile(item, obj.component, "plginTemp" + i);
41
- this.build(obj, config, "plginTemp" + i)
42
- }
43
- } else {
44
- let obj = this.getVueValue(answers.buildFileName);
45
- this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
46
- this.build(obj, config, "plginTemp")
47
- }
48
- }
49
- }
50
- /**
51
- * 获得用户信息
52
- * @returns 配置信息
53
- */
54
- getPackageJson() {
55
- const packageJson = JSON.parse(fs.readFileSync("package.json", 'utf8'));
56
- return packageJson.devConsoleConfig; // cloudcc-plugin 中的 devConsoleConfig
57
- }
58
- /**
59
- * 请求用户token
60
- * @param {用户信息} devConsoleConfig
61
- * @returns token
62
- */
63
- async getToken(devConsoleConfig) {
64
- let res = await post(this.options.devConsoleConfig.baseUrl || BaseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
65
- if (res.returnCode == 200) {
66
- return res.data.accessToken;
67
- } else {
68
- console.error(chalk.red(`登录失败`, JSON.stringify(res)));
69
- return null;
70
- }
71
- }
72
-
73
- /**
74
- * 获得Vue内容
75
- */
76
- getVueValue(buildFileName) {
77
- let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
78
- let vueData = vueContent + ""
79
- // 添加scoped限制样式污染
80
- if (!vueContent.includes("scoped")) {
81
- // vueData = vueData.replace("<style", "<style scoped ")
82
- console.log()
83
- console.log(chalk.yellow("警告:style中缺少scoped属性,可能会造成样式全局污染,建议修复。"));
84
- console.log()
85
- }
86
- // 去除空格
87
- // vueData = vueData.replace(/\ +/g, "")
88
- // 去除换行
89
- // vueData =vueData.replace(/[\r\n]/g, "");
90
- vueData = vueData.split("data()")[1].split("isLock:")[0] + "isLock:false,};}";
91
- vueData = "function data()" + vueData;
92
- const data = eval(`(${vueData})`)()
93
- // 如果propObj不存在,那么初始一个空对象
94
- if (!data.propObj) {
95
- data.propObj = {};
96
- data.propOption = {};
97
- }
98
- // 如果events不存在,那么初始一个空对象
99
- if (!data.events) {
100
- data.events = {};
101
- data.eventsOption = {};
102
- }
103
- // 如果style不存在,那么初始一个空对象
104
- if (!data.style) {
105
- data.style = {
106
- unit: "px",
107
- width: 72,
108
- height: 38,
109
- top: 0,
110
- left: 0,
111
- rotate: 0,
112
- opacity: 1,
113
- };
114
- data.styleOption = {
115
- word: {
116
- lable: "label.help",
117
- type: "word",
118
- link: "https://zucfl0psd6.feishu.cn/wiki/wikcnlXGFHfXw5LgAWbDcJXTFyd",
119
- },
120
- unit: {
121
- lable: "label.custom.unit",
122
- type: "option",
123
- options: [
124
- {
125
- value: "px",
126
- label: "label.custom.pixel",
127
- },
128
- {
129
- value: "%",
130
- label: "label.percent",
131
- },
132
- {
133
- value: "hw",
134
- label: "label.custom.viewport",
135
- },
136
- ],
137
- },
138
- width: {
139
- lable: "label.custom.width",
140
- type: "input",
141
- inputType: "number",
142
- },
143
- height: {
144
- lable: "label.custom.height",
145
- type: "input",
146
- inputType: "number",
147
- },
148
- top: {
149
- lable: "label.dev.y.coordinate",
150
- type: "input",
151
- inputType: "number",
152
- },
153
- left: {
154
- lable: "label.dev.x.coordinate",
155
- type: "input",
156
- inputType: "number",
157
- },
158
- };
159
- }
160
- let component = data.componentInfo.component // 组件标识
161
- let compName = data.componentInfo.compName // 组件名字
162
- vueData = JSON.stringify(data);
163
- let bizType = data.componentInfo.bizType // 组件类型
164
- let compDesc = data.componentInfo.compDesc // 组件描述
165
- let category = data.componentInfo.category // 组件状态
166
- let loadModel = data.componentInfo.loadModel // 组件加载模式,按需加载(lazy),启动加载(start)。
167
- return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
168
- };
169
- /**
170
- *
171
- * @param {string} buildFileName 编译文件入口
172
- * @param {string} component 编译后组件的名字
173
- * @param {string} plginTemp 生成模板代码存储路径
174
- */
175
- initPluginFile(buildFileName, component, plginTemp) {
176
- this.initPluginFile1(buildFileName, component, plginTemp)
177
- }
178
- /**
179
- * 生成依赖文件,vue-custom-element
180
- * @param {编译的文件名称} buildFileName
181
- * @param {编译后的组件名称} component
182
- */
183
- initPluginFile1(buildFileName, component, plginTemp) {
184
- let newContent =
185
- `
186
- import Vue from "vue"
187
- import VueCustomElement from "vue-custom-element"
188
- Vue.use(VueCustomElement);
189
-
190
- import index from "./` + buildFileName + `"
191
- Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
192
- `
193
-
194
- fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
195
- }
196
-
197
- /**
198
- * 生成依赖文件
199
- * @param {编译的文件名称} buildFileName
200
- * @param {编译后的组件名称} component
201
- */
202
- initPluginFile2(buildFileName, component, plginTemp) {
203
- let newContent =
204
- `
205
- import index from "./${buildFileName}"
206
- function install(Vue) {
207
- Vue.component('${component}', index);
208
- }
209
- export default install;
210
- if (typeof window !== 'undefined' && window.Vue) {
211
- console.log("install装载",install)
212
- window.Vue.use(install);
213
- if (install.installed) {
214
- install.installed = false;
215
- }
216
- }
217
- `
218
- fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
219
- }
220
-
221
- /**
222
- * 编译文件,将vue编译为js文件
223
- * @param {编译对象信息} obj
224
- */
225
- build(obj, config, plginTemp) {
226
- console.log(chalk.green('编译中,请稍后...'));
227
- exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugin/${plginTemp}.js`, async (error, stdout, stderr) => {
228
- if (error) {
229
- console.log('编译失败:', error);
230
- console.log(chalk.red('编译失败:' + stdout));
231
- return;
232
- } else {
233
- console.log(chalk.green('编译成功!'));
234
- console.log();
235
- await this.upload(obj, config)
236
- fs.unlinkSync(`plugin/${plginTemp}.js`);
237
- }
238
- })
239
- }
240
- /**
241
- * 将文件上传
242
- */
243
- async upload(obj, header) {
244
- console.log(chalk.green('发布中,请稍后...'));
245
- let jsContent = "";
246
- try {
247
- jsContent = fs.readFileSync(path.join("build", obj.component + ".umd.min.js"), 'utf8')
248
- } catch (err) {
249
- console.error(err)
250
- return;
251
- }
252
- let body = {
253
- "compLabel": obj.compName,
254
- "compUniName": obj.component,
255
- "compContentJs": jsContent,
256
- "compContentVue": obj.vueContent,
257
- "vueData": obj.vueData,
258
- "bizType": obj.bizType,
259
- "compDesc": obj.compDesc,
260
- "category": obj.category,
261
- "loadModel": obj.loadModel || "lazy",
262
- "belongOrgFlag": this.options.devConsoleConfig.belongOrgFlag || "custom" //belongOrgFlag: 所属单位标识,std:官方的组件(神州云动);custom:第三方的组件
263
- }
264
- // 服务名
265
- let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
266
- let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
267
- body, header);
268
- if (res.returnCode == 200) {
269
- console.error(chalk.green(`发布成功!`));
270
- console.log();
271
- } else {
272
- console.error(chalk.red(`发布失败: ${res.returnInfo}`));
273
- console.log();
274
- }
275
- return res;
276
- }
277
-
278
- /**
279
- * 过滤出min.js文件
280
- * @returns 过滤结果
281
- */
282
- getVueContent(buildFileName) {
283
- const jsPath = "plugin";
284
- return path.join(jsPath, buildFileName);
285
- }
286
- }
287
-
288
- function publish(name) {
289
- let p = new Builder()
290
- p.publish(name)
291
- }
292
-
293
- module.exports = publish;
1
+ const { exec } = require('child_process');
2
+ const { post } = require('../../utils/http');
3
+ const fs = require('fs');
4
+ const path = require("path")
5
+ const chalk = require("chalk")
6
+ const inquirer = require("inquirer")
7
+ // 检查cli版本更新功能
8
+ const { checkUpdate } = require("../../utils/checkVersion")
9
+ const BaseUrl = "https://developer.apis.cloudcc.cn"
10
+ const { getPackageJson } = require("../../utils/utils")
11
+
12
+ /**
13
+ * 自定义组件,组件打包命令,将组件打包发布到服务器。
14
+ */
15
+ class Builder {
16
+ constructor() {
17
+ this.options = {
18
+ // 开发配置信息
19
+ devConsoleConfig: {
20
+ },
21
+ }
22
+ this.plugin = process.argv.splice(2)[0]
23
+ }
24
+ async publish(name) {
25
+ let res = await checkUpdate();
26
+ if (!res) {
27
+ this.options.devConsoleConfig = getPackageJson();
28
+ let config = this.options.devConsoleConfig
29
+ // 如果不是私有化部署,那么需要获取token
30
+ if ("private" != this.options.devConsoleConfig.version) { // private私有化
31
+ config = { "accessToken": await this.getToken(config) };
32
+ }
33
+ // 获得用户输入
34
+ let answers = { buildFileName: `${name}/${name}.vue` }
35
+ // 如果输入的是*.vue,那么表示编译全部文件
36
+ if ("*.vue" == answers.buildFileName) {
37
+ let dirs = fs.readdirSync("plugin")
38
+ for (let i = 0; i < dirs.length; i++) {
39
+ let item = dirs[i]
40
+ let obj = this.getVueValue(item);
41
+ this.initPluginFile(item, obj.component, "plginTemp" + i);
42
+ this.build(obj, config, "plginTemp" + i)
43
+ }
44
+ } else {
45
+ let obj = this.getVueValue(answers.buildFileName);
46
+ this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
47
+ this.build(obj, config, "plginTemp")
48
+ }
49
+ }
50
+ }
51
+ /**
52
+ * 请求用户token
53
+ * @param {用户信息} devConsoleConfig
54
+ * @returns token
55
+ */
56
+ async getToken(devConsoleConfig) {
57
+ let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
58
+ if (res.returnCode == 200) {
59
+ return res.data.accessToken;
60
+ } else {
61
+ console.error(chalk.red(`登录失败`, JSON.stringify(res)));
62
+ return null;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * 获得Vue内容
68
+ */
69
+ getVueValue(buildFileName) {
70
+ let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
71
+ let vueData = vueContent + ""
72
+ // 添加scoped限制样式污染
73
+ if (!vueContent.includes("scoped")) {
74
+ // vueData = vueData.replace("<style", "<style scoped ")
75
+ console.log()
76
+ console.log(chalk.yellow("警告:style中缺少scoped属性,可能会造成样式全局污染,建议修复。"));
77
+ console.log()
78
+ }
79
+ // 去除空格
80
+ // vueData = vueData.replace(/\ +/g, "")
81
+ // 去除换行
82
+ // vueData =vueData.replace(/[\r\n]/g, "");
83
+ vueData = vueData.split("data()")[1].split("isLock:")[0] + "isLock:false,};}";
84
+ vueData = "function data()" + vueData;
85
+ const data = eval(`(${vueData})`)()
86
+ // 如果propObj不存在,那么初始一个空对象
87
+ if (!data.propObj) {
88
+ data.propObj = {};
89
+ data.propOption = {};
90
+ }
91
+ // 如果events不存在,那么初始一个空对象
92
+ if (!data.events) {
93
+ data.events = {};
94
+ data.eventsOption = {};
95
+ }
96
+ // 如果style不存在,那么初始一个空对象
97
+ if (!data.style) {
98
+ data.style = {
99
+ unit: "px",
100
+ width: 72,
101
+ height: 38,
102
+ top: 0,
103
+ left: 0,
104
+ rotate: 0,
105
+ opacity: 1,
106
+ };
107
+ data.styleOption = {
108
+ word: {
109
+ lable: "label.help",
110
+ type: "word",
111
+ link: "https://zucfl0psd6.feishu.cn/wiki/wikcnlXGFHfXw5LgAWbDcJXTFyd",
112
+ },
113
+ unit: {
114
+ lable: "label.custom.unit",
115
+ type: "option",
116
+ options: [
117
+ {
118
+ value: "px",
119
+ label: "label.custom.pixel",
120
+ },
121
+ {
122
+ value: "%",
123
+ label: "label.percent",
124
+ },
125
+ {
126
+ value: "hw",
127
+ label: "label.custom.viewport",
128
+ },
129
+ ],
130
+ },
131
+ width: {
132
+ lable: "label.custom.width",
133
+ type: "input",
134
+ inputType: "number",
135
+ },
136
+ height: {
137
+ lable: "label.custom.height",
138
+ type: "input",
139
+ inputType: "number",
140
+ },
141
+ top: {
142
+ lable: "label.dev.y.coordinate",
143
+ type: "input",
144
+ inputType: "number",
145
+ },
146
+ left: {
147
+ lable: "label.dev.x.coordinate",
148
+ type: "input",
149
+ inputType: "number",
150
+ },
151
+ };
152
+ }
153
+ let component = data.componentInfo.component // 组件标识
154
+ let compName = data.componentInfo.compName // 组件名字
155
+ vueData = JSON.stringify(data);
156
+ let bizType = data.componentInfo.bizType // 组件类型
157
+ let compDesc = data.componentInfo.compDesc // 组件描述
158
+ let category = data.componentInfo.category // 组件状态
159
+ let loadModel = data.componentInfo.loadModel // 组件加载模式,按需加载(lazy),启动加载(start)。
160
+ return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
161
+ };
162
+ /**
163
+ *
164
+ * @param {string} buildFileName 编译文件入口
165
+ * @param {string} component 编译后组件的名字
166
+ * @param {string} plginTemp 生成模板代码存储路径
167
+ */
168
+ initPluginFile(buildFileName, component, plginTemp) {
169
+ this.initPluginFile1(buildFileName, component, plginTemp)
170
+ }
171
+ /**
172
+ * 生成依赖文件,vue-custom-element
173
+ * @param {编译的文件名称} buildFileName
174
+ * @param {编译后的组件名称} component
175
+ */
176
+ initPluginFile1(buildFileName, component, plginTemp) {
177
+ let newContent =
178
+ `
179
+ import Vue from "vue"
180
+ import VueCustomElement from "vue-custom-element"
181
+ Vue.use(VueCustomElement);
182
+
183
+ import index from "./` + buildFileName + `"
184
+ Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
185
+ `
186
+
187
+ fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
188
+ }
189
+
190
+ /**
191
+ * 生成依赖文件
192
+ * @param {编译的文件名称} buildFileName
193
+ * @param {编译后的组件名称} component
194
+ */
195
+ initPluginFile2(buildFileName, component, plginTemp) {
196
+ let newContent =
197
+ `
198
+ import index from "./${buildFileName}"
199
+ function install(Vue) {
200
+ Vue.component('${component}', index);
201
+ }
202
+ export default install;
203
+ if (typeof window !== 'undefined' && window.Vue) {
204
+ console.log("install装载",install)
205
+ window.Vue.use(install);
206
+ if (install.installed) {
207
+ install.installed = false;
208
+ }
209
+ }
210
+ `
211
+ fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
212
+ }
213
+
214
+ /**
215
+ * 编译文件,将vue编译为js文件
216
+ * @param {编译对象信息} obj
217
+ */
218
+ build(obj, config, plginTemp) {
219
+ console.log(chalk.green('编译中,请稍后...'));
220
+ exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugin/${plginTemp}.js`, async (error, stdout, stderr) => {
221
+ if (error) {
222
+ console.log('编译失败:', error);
223
+ console.log(chalk.red('编译失败:' + stdout));
224
+ return;
225
+ } else {
226
+ console.log(chalk.green('编译成功!'));
227
+ console.log();
228
+ await this.upload(obj, config)
229
+ fs.unlinkSync(`plugin/${plginTemp}.js`);
230
+ }
231
+ })
232
+ }
233
+ /**
234
+ * 将文件上传
235
+ */
236
+ async upload(obj, header) {
237
+ console.log(chalk.green('发布中,请稍后...'));
238
+ let jsContent = "";
239
+ try {
240
+ jsContent = fs.readFileSync(path.join("build", obj.component + ".umd.min.js"), 'utf8')
241
+ } catch (err) {
242
+ console.error(err)
243
+ return;
244
+ }
245
+ let body = {
246
+ "compLabel": obj.compName,
247
+ "compUniName": obj.component,
248
+ "compContentJs": jsContent,
249
+ "compContentVue": obj.vueContent,
250
+ "vueData": obj.vueData,
251
+ "bizType": obj.bizType,
252
+ "compDesc": obj.compDesc,
253
+ "category": obj.category,
254
+ "loadModel": obj.loadModel || "lazy",
255
+ "belongOrgFlag": this.options.devConsoleConfig.belongOrgFlag || "custom" //belongOrgFlag: 所属单位标识,std:官方的组件(神州云动);custom:第三方的组件
256
+ }
257
+ // 服务名
258
+ let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
259
+ let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
260
+ body, header);
261
+ if (res.returnCode == 200) {
262
+ console.error(chalk.green(`发布成功!`));
263
+ console.log();
264
+ } else {
265
+ console.error(chalk.red(`发布失败: ${res.returnInfo}`));
266
+ console.log();
267
+ }
268
+ return res;
269
+ }
270
+
271
+ /**
272
+ * 过滤出min.js文件
273
+ * @returns 过滤结果
274
+ */
275
+ getVueContent(buildFileName) {
276
+ const jsPath = "plugin";
277
+ return path.join(jsPath, buildFileName);
278
+ }
279
+ }
280
+
281
+ function publish(argvs) {
282
+ let p = new Builder()
283
+ p.publish(argvs)
284
+ }
285
+
286
+ module.exports = publish;