@vkontakte/vk-miniapps-deploy 0.1.5 → 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 +4 -0
- package/index.js +39 -1
- package/package.json +1 -1
- package/vk-hosting-config.json.example +2 -1
package/bin/vk-miniapps-deploy
CHANGED
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