cloudcc-cli 1.2.9 → 1.3.1

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/src/builderSDK.js CHANGED
@@ -1,161 +1,161 @@
1
- const { execSync } = 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
- const { checkUpdate } = require("../utils/checkVersion")
8
- /**
9
- * 打包业务sdk为js并发布到cdn
10
- */
11
- class Builder {
12
- constructor() {
13
- this.options = {
14
- // 开发配置信息
15
- devConsoleConfig: {
16
- },
17
- }
18
- }
19
- async init() {
20
- let res = await checkUpdate();
21
- if (!res) {
22
- this.options.devConsoleConfig = this.getPackageJson();
23
- // 获得用户输入
24
- let answers = await this.ask();
25
- if (answers.types.length == 0) {
26
- console.log();
27
- console.error(chalk.red(`请选择一个有效的发布版本!`));
28
- console.log();
29
- return;
30
- }
31
- // 获得vue内容
32
- let obj = this.getSDKName(answers.buildDirName);
33
- obj.type = answers.types;
34
- this.build(obj) && this.upload(obj);
35
- }
36
- }
37
- /**
38
- * 命令行交互
39
- * @returns 结果
40
- */
41
- ask() {
42
- const prompt = [{
43
- type: 'list',
44
- message: '请选择发布版本:',
45
- name: 'types',
46
- choices: [
47
- { name: "客户环境-Release", value: "release" },
48
- { name: "公司环境-GA", value: "ga" },
49
- { name: "uat环境-Beta", value: "beta" },
50
- { name: "测试环境-Dev", value: "dev" },
51
- ],
52
- }, {
53
- type: "input",
54
- name: "buildDirName",
55
- message: "请输入需要编译的目录名称,如Detail:",
56
- }];
57
- return inquirer.prompt(prompt)
58
- }
59
- /**
60
- * 获得用户信息
61
- * @returns 配置信息
62
- */
63
- getPackageJson() {
64
- const packageJson = JSON.parse(fs.readFileSync("package.json", 'utf8'));
65
- return packageJson.devConsoleConfig; // cloudcc-plugin 中的 devConsoleConfig
66
- }
67
- /**
68
- * 请求用户token
69
- * @param {用户信息} devConsoleConfig
70
- * @returns token
71
- */
72
- async getToken(devConsoleConfig) {
73
- let res = await post(this.options.devConsoleConfig.baseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
74
- if (res.returnCode == 200) {
75
- return res.data.accessToken;
76
- } else {
77
- console.error(chalk.red(`登录失败`, JSON.stringify(res)));
78
- return null;
79
- }
80
- }
81
- /**
82
- * 获得sdk名字
83
- */
84
- getSDKName(buildFileName) {
85
- let vueContent = fs.readFileSync(path.join("packages", buildFileName, "src", "index.vue"), 'utf8');
86
-
87
- let sdkName = "cc-" + vueContent.split("\"cc-")[1].split("\"")[0]
88
-
89
- return { sdkName, path: path.join("packages", buildFileName) }
90
- };
91
- /**
92
- * 编译文件,将vue编译为js文件
93
- * @param {编译对象信息} obj
94
- */
95
- build(obj) {
96
- try {
97
- console.log(chalk.green('编译中,请稍后...'));
98
- console.log()
99
- execSync(`npx vue-cli-service build --target lib --name ${obj.sdkName} --dest ${path.join(obj.path, "lib")} ${path.join(obj.path, "index.js")}`);
100
- console.log(chalk.green('编译成功!'));
101
- console.log()
102
- return true
103
- } catch (e) {
104
- console.log(chalk.red("编译失败:", e.toString("utf8").trim()));
105
- console.log()
106
- return false;
107
- }
108
- }
109
- /**
110
- * 将文件上传
111
- */
112
- async upload(obj) {
113
- console.log(chalk.green('发布中,请稍后...'));
114
- console.log()
115
- let jsContent = "";
116
- try {
117
- jsContent = fs.readFileSync(path.join(obj.path, "lib", obj.sdkName + ".umd.min.js"), 'utf8')
118
- } catch (err) {
119
- console.error(err)
120
- }
121
- let body = {
122
- fileInfo: []
123
- };
124
- body.fileInfo.push(
125
- {
126
- "fileName": obj.type + "/" + obj.sdkName + ".umd.min.js",
127
- "fileContent": jsContent,
128
- "bucketName": "cloudcc-sdk",
129
- }
130
- )
131
- let res = await post(this.options.devConsoleConfig.baseUrl + "/devconsole/cdn/uploadFile",
132
- body);
133
- if (res.returnCode == 200) {
134
- console.error(chalk.green(`发布成功!`));
135
- console.log();
136
- } else {
137
- console.error(chalk.red(`发布失败: ${res.returnInfo}`));
138
- console.log();
139
- }
140
-
141
- return res;
142
- }
143
-
144
- /**
145
- * 过滤出min.js文件
146
- * @returns 过滤结果
147
- */
148
- filterFile() {
149
- const jsPath = "build";
150
- let jsPaths = [];
151
- if (jsPath) {
152
- jsPaths = fs.readdirSync(jsPath).filter((f) => {
153
- return f.endsWith('umd.min.js');
154
- }).map((item) => {
155
- return path.join(jsPath, item);
156
- });
157
- }
158
- return jsPaths;
159
- }
160
- }
1
+ const { execSync } = 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
+ const { checkUpdate } = require("../utils/checkVersion")
8
+ /**
9
+ * 打包业务sdk为js并发布到cdn
10
+ */
11
+ class Builder {
12
+ constructor() {
13
+ this.options = {
14
+ // 开发配置信息
15
+ devConsoleConfig: {
16
+ },
17
+ }
18
+ }
19
+ async init() {
20
+ let res = await checkUpdate();
21
+ if (!res) {
22
+ this.options.devConsoleConfig = this.getPackageJson();
23
+ // 获得用户输入
24
+ let answers = await this.ask();
25
+ if (answers.types.length == 0) {
26
+ console.log();
27
+ console.error(chalk.red(`请选择一个有效的发布版本!`));
28
+ console.log();
29
+ return;
30
+ }
31
+ // 获得vue内容
32
+ let obj = this.getSDKName(answers.buildDirName);
33
+ obj.type = answers.types;
34
+ this.build(obj) && this.upload(obj);
35
+ }
36
+ }
37
+ /**
38
+ * 命令行交互
39
+ * @returns 结果
40
+ */
41
+ ask() {
42
+ const prompt = [{
43
+ type: 'list',
44
+ message: '请选择发布版本:',
45
+ name: 'types',
46
+ choices: [
47
+ { name: "客户环境-Release", value: "release" },
48
+ { name: "公司环境-GA", value: "ga" },
49
+ { name: "uat环境-Beta", value: "beta" },
50
+ { name: "测试环境-Dev", value: "dev" },
51
+ ],
52
+ }, {
53
+ type: "input",
54
+ name: "buildDirName",
55
+ message: "请输入需要编译的目录名称,如Detail:",
56
+ }];
57
+ return inquirer.prompt(prompt)
58
+ }
59
+ /**
60
+ * 获得用户信息
61
+ * @returns 配置信息
62
+ */
63
+ getPackageJson() {
64
+ const packageJson = JSON.parse(fs.readFileSync("package.json", 'utf8'));
65
+ return packageJson.devConsoleConfig; // cloudcc-plugin 中的 devConsoleConfig
66
+ }
67
+ /**
68
+ * 请求用户token
69
+ * @param {用户信息} devConsoleConfig
70
+ * @returns token
71
+ */
72
+ async getToken(devConsoleConfig) {
73
+ let res = await post(this.options.devConsoleConfig.baseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
74
+ if (res.returnCode == 200) {
75
+ return res.data.accessToken;
76
+ } else {
77
+ console.error(chalk.red(`登录失败`, JSON.stringify(res)));
78
+ return null;
79
+ }
80
+ }
81
+ /**
82
+ * 获得sdk名字
83
+ */
84
+ getSDKName(buildFileName) {
85
+ let vueContent = fs.readFileSync(path.join("packages", buildFileName, "src", "index.vue"), 'utf8');
86
+
87
+ let sdkName = "cc-" + vueContent.split("\"cc-")[1].split("\"")[0]
88
+
89
+ return { sdkName, path: path.join("packages", buildFileName) }
90
+ };
91
+ /**
92
+ * 编译文件,将vue编译为js文件
93
+ * @param {编译对象信息} obj
94
+ */
95
+ build(obj) {
96
+ try {
97
+ console.log(chalk.green('编译中,请稍后...'));
98
+ console.log()
99
+ execSync(`npx vue-cli-service build --target lib --name ${obj.sdkName} --dest ${path.join(obj.path, "lib")} ${path.join(obj.path, "index.js")}`);
100
+ console.log(chalk.green('编译成功!'));
101
+ console.log()
102
+ return true
103
+ } catch (e) {
104
+ console.log(chalk.red("编译失败:", e.toString("utf8").trim()));
105
+ console.log()
106
+ return false;
107
+ }
108
+ }
109
+ /**
110
+ * 将文件上传
111
+ */
112
+ async upload(obj) {
113
+ console.log(chalk.green('发布中,请稍后...'));
114
+ console.log()
115
+ let jsContent = "";
116
+ try {
117
+ jsContent = fs.readFileSync(path.join(obj.path, "lib", obj.sdkName + ".umd.min.js"), 'utf8')
118
+ } catch (err) {
119
+ console.error(err)
120
+ }
121
+ let body = {
122
+ fileInfo: []
123
+ };
124
+ body.fileInfo.push(
125
+ {
126
+ "fileName": obj.type + "/" + obj.sdkName + ".umd.min.js",
127
+ "fileContent": jsContent,
128
+ "bucketName": "cloudcc-sdk",
129
+ }
130
+ )
131
+ let res = await post(this.options.devConsoleConfig.baseUrl + "/devconsole/cdn/uploadFile",
132
+ body);
133
+ if (res.returnCode == 200) {
134
+ console.error(chalk.green(`发布成功!`));
135
+ console.log();
136
+ } else {
137
+ console.error(chalk.red(`发布失败: ${res.returnInfo}`));
138
+ console.log();
139
+ }
140
+
141
+ return res;
142
+ }
143
+
144
+ /**
145
+ * 过滤出min.js文件
146
+ * @returns 过滤结果
147
+ */
148
+ filterFile() {
149
+ const jsPath = "build";
150
+ let jsPaths = [];
151
+ if (jsPath) {
152
+ jsPaths = fs.readdirSync(jsPath).filter((f) => {
153
+ return f.endsWith('umd.min.js');
154
+ }).map((item) => {
155
+ return path.join(jsPath, item);
156
+ });
157
+ }
158
+ return jsPaths;
159
+ }
160
+ }
161
161
  module.exports = Builder;
@@ -1,91 +1,91 @@
1
- const chalk = require("chalk")
2
- const inquirer = require("inquirer")
3
- const memFs = require("mem-fs")
4
- const memFsEditor = require("mem-fs-editor")
5
- const fs = require("fs")
6
- const path = require("path")
7
- const { checkUpdate } = require("../utils/checkVersion")
8
- /**
9
- * 创建自定组件开发模板项目
10
- */
11
- class Creator {
12
- constructor() {
13
- this.fs = memFsEditor.create(memFs.create());
14
- this.options = {
15
- name: "",
16
- description: ""
17
- }
18
- // 当前目录
19
- this.rootPath = path.resolve(__dirname, "../");
20
- // 模板目录
21
- this.tplDirPath = path.join(this.rootPath, "template");
22
- }
23
- // 初始化
24
- async init() {
25
- let res = await checkUpdate();
26
- if (!res) {
27
- console.log()
28
- console.log(chalk.green('欢迎使用CloudCC-CLI'));
29
- console.log()
30
- this.ask().then(answers => {
31
- this.options = Object.assign({}, this.options, answers);
32
- console.log(this.options);
33
- this.write();
34
- })
35
- }
36
- }
37
- // 命令行交互
38
- ask() {
39
- const prompt = [];
40
-
41
- prompt.push({
42
- type: "input",
43
- name: "name",
44
- message: "请输入项目名称",
45
- validate(input) {
46
- if (!input) {
47
- return "请输入项目名称"
48
- }
49
-
50
- if (fs.existsSync(input)) {
51
- return "项目名已存在"
52
- }
53
-
54
- return true;
55
- }
56
- });
57
- prompt.push({
58
- type: "input",
59
- name: "description",
60
- message: "请输入项目描述",
61
- })
62
- return inquirer.prompt(prompt)
63
- }
64
- // 拷贝和写数据
65
- write() {
66
- console.log();
67
- console.log(chalk.green("开始构建,请稍后"));
68
- const tplBuilder = require("../template/index");
69
- tplBuilder(this, this.options, () => {
70
- console.log();
71
- console.log(chalk.green('构建完成'));
72
- console.log();
73
- console.log(chalk.green(`运行项目: \n 1:cd ${this.options.name} \n 2:code . \n 3:npm install`));
74
- })
75
- }
76
-
77
- getTplPath(file) {
78
- return path.join(this.tplDirPath, file);
79
- }
80
-
81
- copyTpl(file, to, data = {}) {
82
- const tplPath = this.getTplPath(file);
83
- this.fs.copyTpl(tplPath, to, data);
84
- }
85
-
86
- copy(file, to) {
87
- const tplPath = this.getTplPath(file);
88
- this.fs.copy(tplPath, to)
89
- }
90
- }
1
+ const chalk = require("chalk")
2
+ const inquirer = require("inquirer")
3
+ const memFs = require("mem-fs")
4
+ const memFsEditor = require("mem-fs-editor")
5
+ const fs = require("fs")
6
+ const path = require("path")
7
+ const { checkUpdate } = require("../utils/checkVersion")
8
+ /**
9
+ * 创建自定组件开发模板项目
10
+ */
11
+ class Creator {
12
+ constructor() {
13
+ this.fs = memFsEditor.create(memFs.create());
14
+ this.options = {
15
+ name: "",
16
+ description: ""
17
+ }
18
+ // 当前目录
19
+ this.rootPath = path.resolve(__dirname, "../");
20
+ // 模板目录
21
+ this.tplDirPath = path.join(this.rootPath, "template");
22
+ }
23
+ // 初始化
24
+ async init() {
25
+ let res = await checkUpdate();
26
+ if (!res) {
27
+ console.log()
28
+ console.log(chalk.green('欢迎使用CloudCC-CLI'));
29
+ console.log()
30
+ this.ask().then(answers => {
31
+ this.options = Object.assign({}, this.options, answers);
32
+ console.log(this.options);
33
+ this.write();
34
+ })
35
+ }
36
+ }
37
+ // 命令行交互
38
+ ask() {
39
+ const prompt = [];
40
+
41
+ prompt.push({
42
+ type: "input",
43
+ name: "name",
44
+ message: "请输入项目名称",
45
+ validate(input) {
46
+ if (!input) {
47
+ return "请输入项目名称"
48
+ }
49
+
50
+ if (fs.existsSync(input)) {
51
+ return "项目名已存在"
52
+ }
53
+
54
+ return true;
55
+ }
56
+ });
57
+ prompt.push({
58
+ type: "input",
59
+ name: "description",
60
+ message: "请输入项目描述",
61
+ })
62
+ return inquirer.prompt(prompt)
63
+ }
64
+ // 拷贝和写数据
65
+ write() {
66
+ console.log();
67
+ console.log(chalk.green("开始构建,请稍后"));
68
+ const tplBuilder = require("../template/index");
69
+ tplBuilder(this, this.options, () => {
70
+ console.log();
71
+ console.log(chalk.green('构建完成'));
72
+ console.log();
73
+ console.log(chalk.green(`运行项目: \n 1:cd ${this.options.name} \n 2:code . \n 3:npm install`));
74
+ })
75
+ }
76
+
77
+ getTplPath(file) {
78
+ return path.join(this.tplDirPath, file);
79
+ }
80
+
81
+ copyTpl(file, to, data = {}) {
82
+ const tplPath = this.getTplPath(file);
83
+ this.fs.copyTpl(tplPath, to, data);
84
+ }
85
+
86
+ copy(file, to) {
87
+ const tplPath = this.getTplPath(file);
88
+ this.fs.copy(tplPath, to)
89
+ }
90
+ }
91
91
  module.exports = Creator;