@vkontakte/vk-miniapps-deploy 0.1.4 → 0.1.6
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/bin/vk-miniapps-deploy +10 -6
- package/index.js +39 -1
- package/package.json +1 -1
- package/vk-hosting-config.json.example +2 -1
package/bin/vk-miniapps-deploy
CHANGED
|
@@ -21,6 +21,10 @@ async function run() {
|
|
|
21
21
|
const deploy = require('../index');
|
|
22
22
|
const cfg = configJSON || {};
|
|
23
23
|
|
|
24
|
+
if (cfg.debug) {
|
|
25
|
+
console.log('\nDebug mode is enabled. It will log all client requests!\n');
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
let confirmation = {
|
|
25
29
|
result: true,
|
|
26
30
|
}
|
|
@@ -35,9 +39,11 @@ async function run() {
|
|
|
35
39
|
name: 'result',
|
|
36
40
|
message: chalk.yellow('Would you like to deploy to VK Mini Apps hosting using these commands?')
|
|
37
41
|
});
|
|
38
|
-
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
if (!confirmation.result) {
|
|
44
|
+
process.exit();
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
const extraOptions = await getExtraOptions()
|
|
42
48
|
cfg.update_prod = extraOptions.update_prod;
|
|
43
49
|
cfg.update_dev = extraOptions.update_dev;
|
|
@@ -45,12 +51,10 @@ async function run() {
|
|
|
45
51
|
if (extraOptions.update_test === true && extraOptions.test_group_name !== '') {
|
|
46
52
|
cfg.test_group_name = extraOptions.test_group_name;
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
const status = await deploy.run(cfg) ? 0 : 1;
|
|
50
|
-
process.exit(status);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
const status = await deploy.run(cfg) ? 0 : 1;
|
|
57
|
+
process.exit(status);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
async function getExtraOptions() {
|
package/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
1
2
|
const packageJson = require('./package.json');
|
|
2
3
|
const chalk = require('chalk');
|
|
3
4
|
const prompt = require('prompts');
|
|
4
|
-
const
|
|
5
|
+
const nodeFetch = require('node-fetch');
|
|
5
6
|
const { zip } = require('zip-a-folder');
|
|
6
7
|
const fs = require('fs-extra');
|
|
7
8
|
const FormData = require('form-data');
|
|
@@ -14,6 +15,8 @@ var cfg = configJSON || {};
|
|
|
14
15
|
prompt.message = "vk-mini-apps-deploy".grey;
|
|
15
16
|
prompt.delimiter = "=>".grey;
|
|
16
17
|
|
|
18
|
+
const DEBUG_MODE = !!cfg.debug;
|
|
19
|
+
|
|
17
20
|
const API_HOST = cfg.api_host || 'https://api.vk.com/method/';
|
|
18
21
|
const OAUTH_HOST = cfg.oauth_host || 'https://oauth.vk.com/';
|
|
19
22
|
|
|
@@ -63,6 +66,41 @@ const URL_NAMES_MAP = {
|
|
|
63
66
|
[URL_NAMES.MOBILE_WEB]: PLATFORMS.MOBILE_WEB,
|
|
64
67
|
};
|
|
65
68
|
|
|
69
|
+
function getTraceId() {
|
|
70
|
+
return crypto.randomBytes(4).toString("hex");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {nodeFetch.RequestInfo} url
|
|
75
|
+
* @param {nodeFetch.RequestInit} options
|
|
76
|
+
* @returns {Promise<nodeFetch.Response>}
|
|
77
|
+
*/
|
|
78
|
+
async function fetch(url, options) {
|
|
79
|
+
if (!DEBUG_MODE) {
|
|
80
|
+
return nodeFetch(url, options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const traceId = chalk.hex(`#${(Math.random() * 0xFFFFFF << 0).toString(16)}`)(getTraceId());
|
|
84
|
+
const logLine = (line, type) => console.log(`[${traceId}][${type}]`, chalk.cyan(line));
|
|
85
|
+
const logError = (error) => console.error(`[${traceId}][ERROR]`, chalk.red(error));
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
logLine(url, 'REQ');
|
|
89
|
+
options && logLine(JSON.stringify(options), 'REQ');
|
|
90
|
+
|
|
91
|
+
const response = await nodeFetch(url, options);
|
|
92
|
+
const body = await response.clone().text();
|
|
93
|
+
|
|
94
|
+
logLine(`${response.status} ${response.statusText}`, 'RESP');
|
|
95
|
+
logLine(body, 'RESP');
|
|
96
|
+
|
|
97
|
+
return response
|
|
98
|
+
} catch (e) {
|
|
99
|
+
logError(e);
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
66
104
|
async function auth() {
|
|
67
105
|
const get_auth_code = await fetch(OAUTH_HOST + 'get_auth_code?scope=offline&client_id=' + DEPLOY_APP_ID);
|
|
68
106
|
const get_auth_code_res = await get_auth_code.json();
|
package/package.json
CHANGED