tt-minigame-ide-cli 1.0.2 → 2.0.0-alpha.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/README.md +5 -98
- package/bin/tmg.js +4 -161
- package/dist/cli.js +1 -0
- package/dist/index.js +1 -0
- package/dist/miniprogram-utils/src/constants/error.d.ts +41 -0
- package/dist/miniprogram-utils/src/constants/index.d.ts +217 -0
- package/dist/miniprogram-utils/src/constants/project.d.ts +3 -0
- package/dist/miniprogram-utils/src/constants/slardar-events/update-events.d.ts +24 -0
- package/dist/miniprogram-utils/src/data/app.d.ts +30 -0
- package/dist/miniprogram-utils/src/data/ext.d.ts +6 -0
- package/dist/miniprogram-utils/src/data/jsons.d.ts +23 -0
- package/dist/miniprogram-utils/src/data/project.d.ts +124 -0
- package/dist/miniprogram-utils/src/electron-monitor/common/tea-sdk.d.ts +17 -0
- package/dist/miniprogram-utils/src/formation.d.ts +17 -0
- package/dist/miniprogram-utils/src/network/axios.d.ts +28 -0
- package/dist/tt-ide-cli/src/features/audit.d.ts +9 -0
- package/dist/tt-ide-cli/src/features/cli-login.d.ts +1 -0
- package/dist/tt-ide-cli/src/features/config.d.ts +3 -0
- package/dist/tt-ide-cli/src/features/create.d.ts +7 -0
- package/dist/tt-ide-cli/src/features/login.d.ts +18 -0
- package/dist/tt-ide-cli/src/features/meta.d.ts +23 -0
- package/dist/tt-ide-cli/src/features/microgame/cloud-compile.d.ts +75 -0
- package/dist/tt-ide-cli/src/features/microgame/index.d.ts +3 -0
- package/dist/tt-ide-cli/src/features/microgame/meta.d.ts +1 -0
- package/dist/tt-ide-cli/src/features/microgame/utils/file-system.d.ts +13 -0
- package/dist/tt-ide-cli/src/features/microgame/utils/package.d.ts +22 -0
- package/dist/tt-ide-cli/src/features/microgame/utils/settings.d.ts +48 -0
- package/dist/tt-ide-cli/src/features/microgame/utils/source.type.d.ts +35 -0
- package/dist/tt-ide-cli/src/features/npm.d.ts +10 -0
- package/dist/tt-ide-cli/src/features/open.d.ts +3 -0
- package/dist/tt-ide-cli/src/features/packages.d.ts +53 -0
- package/dist/tt-ide-cli/src/features/preview.d.ts +80 -0
- package/dist/tt-ide-cli/src/features/third-party.d.ts +9 -0
- package/dist/tt-ide-cli/src/index.d.ts +22 -0
- package/dist/tt-ide-cli/src/monitor/cli-monitor.d.ts +15 -0
- package/dist/tt-ide-cli/src/monitor/constants.d.ts +7 -0
- package/dist/tt-ide-cli/src/monitor/index.d.ts +2 -0
- package/dist/tt-ide-cli/src/types.d.ts +44 -0
- package/dist/tt-ide-cli/src/utils/constants.d.ts +3 -0
- package/dist/tt-ide-cli/src/utils/cookie.d.ts +6 -0
- package/dist/tt-ide-cli/src/utils/logger.d.ts +19 -0
- package/dist/tt-ide-cli/src/utils/metrics.d.ts +67 -0
- package/dist/tt-ide-cli/src/utils/qrcode.d.ts +64 -0
- package/dist/tt-ide-cli/src/utils/util.d.ts +56 -0
- package/dist/tt-minigame-ide-cli/src/cli.d.ts +1 -0
- package/dist/tt-minigame-ide-cli/src/index.d.ts +1 -0
- package/dist/tt-minigame-ide-cli/src/types.d.ts +43 -0
- package/package.json +49 -26
- package/.yarnrc +0 -1
- package/LICENSE +0 -21
- package/README.en.md +0 -104
- package/lib/auth.js +0 -145
- package/lib/build-npm.js +0 -22
- package/lib/create.js +0 -106
- package/lib/index.d.ts +0 -23
- package/lib/index.js +0 -79
- package/lib/preview.js +0 -92
- package/lib/upload.js +0 -133
- package/lib/util/check.js +0 -84
- package/lib/util/config.js +0 -41
- package/lib/util/cookie.js +0 -36
- package/lib/util/helper.js +0 -245
- package/lib/util/logger.js +0 -54
- package/lib/util/qrcode.js +0 -34
- package/lib/util/request.js +0 -396
- package/lib/util/version.js +0 -27
- package/lib/version.js +0 -44
package/lib/util/logger.js
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
const readline = require('readline');
|
2
|
-
const chalk = require('chalk');
|
3
|
-
|
4
|
-
function formatTitle(severity, message) {
|
5
|
-
return chalk[bgColor(severity)].black('', message, '');
|
6
|
-
}
|
7
|
-
|
8
|
-
function formatText(severity, message) {
|
9
|
-
return chalk[textColor(severity)](message);
|
10
|
-
}
|
11
|
-
|
12
|
-
function textColor(severity) {
|
13
|
-
switch (severity.toLowerCase()) {
|
14
|
-
case 'success': return 'green';
|
15
|
-
case 'info': return 'blue';
|
16
|
-
case 'note': return 'white';
|
17
|
-
case 'warning': return 'yellow';
|
18
|
-
case 'error': return 'red';
|
19
|
-
default: return 'red';
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
function bgColor(severity) {
|
24
|
-
const color = textColor(severity);
|
25
|
-
return 'bg'+ capitalizeFirstLetter(color)
|
26
|
-
}
|
27
|
-
|
28
|
-
function capitalizeFirstLetter(string) {
|
29
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
30
|
-
}
|
31
|
-
|
32
|
-
function outputResult(severity, title, subtitle) {
|
33
|
-
const titleFormatted = formatTitle(severity, title);
|
34
|
-
const subTitleFormatted = formatText(severity, subtitle);
|
35
|
-
const message = `${titleFormatted} ${subTitleFormatted}`;
|
36
|
-
console.log(message);
|
37
|
-
}
|
38
|
-
|
39
|
-
function clearConsole(title) {
|
40
|
-
if (process.stdout.isTTY) {
|
41
|
-
const blank = '\n'.repeat(process.stdout.rows);
|
42
|
-
console.log(blank);
|
43
|
-
readline.cursorTo(process.stdout, 0, 0);
|
44
|
-
readline.clearScreenDown(process.stdout);
|
45
|
-
if (title) {
|
46
|
-
console.log(title);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
module.exports = {
|
52
|
-
clearConsole,
|
53
|
-
outputResult
|
54
|
-
}
|
package/lib/util/qrcode.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
const QRCode = require('qrcode');
|
2
|
-
const chalk = require('chalk');
|
3
|
-
|
4
|
-
function generateQrCode(url, options) {
|
5
|
-
if (options.small) {
|
6
|
-
console.log(`${chalk.yellow('small QR Code may not work in some environments')}\n`);
|
7
|
-
}
|
8
|
-
|
9
|
-
QRCode.toString(url, { type: 'terminal', small: options.small }, function (err, str) {
|
10
|
-
if (err) {
|
11
|
-
throw Error(err);
|
12
|
-
}
|
13
|
-
console.log(str);
|
14
|
-
})
|
15
|
-
|
16
|
-
if (options.copy) {
|
17
|
-
require('clipboardy').writeSync(url);
|
18
|
-
copied = chalk.dim('(copied to clipboard)');
|
19
|
-
console.log(`${chalk.cyan(JSON.stringify(url))} ${copied}`);
|
20
|
-
}
|
21
|
-
|
22
|
-
if (options.output) {
|
23
|
-
QRCode.toFile(options.output, url, { type: 'png' }, function (err) {
|
24
|
-
console.log(chalk.yellow(`Save qrcode image to ${options.output}`));
|
25
|
-
if (err) {
|
26
|
-
throw Error(err);
|
27
|
-
}
|
28
|
-
})
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
module.exports = {
|
33
|
-
generateQrCode,
|
34
|
-
};
|
package/lib/util/request.js
DELETED
@@ -1,396 +0,0 @@
|
|
1
|
-
const axios = require('axios');
|
2
|
-
const FormData = require('form-data');
|
3
|
-
const querystring = require('querystring');
|
4
|
-
const url = require('url');
|
5
|
-
const fs = require('fs');
|
6
|
-
const execa = require('execa');
|
7
|
-
const compareVersions = require('compare-versions');
|
8
|
-
const {
|
9
|
-
getUserCookies
|
10
|
-
} = require('./cookie');
|
11
|
-
const {
|
12
|
-
compileErrFormat,
|
13
|
-
getPackageName
|
14
|
-
} = require('./helper');
|
15
|
-
const {
|
16
|
-
getVersion
|
17
|
-
} = require('./version');
|
18
|
-
const useBoeRequest = getVersion().includes('test');
|
19
|
-
const URL = require('url');
|
20
|
-
const baseParams = {
|
21
|
-
aid: 1365
|
22
|
-
};
|
23
|
-
const VERIFICATION_CODE_URL = '/passport/web/send_code';
|
24
|
-
const MOBILE_LOGIN_URL = '/passport/web/sms_login';
|
25
|
-
const EMAIL_LOGIN_URL = '/passport/web/email/login';
|
26
|
-
const GET_USER_INFO = '/api/v1/user';
|
27
|
-
const BASE_URL = useBoeRequest ? 'http://developer-boe.toutiao.com' : 'https://developer.toutiao.com';
|
28
|
-
const REFERER = 'developer.toutiao.com';
|
29
|
-
axios.defaults.baseURL = BASE_URL;
|
30
|
-
|
31
|
-
// 为请求添加referer
|
32
|
-
axios.interceptors.request.use(config => {
|
33
|
-
config.headers.Referer = REFERER;
|
34
|
-
if (config.data instanceof FormData) {
|
35
|
-
Object.assign(config.headers, config.data.getHeaders());
|
36
|
-
}
|
37
|
-
if (config.proxy) {
|
38
|
-
const parseURL = URL.parse(config.proxy.host);
|
39
|
-
config.httpsAgent = require('tunnel').httpsOverHttp({
|
40
|
-
proxy: {
|
41
|
-
host: parseURL.host,
|
42
|
-
port: config.proxy.port,
|
43
|
-
},
|
44
|
-
rejectUnauthorized: false
|
45
|
-
});
|
46
|
-
config.proxy = false;
|
47
|
-
}
|
48
|
-
return config;
|
49
|
-
})
|
50
|
-
|
51
|
-
exports.getMobileVerificationCode = function (mobile, proxy) {
|
52
|
-
const verificationOptions = {
|
53
|
-
method: 'get',
|
54
|
-
url: VERIFICATION_CODE_URL,
|
55
|
-
params: {
|
56
|
-
...baseParams,
|
57
|
-
type: 24,
|
58
|
-
mobile
|
59
|
-
},
|
60
|
-
headers: {
|
61
|
-
'User-Agent': 'bytedanceide'
|
62
|
-
}
|
63
|
-
}
|
64
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
65
|
-
const proxySplitArr = proxy.split(':');
|
66
|
-
const proxyPort = proxySplitArr.pop();
|
67
|
-
const proxyHost = proxySplitArr.join(':');
|
68
|
-
verificationOptions.proxy = {
|
69
|
-
host: proxyHost,
|
70
|
-
port: proxyPort
|
71
|
-
}
|
72
|
-
}
|
73
|
-
return axios(verificationOptions).then(res => {
|
74
|
-
const isSuccess = res.data.message === 'success';
|
75
|
-
// Not send res.data.data.description temporarily,because the tip is not for i18n
|
76
|
-
return {
|
77
|
-
success: isSuccess,
|
78
|
-
// msg: !isSuccess ? (res.data.data.description || 'Get verification code fail, please try later') : ''
|
79
|
-
msg: !isSuccess ? 'Get verification code fail, please try later' : ''
|
80
|
-
}
|
81
|
-
}).catch(err => {
|
82
|
-
return {
|
83
|
-
success: false,
|
84
|
-
msg: err.message
|
85
|
-
}
|
86
|
-
});
|
87
|
-
}
|
88
|
-
|
89
|
-
exports.userLogin = function (type, params, proxy) {
|
90
|
-
const userLoginOptions = {
|
91
|
-
url: type === 'mobile' ? MOBILE_LOGIN_URL : EMAIL_LOGIN_URL,
|
92
|
-
method: 'POST',
|
93
|
-
data: querystring.stringify({
|
94
|
-
...baseParams,
|
95
|
-
...params
|
96
|
-
}),
|
97
|
-
headers: {
|
98
|
-
'content-type': 'application/x-www-form-urlencoded'
|
99
|
-
}
|
100
|
-
}
|
101
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
102
|
-
const proxySplitArr = proxy.split(':');
|
103
|
-
const proxyPort = proxySplitArr.pop();
|
104
|
-
const proxyHost = proxySplitArr.join(':');
|
105
|
-
userLoginOptions.proxy = {
|
106
|
-
host: proxyHost,
|
107
|
-
port: proxyPort
|
108
|
-
}
|
109
|
-
}
|
110
|
-
return axios(userLoginOptions).then(res => {
|
111
|
-
const isSuccess = res.data.message === 'success';
|
112
|
-
return {
|
113
|
-
success: isSuccess,
|
114
|
-
cookies: res.headers['set-cookie'],
|
115
|
-
msg: !isSuccess ? (res.data.data.description || 'Login failed, please try again') : ''
|
116
|
-
}
|
117
|
-
}).catch(err => {
|
118
|
-
return {
|
119
|
-
success: false,
|
120
|
-
msg: err.message
|
121
|
-
}
|
122
|
-
});
|
123
|
-
}
|
124
|
-
|
125
|
-
exports.getUserData = function (proxy) {
|
126
|
-
const userDataOption = {
|
127
|
-
params: {},
|
128
|
-
headers: {
|
129
|
-
Cookie: getUserCookies()
|
130
|
-
}
|
131
|
-
}
|
132
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
133
|
-
const proxySplitArr = proxy.split(':');
|
134
|
-
const proxyPort = proxySplitArr.pop();
|
135
|
-
const proxyHost = proxySplitArr.join(':');
|
136
|
-
userDataOption.proxy = {
|
137
|
-
host: proxyHost,
|
138
|
-
port: proxyPort
|
139
|
-
}
|
140
|
-
}
|
141
|
-
return axios.get(GET_USER_INFO, userDataOption).then(res => {
|
142
|
-
const isSuccess = !res.data.error;
|
143
|
-
const userData = {
|
144
|
-
username: res.data.name || '',
|
145
|
-
avatar: res.data.avatar || '',
|
146
|
-
developerId: res.data.developer_id || '',
|
147
|
-
mobile: res.data.mobile || '',
|
148
|
-
email: res.data.email || '',
|
149
|
-
auditStatus: res.data.audit_status || 0,
|
150
|
-
uid: res.data.uid
|
151
|
-
};
|
152
|
-
return {
|
153
|
-
success: isSuccess,
|
154
|
-
userData,
|
155
|
-
msg: !isSuccess ? 'Login fail, please try later' : ''
|
156
|
-
}
|
157
|
-
}).catch(err => {
|
158
|
-
return {
|
159
|
-
success: false,
|
160
|
-
msg: err.message
|
161
|
-
}
|
162
|
-
});
|
163
|
-
}
|
164
|
-
|
165
|
-
exports.uploadProject = function ({
|
166
|
-
type,
|
167
|
-
appId,
|
168
|
-
zipPath,
|
169
|
-
versionInfo,
|
170
|
-
updateInfo,
|
171
|
-
proxy,
|
172
|
-
gameConfig,
|
173
|
-
}) {
|
174
|
-
return new Promise(function (resolve, reject) {
|
175
|
-
let path;
|
176
|
-
const form = new FormData();
|
177
|
-
if (type === 'preview') {
|
178
|
-
// path = `/api/v2/app/${appId}/preview`
|
179
|
-
path = `/api/developer/ide/microgame/v1/preview?appid=${appId}`
|
180
|
-
} else {
|
181
|
-
// path = `/api/v2/app/${appId}/testing`
|
182
|
-
path = `/api/developer/ide/microgame/v1/testing?appid=${appId}`
|
183
|
-
form.append('version', versionInfo);
|
184
|
-
form.append('intro', updateInfo);
|
185
|
-
}
|
186
|
-
// form.append('render_type', 3);
|
187
|
-
form.append('source', fs.createReadStream(zipPath));
|
188
|
-
form.append('local_compile_version', '4.0.0-rc.12.ide');
|
189
|
-
form.append('subpackage', String((gameConfig.subPackages || gameConfig.subpackages || []).length > 0));
|
190
|
-
const uploadOptions = {
|
191
|
-
method: 'put',
|
192
|
-
headers: {
|
193
|
-
'Cookie': getUserCookies()
|
194
|
-
},
|
195
|
-
url: path,
|
196
|
-
form,
|
197
|
-
maxBodyLength: Infinity,
|
198
|
-
maxContentLength: Infinity,
|
199
|
-
}
|
200
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
201
|
-
const proxySplitArr = proxy.split(':');
|
202
|
-
const proxyPort = proxySplitArr.pop();
|
203
|
-
const proxyHost = proxySplitArr.join(':');
|
204
|
-
uploadOptions.proxy = {
|
205
|
-
host: proxyHost,
|
206
|
-
port: proxyPort
|
207
|
-
}
|
208
|
-
}
|
209
|
-
axios.put(path, form, uploadOptions).then(res => {
|
210
|
-
if (res.data && res.data.error === 0) {
|
211
|
-
resolve();
|
212
|
-
} else {
|
213
|
-
reject(res.data.message)
|
214
|
-
}
|
215
|
-
}).catch(err => {
|
216
|
-
reject(err.message);
|
217
|
-
});
|
218
|
-
})
|
219
|
-
}
|
220
|
-
|
221
|
-
exports.getCompileProgress = function (appId, proxy) {
|
222
|
-
const compileProgressOption = {
|
223
|
-
headers: {
|
224
|
-
Cookie: getUserCookies()
|
225
|
-
}
|
226
|
-
}
|
227
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
228
|
-
const proxySplitArr = proxy.split(':');
|
229
|
-
const proxyPort = proxySplitArr.pop();
|
230
|
-
const proxyHost = proxySplitArr.join(':');
|
231
|
-
compileProgressOption.proxy = {
|
232
|
-
host: proxyHost,
|
233
|
-
port: proxyPort
|
234
|
-
}
|
235
|
-
}
|
236
|
-
// return axios.get(`/api/v1/app/${appId}/compile_progress`, compileProgressOption).then(res => {
|
237
|
-
return axios.get(`/api/developer/ide/microgame/v1/compile_progress?appid=${appId}`, compileProgressOption).then(res => {
|
238
|
-
const {
|
239
|
-
error,
|
240
|
-
status,
|
241
|
-
message = ''
|
242
|
-
} = res.data || {};
|
243
|
-
if (error === 1) {
|
244
|
-
msg = message ? compileErrFormat(message) : 'Preview failed, please try later';
|
245
|
-
return {
|
246
|
-
success: false,
|
247
|
-
msg
|
248
|
-
}
|
249
|
-
}
|
250
|
-
return {
|
251
|
-
success: true,
|
252
|
-
done: error === 0 && status === 2,
|
253
|
-
msg: ''
|
254
|
-
}
|
255
|
-
}).catch(err => {
|
256
|
-
return {
|
257
|
-
success: false,
|
258
|
-
msg: err.message
|
259
|
-
}
|
260
|
-
});
|
261
|
-
}
|
262
|
-
|
263
|
-
exports.getQrCode = function (appId, proxy, type = 'preview') {
|
264
|
-
const requestHeader = {
|
265
|
-
Cookie: getUserCookies()
|
266
|
-
}
|
267
|
-
if (useBoeRequest) {
|
268
|
-
requestHeader['X-TT-ENV'] = 'test';
|
269
|
-
}
|
270
|
-
const qrCodeOptions = {
|
271
|
-
params: {
|
272
|
-
t: Date.now()
|
273
|
-
},
|
274
|
-
headers: requestHeader
|
275
|
-
}
|
276
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
277
|
-
const proxySplitArr = proxy.split(':');
|
278
|
-
const proxyPort = proxySplitArr.pop();
|
279
|
-
const proxyHost = proxySplitArr.join(':');
|
280
|
-
qrCodeOptions.proxy = {
|
281
|
-
host: proxyHost,
|
282
|
-
port: proxyPort
|
283
|
-
}
|
284
|
-
}
|
285
|
-
return axios.get(`/api/v1/app/${appId}/${type}/qrcode_url`, qrCodeOptions).then(res => {
|
286
|
-
return {
|
287
|
-
success: true,
|
288
|
-
url: res.data,
|
289
|
-
msg: ''
|
290
|
-
}
|
291
|
-
}).catch(err => {
|
292
|
-
return {
|
293
|
-
success: false,
|
294
|
-
msg: err.message
|
295
|
-
}
|
296
|
-
});
|
297
|
-
}
|
298
|
-
|
299
|
-
exports.checkUserPermissions = function (appId, proxy) {
|
300
|
-
const permissionsOptions = {
|
301
|
-
headers: {
|
302
|
-
Cookie: getUserCookies()
|
303
|
-
}
|
304
|
-
}
|
305
|
-
if (proxy && proxy.indexOf(':') > -1) {
|
306
|
-
const proxySplitArr = proxy.split(':');
|
307
|
-
const proxyPort = proxySplitArr.pop();
|
308
|
-
const proxyHost = proxySplitArr.join(':');
|
309
|
-
permissionsOptions.proxy = {
|
310
|
-
host: proxyHost,
|
311
|
-
port: proxyPort
|
312
|
-
}
|
313
|
-
}
|
314
|
-
return axios.get(`/api/v1/app/${appId}/permissions`, permissionsOptions).then(res => {
|
315
|
-
const {
|
316
|
-
error,
|
317
|
-
message,
|
318
|
-
data
|
319
|
-
} = res.data || {};
|
320
|
-
if (error) {
|
321
|
-
const msg = message || 'Upload failed,please check if your appId is valid';
|
322
|
-
return {
|
323
|
-
success: false,
|
324
|
-
msg
|
325
|
-
};
|
326
|
-
}
|
327
|
-
if (data.is_admin || data.publish === 2) {
|
328
|
-
return {
|
329
|
-
success: true,
|
330
|
-
msg: ''
|
331
|
-
};
|
332
|
-
} else {
|
333
|
-
return {
|
334
|
-
success: false,
|
335
|
-
msg: 'You do not have permission to upload app'
|
336
|
-
};
|
337
|
-
}
|
338
|
-
}).catch(err => {
|
339
|
-
console.log(err)
|
340
|
-
return {
|
341
|
-
success: false,
|
342
|
-
msg: err.message
|
343
|
-
}
|
344
|
-
});
|
345
|
-
}
|
346
|
-
|
347
|
-
// 该方法暂无调用
|
348
|
-
exports.checkRemoteVersion = async function () {
|
349
|
-
const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout;
|
350
|
-
return axios.get(`${registry}${getPackageName()}`, {
|
351
|
-
params: {},
|
352
|
-
headers: {
|
353
|
-
Accept: 'application/vnd.npm.install-v1+json'
|
354
|
-
}
|
355
|
-
}).then(res => {
|
356
|
-
return {
|
357
|
-
version: res.data['dist-tags'].latest,
|
358
|
-
success: true
|
359
|
-
}
|
360
|
-
}).catch(err => {
|
361
|
-
return {
|
362
|
-
success: false,
|
363
|
-
msg: err.message
|
364
|
-
}
|
365
|
-
});
|
366
|
-
}
|
367
|
-
|
368
|
-
// 获取远程版本号
|
369
|
-
exports.checkUploadVersion = async function (appId, version) {
|
370
|
-
try {
|
371
|
-
const current = await getProjectReleaseVersion(appId);
|
372
|
-
if (compareVersions(version, current) > 0) {
|
373
|
-
return {
|
374
|
-
current,
|
375
|
-
success: true,
|
376
|
-
}
|
377
|
-
} else {
|
378
|
-
return {
|
379
|
-
current,
|
380
|
-
success: false,
|
381
|
-
msg: `The version you uploaded must be greater than ${current}.`,
|
382
|
-
}
|
383
|
-
}
|
384
|
-
} catch (err) {
|
385
|
-
return {
|
386
|
-
success: false,
|
387
|
-
msg: err.message
|
388
|
-
}
|
389
|
-
}
|
390
|
-
}
|
391
|
-
|
392
|
-
const getProjectReleaseVersion = async function (appId) {
|
393
|
-
const res = await axios.get(`/api/apps/v3/meta?appid=${appId}&aid=13&version=current&ttcode=OVCNW/U0UREwv0sHdY9Rm16vBgGrCQIBOWurUCmJ1H6d/2XHLKeOYTYfEJIEeC0AOCwBZAR2j34C4tFN7Nqfq9tHVEpM4OuJM2b8qz0INtUs1qLhKFOtnGa9/Ey0WW86GGocJk074eP72MMhzNmePzaTQzXwn/eqEq4GHwyF2Tg=&t=${new Date().getTime()}`)
|
394
|
-
return res.data.data.version;
|
395
|
-
}
|
396
|
-
exports.getProjectReleaseVersion = getProjectReleaseVersion;
|
package/lib/util/version.js
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
const fs = require('fs-extra');
|
2
|
-
const path = require('path');
|
3
|
-
const { getStoragePath } = require('./config');
|
4
|
-
const versionFilePath = path.join(getStoragePath(), 'version.json');
|
5
|
-
fs.ensureFileSync(versionFilePath);
|
6
|
-
|
7
|
-
function getVersion() {
|
8
|
-
return require(`../../package.json`).version;
|
9
|
-
}
|
10
|
-
|
11
|
-
async function saveLatestVersionToLocal(version, time) {
|
12
|
-
await fs.writeFile(versionFilePath, JSON.stringify({
|
13
|
-
"version": version,
|
14
|
-
"time": time
|
15
|
-
}));
|
16
|
-
}
|
17
|
-
|
18
|
-
async function getLatestVersionFromLocal() {
|
19
|
-
const fileData = await fs.readFile(versionFilePath, 'utf-8');
|
20
|
-
return JSON.parse(fileData || "{}");
|
21
|
-
}
|
22
|
-
|
23
|
-
module.exports = {
|
24
|
-
getVersion,
|
25
|
-
saveLatestVersionToLocal,
|
26
|
-
getLatestVersionFromLocal
|
27
|
-
}
|
package/lib/version.js
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
// Get project version
|
2
|
-
const path = require('path');
|
3
|
-
const chalk = require('chalk');
|
4
|
-
const {
|
5
|
-
checkBeforeUpload,
|
6
|
-
isValidAppVersion,
|
7
|
-
} = require('./util/check');
|
8
|
-
const {
|
9
|
-
getProjectReleaseVersion
|
10
|
-
} = require('./util/request');
|
11
|
-
|
12
|
-
async function version(entry, options) {
|
13
|
-
const cwd = options.cwd || process.cwd();
|
14
|
-
if (!entry) {
|
15
|
-
entry = cwd
|
16
|
-
} else if (path.isAbsolute(entry)) {
|
17
|
-
// skip if entry if absolute path
|
18
|
-
} else {
|
19
|
-
// resolve the relative entry with cwd
|
20
|
-
entry = path.resolve(cwd, entry);
|
21
|
-
}
|
22
|
-
|
23
|
-
const {
|
24
|
-
success: beforeSuccess,
|
25
|
-
msg: beforeMsg,
|
26
|
-
appId
|
27
|
-
} = await checkBeforeUpload(entry);
|
28
|
-
if (!beforeSuccess) {
|
29
|
-
const errMsg = `[CLI VERSION ERROR]: ${beforeMsg}`;
|
30
|
-
console.log(chalk.red(errMsg));
|
31
|
-
throw new Error(errMsg);
|
32
|
-
}
|
33
|
-
|
34
|
-
const version = await getProjectReleaseVersion(appId);
|
35
|
-
console.log(version);
|
36
|
-
}
|
37
|
-
|
38
|
-
module.exports = (...args) => {
|
39
|
-
return version(...args).catch(err => {
|
40
|
-
const errMsg = `[CLI VERSION ERROR]: ${err}`;
|
41
|
-
console.log(chalk.red(errMsg));
|
42
|
-
throw new Error(errMsg);
|
43
|
-
});
|
44
|
-
}
|