jjb-cmd 2.2.2 → 2.2.3
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 +4 -0
- package/build.js +15 -0
- package/obf.config.json +3 -0
- package/package.json +1 -1
- package/src/new/cmd.auth/index.js +26 -1
- package/src/new/cmd.init/index.js +116 -1
- package/src/new/cmd.install/config.js +70 -1
- package/src/new/cmd.install/index.js +262 -1
- package/src/new/cmd.install/tools.js +230 -1
- package/src/new/cmd.install.app/index.js +27 -1
- package/src/new/cmd.jenkins/index.js +72 -1
- package/src/new/cmd.publish/index.js +197 -1
- package/src/new/cmd.push/index.js +76 -1
- package/src/new/cmd.push/java.js +148 -1
- package/src/new/cmd.push-set/index.js +205 -1
- package/src/new/cmd.refresh/index.js +65 -1
- package/src/new/cmd.reglist/index.js +23 -1
- package/src/new/cmd.rm-rf/index.js +58 -1
- package/src/new/cmd.version/index.js +35 -1
- package/src/old/cli.dva.register.saas.txt +40 -0
- package/src/old/cli.dva.register.spa.txt +22 -0
- package/src/old/cli.dva.router.saas.txt +210 -0
- package/src/old/cli.dva.router.spa.txt +119 -0
- package/src/old/cli.init.js +26 -1
- package/src/old/cli.install/config.js +206 -1
- package/src/old/cli.install/index.js +340 -1
- package/src/old/cli.install/tools.js +230 -1
- package/src/old/cli.merge.js +80 -1
- package/src/old/cli.pull.js +94 -1
- package/src/old/cli.pull2.js +377 -1
- package/src/old/cli.rm-rf.js +88 -1
- package/src/old/progress-bar.js +23 -1
- package/src/old/util.js +149 -1
@@ -1 +1,230 @@
|
|
1
|
-
|
1
|
+
const fs = require('fs');
|
2
|
+
const os = require('os');
|
3
|
+
const {
|
4
|
+
GIT_HOST,
|
5
|
+
GIT_TEMP_DIR,
|
6
|
+
CLOUD_PROJECT
|
7
|
+
} = require('./config');
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @description 删除全部
|
11
|
+
* @param path {string} 路径
|
12
|
+
*/
|
13
|
+
exports.f_rm_rf = function (path) {
|
14
|
+
if (fs.existsSync(path)) {
|
15
|
+
const list = fs.readdirSync(path);
|
16
|
+
for (let i = 0; i < list.length; i++) {
|
17
|
+
const item = list[ i ];
|
18
|
+
const vPath = `${path}/${item}`;
|
19
|
+
if (fs.statSync(vPath).isDirectory()) {
|
20
|
+
exports.f_rm_rf(vPath);
|
21
|
+
fs.rmdirSync(vPath);
|
22
|
+
} else {
|
23
|
+
fs.unlinkSync(vPath);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @typedef {object} GitResource
|
31
|
+
* @property {string} path
|
32
|
+
* @property {string} compress
|
33
|
+
* @property {string} repository
|
34
|
+
*/
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @description 拉取git资源
|
38
|
+
* @param installResources {Resource[]} 资源名称
|
39
|
+
* @return {GitResource[]}
|
40
|
+
*/
|
41
|
+
exports.f_pull_git_repository = function (installResources = []) {
|
42
|
+
return installResources.map(item => {
|
43
|
+
const resource = CLOUD_PROJECT[ item.name ] || undefined;
|
44
|
+
const template = os.tmpdir();
|
45
|
+
return {
|
46
|
+
path: `${template}\\${GIT_TEMP_DIR}\\${item.name}.zip`,
|
47
|
+
compress: `${template}\\${GIT_TEMP_DIR}\\${item.name}_zip`,
|
48
|
+
repository: `${GIT_HOST}/api/v4/projects/${resource.projectId}/repository/archive.zip?private_token=${resource.token}&ref=master`
|
49
|
+
};
|
50
|
+
});
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @description 扫描是否存在jjb.config.json
|
55
|
+
* @param root 路径
|
56
|
+
* @returns {boolean}
|
57
|
+
*/
|
58
|
+
exports.f_scan_jjb_config_json = function (root) {
|
59
|
+
return fs.existsSync(`${root}\\jjb.config.json`);
|
60
|
+
};
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @typedef {object} JJB_CONFIG_JSON
|
64
|
+
* @property {string} projectType
|
65
|
+
* @property {string} installTarget
|
66
|
+
* @property {Resource[]} installResources
|
67
|
+
*/
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @description 验证规则
|
71
|
+
* @param root {string} 路径
|
72
|
+
* @return {JJB_CONFIG_JSON}
|
73
|
+
*/
|
74
|
+
exports.f_scan_jjb_config_json_rules = function (root) {
|
75
|
+
let jjb_config_json = {};
|
76
|
+
try {
|
77
|
+
jjb_config_json = JSON.parse(fs.readFileSync(`${root}\\jjb.config.json`).toString());
|
78
|
+
} catch (e) {
|
79
|
+
console.log('【Error】:[jjb.config.json]文件解析失败,请确认是否配置正确。');
|
80
|
+
process.exit(0);
|
81
|
+
}
|
82
|
+
if (!('projectType' in jjb_config_json)) {
|
83
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要projectType属性。');
|
84
|
+
process.exit(0);
|
85
|
+
}
|
86
|
+
if (!('installTarget' in jjb_config_json)) {
|
87
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要installTarget属性。');
|
88
|
+
process.exit(0);
|
89
|
+
}
|
90
|
+
if (!('installResources' in jjb_config_json)) {
|
91
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要installResources属性。');
|
92
|
+
process.exit(0);
|
93
|
+
}
|
94
|
+
if (typeof jjb_config_json.projectType !== 'string') {
|
95
|
+
console.log('【Error】:[jjb.config.json.projectType]类型是一个string。');
|
96
|
+
process.exit(0);
|
97
|
+
}
|
98
|
+
if (![
|
99
|
+
'multi',
|
100
|
+
'spa',
|
101
|
+
'uniapp',
|
102
|
+
'micro-spa'
|
103
|
+
].includes(jjb_config_json.projectType)) {
|
104
|
+
console.log('【Error】:[jjb.config.json.projectType]配置无效,有效值<multi | spa | micro-spa | uniapp>。');
|
105
|
+
process.exit(0);
|
106
|
+
}
|
107
|
+
if (typeof jjb_config_json.installTarget !== 'string') {
|
108
|
+
console.log('【Error】:[jjb.config.json.installTarget]类型是一个string。');
|
109
|
+
process.exit(0);
|
110
|
+
}
|
111
|
+
if (![
|
112
|
+
'node_modules',
|
113
|
+
'src'
|
114
|
+
].includes(jjb_config_json.installTarget)) {
|
115
|
+
console.log('【Error】:[jjb.config.json.node_modules]配置无效,有效值<node_modules | src>。');
|
116
|
+
process.exit(0);
|
117
|
+
}
|
118
|
+
if (!Array.isArray(jjb_config_json.installResources)) {
|
119
|
+
console.log('【Error】:[jjb.config.json.installResources]类型是一个Array<string>。');
|
120
|
+
process.exit(0);
|
121
|
+
}
|
122
|
+
if (jjb_config_json.installResources.length === 0) {
|
123
|
+
console.log('【Error】:[jjb.config.json.installResources]无资源。');
|
124
|
+
process.exit(0);
|
125
|
+
}
|
126
|
+
const resources = exports.f_resolve_install_resources(jjb_config_json.installResources);
|
127
|
+
if (resources.map(item => item.name).filter(v => ![
|
128
|
+
'jjb-common',
|
129
|
+
'jjb-dva-runtime',
|
130
|
+
'jjb-common-lib',
|
131
|
+
'jjb-common-decorator',
|
132
|
+
'react-admin-component',
|
133
|
+
'vue-unisass-component'
|
134
|
+
].includes(v)).length !== 0) {
|
135
|
+
console.log('【Error】:[jjb.config.json.installResources]配置无效,有效值<common | react-admin-component | vue-unisass-component | jjb-common-decorator | jjb-dva-runtime | jjb-common-lib>。');
|
136
|
+
process.exit(0);
|
137
|
+
}
|
138
|
+
jjb_config_json.installResources = resources;
|
139
|
+
return jjb_config_json;
|
140
|
+
};
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @description 创建package.json
|
144
|
+
* @param path {string} 路径
|
145
|
+
* @param name {string} 包名
|
146
|
+
* @param version {string} 版本
|
147
|
+
*/
|
148
|
+
exports.f_create_package_json = function (path, name, version) {
|
149
|
+
fs.writeFileSync(`${path}\\package.json`, `{"name":"${name}","version":"${version}","main": "index.js"}`);
|
150
|
+
};
|
151
|
+
|
152
|
+
/**
|
153
|
+
* @typedef {object} Resource
|
154
|
+
* @property {string} name
|
155
|
+
* @property {string[]} importList
|
156
|
+
*/
|
157
|
+
|
158
|
+
/**
|
159
|
+
* @description 分析resources
|
160
|
+
* @param installResources
|
161
|
+
* @return {Resource[]}
|
162
|
+
*/
|
163
|
+
exports.f_resolve_install_resources = function (installResources = []) {
|
164
|
+
const resources = [];
|
165
|
+
if (Array.isArray(installResources)) {
|
166
|
+
installResources.forEach(resource => {
|
167
|
+
if (Array.isArray(resource)) {
|
168
|
+
const [ name, importList = [] ] = resource;
|
169
|
+
resources.push({
|
170
|
+
name,
|
171
|
+
importList
|
172
|
+
});
|
173
|
+
} else {
|
174
|
+
resources.push({
|
175
|
+
name: resource,
|
176
|
+
importList: []
|
177
|
+
});
|
178
|
+
}
|
179
|
+
});
|
180
|
+
}
|
181
|
+
return resources;
|
182
|
+
};
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @description 更新项目package.json文件
|
186
|
+
* @param path {string} 路径
|
187
|
+
* @param name {string} 包名
|
188
|
+
* @param version {string} 版本
|
189
|
+
*/
|
190
|
+
exports.f_update_project_package_json = function (path, name, version) {
|
191
|
+
const packageJSONFile = JSON.parse(fs.readFileSync(path).toString());
|
192
|
+
packageJSONFile.dependencies[ name ] = version;
|
193
|
+
fs.writeFileSync(path, JSON.stringify(packageJSONFile, null, 2));
|
194
|
+
};
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @description 复制文件
|
198
|
+
* @param originSrc
|
199
|
+
* @param targetSrc
|
200
|
+
*/
|
201
|
+
exports.f_file_copy = function (originSrc, targetSrc) {
|
202
|
+
fs.readdirSync(originSrc).forEach(dir => {
|
203
|
+
const oPath = `${originSrc}\\${dir}`;
|
204
|
+
const tPath = `${targetSrc}\\${dir}`;
|
205
|
+
if (fs.statSync(oPath).isDirectory()) {
|
206
|
+
fs.mkdirSync(tPath);
|
207
|
+
exports.f_file_copy(oPath, tPath);
|
208
|
+
} else {
|
209
|
+
fs.writeFileSync(tPath, fs.readFileSync(oPath).toString());
|
210
|
+
}
|
211
|
+
});
|
212
|
+
};
|
213
|
+
|
214
|
+
/**
|
215
|
+
* @description 替换文件操作
|
216
|
+
* @param source {[]} 替换源
|
217
|
+
* @param root {string} 路径
|
218
|
+
*/
|
219
|
+
exports.f_content_replace = function (source = [], root) {
|
220
|
+
source.forEach(item => {
|
221
|
+
const path = root + item.path;
|
222
|
+
if (fs.existsSync(path)) {
|
223
|
+
let content = fs.readFileSync(path).toString();
|
224
|
+
item.replace.forEach(rep => {
|
225
|
+
content = content.replace(rep[ 0 ], rep[ 1 ]);
|
226
|
+
});
|
227
|
+
fs.writeFileSync(path, content);
|
228
|
+
}
|
229
|
+
});
|
230
|
+
};
|
@@ -1 +1,27 @@
|
|
1
|
-
|
1
|
+
const child_process = require('child_process');
|
2
|
+
const path = require('path');
|
3
|
+
const fs = require('fs');
|
4
|
+
|
5
|
+
module.exports = registry_source => {
|
6
|
+
|
7
|
+
if (!['npm', 'yarn'].includes(registry_source)) {
|
8
|
+
console.log(`【Error】:no registry source, available:[npm, yarn]`);
|
9
|
+
process.exit(0);
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* 当前根路径
|
14
|
+
* @type {Promise<void> | Promise<string>}
|
15
|
+
*/
|
16
|
+
const root_path = path.resolve('./');
|
17
|
+
|
18
|
+
console.log("install modules please wait....");
|
19
|
+
child_process.execSync(registry_source === 'yarn' ? 'yarn' : 'npm install', { cwd: root_path });
|
20
|
+
if (!fs.existsSync(`${root_path}/.git`)) {
|
21
|
+
console.log("git init please wait....");
|
22
|
+
child_process.execSync(`git init`, { cwd: root_path });
|
23
|
+
}
|
24
|
+
console.log("install husky please wait....");
|
25
|
+
child_process.execSync(`npx husky install`, { cwd: root_path });
|
26
|
+
console.log("Finish!");
|
27
|
+
};
|
@@ -1 +1,72 @@
|
|
1
|
-
const
|
1
|
+
const path = require('path');
|
2
|
+
const fs = require('fs');
|
3
|
+
const Jenkins = require('jenkins');
|
4
|
+
|
5
|
+
module.exports = arguments => {
|
6
|
+
|
7
|
+
const authPath = path.join(__dirname, '../../../.auth');
|
8
|
+
if (!fs.existsSync(authPath)) {
|
9
|
+
console.log(`【Error】:no auth login`);
|
10
|
+
process.exit(0);
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 当前根路径
|
15
|
+
* @type {Promise<void> | Promise<string>}
|
16
|
+
*/
|
17
|
+
const root_path = path.resolve('./');
|
18
|
+
|
19
|
+
/**
|
20
|
+
* jjb配置文件路径
|
21
|
+
* @type {string}
|
22
|
+
*/
|
23
|
+
const config_json_path = `${root_path}\\jjb.config.js`;
|
24
|
+
/**
|
25
|
+
* 获取配置对象
|
26
|
+
*/
|
27
|
+
const jjbConfig = require(config_json_path);
|
28
|
+
/**
|
29
|
+
* 获取当前处理环境配置信息
|
30
|
+
*/
|
31
|
+
const envData = jjbConfig.environment[arguments];
|
32
|
+
|
33
|
+
const jenkinsData = envData.jenkins || {};
|
34
|
+
|
35
|
+
//分支名
|
36
|
+
const branchName = jenkinsData.branchName;
|
37
|
+
//项目名
|
38
|
+
const jobName = jenkinsData.jobName;
|
39
|
+
//主机
|
40
|
+
const jenkinsHost = jenkinsData.jenkinsHost;
|
41
|
+
//登录用户
|
42
|
+
const jenkinsUserName = jenkinsData.jenkinsUserName;
|
43
|
+
//登录密码
|
44
|
+
const jenkinsPassword = jenkinsData.jenkinsPassword;
|
45
|
+
//namespace
|
46
|
+
const jenkinsNamespace = jenkinsData.jenkinsNamespace;
|
47
|
+
|
48
|
+
//发起请求
|
49
|
+
const jenkins = new Jenkins({
|
50
|
+
// https://用户名:密码/token@jenkins地址
|
51
|
+
baseUrl: `http://${jenkinsUserName}:${jenkinsPassword}@${jenkinsHost}`,
|
52
|
+
});
|
53
|
+
|
54
|
+
try {
|
55
|
+
const result = jenkins.job.build({
|
56
|
+
name: jobName,
|
57
|
+
// jenkins中需要的参数,若无则为空
|
58
|
+
parameters: {
|
59
|
+
app_Version: branchName,
|
60
|
+
build_version: arguments,
|
61
|
+
k8s_namespace: jenkinsNamespace,
|
62
|
+
branch: branchName,
|
63
|
+
merge: true
|
64
|
+
},
|
65
|
+
token: jenkinsPassword
|
66
|
+
})
|
67
|
+
console.log('开始构建...', result)
|
68
|
+
} catch (error) {
|
69
|
+
console.error('error: ', error);
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|
@@ -1 +1,197 @@
|
|
1
|
-
|
1
|
+
const path = require('path');
|
2
|
+
const fs = require('fs');
|
3
|
+
const os = require('os');
|
4
|
+
const axios = require('axios');
|
5
|
+
const readline = require('readline');
|
6
|
+
const io = readline.createInterface({
|
7
|
+
input: process.stdin,
|
8
|
+
output: process.stdout
|
9
|
+
});
|
10
|
+
const child_process = require('child_process');
|
11
|
+
const { getApiHost } = require('../cmd.install/config');
|
12
|
+
|
13
|
+
module.exports = version => {
|
14
|
+
|
15
|
+
const authPath = path.join(__dirname, '../../../.auth');
|
16
|
+
if (!fs.existsSync(authPath)) {
|
17
|
+
console.log(`【Error】:no auth login`);
|
18
|
+
process.exit(0);
|
19
|
+
}
|
20
|
+
|
21
|
+
const [ username, password ] = fs.readFileSync(authPath).toString().split('/');
|
22
|
+
axios.post(`${getApiHost()}/api/auth`, {
|
23
|
+
username,
|
24
|
+
password
|
25
|
+
}).then(res => {
|
26
|
+
if (res.data.status) {
|
27
|
+
|
28
|
+
/**
|
29
|
+
* 下发数据根路径
|
30
|
+
* @type {string}
|
31
|
+
*/
|
32
|
+
const root_path = path.resolve('./');
|
33
|
+
|
34
|
+
console.log('Please wait, build ...');
|
35
|
+
if (fs.existsSync(root_path + '/yarn.lock')) {
|
36
|
+
child_process.execSync('yarn build:production', { cwd: root_path });
|
37
|
+
} else {
|
38
|
+
child_process.execSync('npm run build:production', { cwd: root_path });
|
39
|
+
}
|
40
|
+
|
41
|
+
const dist_folder_path = `${root_path}\\dist\\index.js`;
|
42
|
+
const package_json_path = `${root_path}\\package.json`;
|
43
|
+
const readme_path = `${root_path}\\README.md`;
|
44
|
+
const thumbnail_png_path = `${root_path}\\thumbnail.png`;
|
45
|
+
const log_text = [
|
46
|
+
os.hostname(),
|
47
|
+
os.platform(),
|
48
|
+
os.arch(),
|
49
|
+
new Date().toString()
|
50
|
+
];
|
51
|
+
|
52
|
+
const package_json_file = JSON.parse(fs.readFileSync(path.join(__dirname, '../../../package.json')).toString());
|
53
|
+
const {
|
54
|
+
version: cmd_version
|
55
|
+
} = package_json_file;
|
56
|
+
|
57
|
+
const pushData = {
|
58
|
+
username,
|
59
|
+
cmd_version,
|
60
|
+
hostname: os.hostname(),
|
61
|
+
platform: os.platform()
|
62
|
+
};
|
63
|
+
|
64
|
+
if (fs.existsSync(package_json_path)) {
|
65
|
+
if (fs.existsSync(dist_folder_path)) {
|
66
|
+
pushData.package_version = version
|
67
|
+
? version
|
68
|
+
: 0;
|
69
|
+
pushData.package_content = fs.readFileSync(dist_folder_path).toString();
|
70
|
+
pushData.component_config_content = {};
|
71
|
+
|
72
|
+
const dist_content = fs.readFileSync(dist_folder_path).toString();
|
73
|
+
|
74
|
+
|
75
|
+
const matches = dist_content.match(/(window\[).+?(\.componentKey|.+]={)/img);
|
76
|
+
if (matches && matches.length){
|
77
|
+
|
78
|
+
const infoMatches = dist_content.match(/componentKey.+([{,]info:\s{0,}{)/img);
|
79
|
+
if (infoMatches && infoMatches.length) {
|
80
|
+
let infoStr = '{';
|
81
|
+
const infoStr1 = dist_content.split(infoMatches[0])[1];
|
82
|
+
for (let i = 0; i < infoStr1.length; i++){
|
83
|
+
infoStr += infoStr1[i];
|
84
|
+
if (infoStr1[i] === '}') {
|
85
|
+
try {
|
86
|
+
const currJson = new Function('return '+infoStr)();
|
87
|
+
pushData.component_config_content = {
|
88
|
+
...currJson,
|
89
|
+
defaultSetting: {}
|
90
|
+
};
|
91
|
+
} catch (e) {
|
92
|
+
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
} else {
|
97
|
+
console.log('【Error】:window暴露配置缺少info基础信息');
|
98
|
+
process.exit(0);
|
99
|
+
}
|
100
|
+
|
101
|
+
const settingsMatches = dist_content.match(/componentKey.+([{,]settings:\s{0,}{)/img);
|
102
|
+
if (settingsMatches && settingsMatches.length) {
|
103
|
+
let settingsStr = '{';
|
104
|
+
const settingsStr1 = dist_content.split(settingsMatches[0])[1];
|
105
|
+
for (let i = 0; i < settingsStr1.length; i++){
|
106
|
+
settingsStr += settingsStr1[i];
|
107
|
+
if (settingsStr1[i] === '}') {
|
108
|
+
try {
|
109
|
+
const currJson = new Function('return '+settingsStr)();
|
110
|
+
pushData.component_config_content.defaultSetting = currJson;
|
111
|
+
} catch (e) {
|
112
|
+
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
pushData.component_config_content = JSON.stringify(pushData.component_config_content);
|
118
|
+
} else {
|
119
|
+
console.log('【Error】:window暴露配置缺少info基础信息');
|
120
|
+
process.exit(0);
|
121
|
+
}
|
122
|
+
|
123
|
+
// let currStr = matches[0].split('=')[1];
|
124
|
+
// const str= dist_content.split(matches[0])[1];
|
125
|
+
// for (let i = 0; i< str.length; i++){
|
126
|
+
// currStr += str[i]
|
127
|
+
// if (str[i] === '}'){
|
128
|
+
// try {
|
129
|
+
// const currJson = new Function('return '+currStr)();
|
130
|
+
// if (!currJson.info) {
|
131
|
+
// console.log('【Error】:window暴露配置缺少info基础信息');
|
132
|
+
// process.exit(0);
|
133
|
+
// }
|
134
|
+
// if (!currJson.settings) {
|
135
|
+
// console.log('【Error】:window暴露配置缺少settings基础信息');
|
136
|
+
// process.exit(0);
|
137
|
+
// }
|
138
|
+
// pushData.component_config_content = JSON.stringify({
|
139
|
+
// ...currJson.info,
|
140
|
+
// defaultSetting: currJson.settings
|
141
|
+
// });
|
142
|
+
// break;
|
143
|
+
// }
|
144
|
+
// catch (e) {
|
145
|
+
// console.log(e)
|
146
|
+
// }
|
147
|
+
// }
|
148
|
+
//
|
149
|
+
// }
|
150
|
+
} else {
|
151
|
+
console.log('【Error】:请在window下暴露配置信息');
|
152
|
+
process.exit(0);
|
153
|
+
}
|
154
|
+
|
155
|
+
if (fs.existsSync(readme_path)) {
|
156
|
+
pushData.readme_content = fs.readFileSync(readme_path).toString();
|
157
|
+
} else {
|
158
|
+
console.log('【Error】:请必须包含README.md说明文件');
|
159
|
+
process.exit(0);
|
160
|
+
}
|
161
|
+
|
162
|
+
if (!fs.existsSync(thumbnail_png_path)) {
|
163
|
+
console.log('【Error】:组件根目录必须包含thumbnail.png缩略图片');
|
164
|
+
process.exit(0);
|
165
|
+
} else {
|
166
|
+
const thumbnailData = fs.readFileSync(thumbnail_png_path);
|
167
|
+
const thumbnail_base64 = Buffer.from(thumbnailData).toString('base64');
|
168
|
+
pushData.thumbnail_base64 = thumbnail_base64;
|
169
|
+
}
|
170
|
+
|
171
|
+
io.question('请输入此次提交信息,按Enter确认:', function (message) {
|
172
|
+
pushData.message = message || 'no message';
|
173
|
+
axios.post(`${getApiHost()}/api/file/publish`, pushData).then(res => {
|
174
|
+
console.log(res.data.message);
|
175
|
+
process.exit(0);
|
176
|
+
}).catch(e => {
|
177
|
+
console.log(e);
|
178
|
+
console.log('网络异常。');
|
179
|
+
process.exit(0);
|
180
|
+
});
|
181
|
+
});
|
182
|
+
} else {
|
183
|
+
console.log('发布失败!根目录缺少‘dist/index.js’文件,无法完成发布。');
|
184
|
+
process.exit(0);
|
185
|
+
}
|
186
|
+
} else {
|
187
|
+
console.log('发布失败!根目录缺少‘package.json’文件,无法完成发布。');
|
188
|
+
process.exit(0);
|
189
|
+
}
|
190
|
+
} else {
|
191
|
+
console.log('Auth Fail!');
|
192
|
+
}
|
193
|
+
}).catch(e => {
|
194
|
+
console.log(e);
|
195
|
+
console.log('Auth NetWork Fail!');
|
196
|
+
});
|
197
|
+
};
|
@@ -1 +1,76 @@
|
|
1
|
-
const
|
1
|
+
const path = require('path');
|
2
|
+
const fs = require('fs');
|
3
|
+
const os = require('os');
|
4
|
+
const axios = require('axios');
|
5
|
+
const { getApiHost } = require('../cmd.install/config');
|
6
|
+
|
7
|
+
module.exports = version => {
|
8
|
+
|
9
|
+
const authPath = path.join(__dirname, '../../../.auth');
|
10
|
+
if (!fs.existsSync(authPath)) {
|
11
|
+
console.log(`【Error】:no auth login`);
|
12
|
+
process.exit(0);
|
13
|
+
}
|
14
|
+
|
15
|
+
const [username , password] = fs.readFileSync(authPath).toString().split('/');
|
16
|
+
axios.post(`${getApiHost()}/api/auth`, {
|
17
|
+
username,
|
18
|
+
password
|
19
|
+
}).then(res => {
|
20
|
+
if (res.data.status) {
|
21
|
+
/**
|
22
|
+
* 下发数据根路径
|
23
|
+
* @type {string}
|
24
|
+
*/
|
25
|
+
const root_path = path.resolve('./');
|
26
|
+
const dist_folder_path = `${root_path}\\dist\\index.js`;
|
27
|
+
const package_json_path = `${root_path}\\package.json`;
|
28
|
+
|
29
|
+
const log_text = [
|
30
|
+
os.hostname(),
|
31
|
+
os.platform(),
|
32
|
+
os.arch(),
|
33
|
+
new Date().toString(),
|
34
|
+
JSON.stringify(os.networkInterfaces(), null, '\t')
|
35
|
+
];
|
36
|
+
|
37
|
+
if (fs.existsSync(package_json_path)) {
|
38
|
+
if (fs.existsSync(dist_folder_path)) {
|
39
|
+
const package_json_file = JSON.parse(fs.readFileSync(package_json_path).toString());
|
40
|
+
const {
|
41
|
+
name: package_name,
|
42
|
+
version: package_version
|
43
|
+
} = package_json_file;
|
44
|
+
log_text.push(JSON.stringify(package_json_file));
|
45
|
+
|
46
|
+
axios.post(`${getApiHost()}/api/file/push`, {
|
47
|
+
username,
|
48
|
+
log_text: log_text.join('\n'),
|
49
|
+
package_name,
|
50
|
+
package_version: version
|
51
|
+
? version
|
52
|
+
: package_version,
|
53
|
+
package_content: fs.readFileSync(dist_folder_path).toString()
|
54
|
+
}).then(res => {
|
55
|
+
console.log(res.data.message);
|
56
|
+
process.exit(0);
|
57
|
+
}).catch(e => {
|
58
|
+
console.log(e);
|
59
|
+
console.log('网络异常。');
|
60
|
+
process.exit(0);
|
61
|
+
});
|
62
|
+
} else {
|
63
|
+
console.log('发布失败!根目录缺少‘dist/index.js’文件,无法完成发布。');
|
64
|
+
process.exit(0);
|
65
|
+
}
|
66
|
+
} else {
|
67
|
+
console.log('发布失败!根目录缺少‘package.json’文件,无法完成发布。');
|
68
|
+
process.exit(0);
|
69
|
+
}
|
70
|
+
} else {
|
71
|
+
console.log('Auth Fail!');
|
72
|
+
}
|
73
|
+
}).catch(e => {
|
74
|
+
console.log('Auth NetWork Fail!');
|
75
|
+
});
|
76
|
+
};
|