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