@vkontakte/vk-miniapps-deploy 0.1.8 → 0.1.9-rc.0

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/.eslintrc.js ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ extends: ['plugin:@vkontakte/eslint-plugin/default', 'prettier'],
3
+ parserOptions: {
4
+ requireConfigFile: false,
5
+ },
6
+ rules: {
7
+ 'import/no-duplicates': 'off',
8
+ 'no-undef': 'off',
9
+ 'no-shadow': 'off',
10
+ 'no-var': 'off',
11
+ 'camelcase': 'off',
12
+ 'valid-jsdoc': 'off',
13
+ },
14
+ };
@@ -1,2 +1,2 @@
1
1
  * @VKCOM/vk-miniapp
2
- .github @VKCOM/vk-sec
2
+ .github/ @VKCOM/vk-sec
@@ -13,7 +13,7 @@ runs:
13
13
  registry-url: 'https://registry.npmjs.org'
14
14
 
15
15
  - name: Install dependencies
16
- run: yarn install --frozen-lockfile --ignore-scripts
16
+ run: yarn install --ignore-scripts
17
17
  shell: bash
18
18
 
19
19
  - name: Set Git credentials
@@ -0,0 +1,9 @@
1
+ name: 'Validation'
2
+ description: It runs linter and prettier checks
3
+
4
+ runs:
5
+ using: composite
6
+ steps:
7
+ - name: Run linters
8
+ run: yarn lint:ci
9
+ shell: bash
@@ -33,6 +33,9 @@ jobs:
33
33
  with:
34
34
  version: ${{ github.event.inputs.new_version }}
35
35
 
36
+ - name: Validation
37
+ uses: ./.github/actions/validation
38
+
36
39
  - name: Complete publish
37
40
  uses: ./.github/actions/complete-publish
38
41
  with:
@@ -47,6 +47,9 @@ jobs:
47
47
  version: ${{ github.event.inputs.custom_version || github.event.inputs.new_version }}
48
48
  npm_tag: ${{ github.event.inputs.npm_tag }}
49
49
 
50
+ - name: Validation
51
+ uses: ./.github/actions/validation
52
+
50
53
  - name: Complete publish
51
54
  uses: ./.github/actions/complete-publish
52
55
  with:
@@ -0,0 +1,19 @@
1
+ name: 'Pull Request'
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ jobs:
7
+ lint:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Checkout
11
+ uses: actions/checkout@v4
12
+ with:
13
+ token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
14
+
15
+ - name: Setting up the repository environment
16
+ uses: ./.github/actions/setup
17
+
18
+ - name: Validation
19
+ uses: ./.github/actions/validation
@@ -0,0 +1,30 @@
1
+ # OS
2
+ .DS_Store
3
+
4
+ # IDE
5
+ .idea/
6
+ .vscode/
7
+
8
+ # Dependencices
9
+ node_modules/
10
+
11
+ # Caches
12
+ .cache
13
+ tmp/
14
+
15
+ # Logs
16
+ test-results.json
17
+ lint-results.json
18
+ yarn-error.log
19
+
20
+ # Caches
21
+ .cache
22
+
23
+ # Coverage directories used by tools like istanbul
24
+ coverage
25
+ .nyc_output
26
+
27
+ # GitHub
28
+ .github/*
29
+
30
+ /bin
package/.prettierrc.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('@vkontakte/prettier-config').createConfig();
package/index.js CHANGED
@@ -11,8 +11,8 @@ const vault = new Configstore(packageJson.name, {});
11
11
 
12
12
  var configJSON = require('require-module')('./vk-hosting-config.json');
13
13
  var cfg = configJSON || {};
14
- prompt.message = "vk-mini-apps-deploy".grey;
15
- prompt.delimiter = "=>".grey;
14
+ prompt.message = 'vk-mini-apps-deploy'.grey;
15
+ prompt.delimiter = '=>'.grey;
16
16
 
17
17
  const DEBUG_MODE = !!cfg.debug;
18
18
 
@@ -40,14 +40,14 @@ const ERROR_TEST_GROUP_UPDATE = 109;
40
40
  const TYPE_SUCCESS = 'success';
41
41
 
42
42
  const URL_NAMES = {
43
- DESKTOP_DEV : 'vk_app_desktop_dev_url',
43
+ DESKTOP_DEV: 'vk_app_desktop_dev_url',
44
44
  MOBILE_DEV: 'vk_app_dev_url',
45
45
  MOBILE_WEB_DEV: 'vk_mini_app_mvk_dev_url',
46
46
  WEB_LEGACY: 'iframe_url',
47
47
  WEB: 'iframe_secure_url',
48
48
  MOBILE: 'm_iframe_secure_url',
49
49
  MOBILE_WEB: 'vk_mini_app_mvk_url',
50
- }
50
+ };
51
51
 
52
52
  const PLATFORMS = {
53
53
  WEB: 'vk.com',
@@ -66,11 +66,11 @@ const URL_NAMES_MAP = {
66
66
  };
67
67
 
68
68
  function getTraceId() {
69
- return crypto.randomBytes(4).toString("hex");
69
+ return crypto.randomBytes(4).toString('hex');
70
70
  }
71
71
 
72
72
  /**
73
- * @param {nodeFetch.RequestInfo} url
73
+ * @param {nodeFetch.RequestInfo} url
74
74
  * @param {nodeFetch.RequestInit} options
75
75
  * @returns {Promise<nodeFetch.Response>}
76
76
  */
@@ -79,7 +79,7 @@ async function fetch(url, options) {
79
79
  return nodeFetch(url, options);
80
80
  }
81
81
 
82
- const traceId = chalk.hex(`#${(Math.random() * 0xFFFFFF << 0).toString(16)}`)(getTraceId());
82
+ const traceId = chalk.hex(`#${((Math.random() * 0xffffff) << 0).toString(16)}`)(getTraceId());
83
83
  const logLine = (line, type) => console.log(`[${traceId}][${type}]`, chalk.cyan(line));
84
84
  const logError = (error) => console.error(`[${traceId}][ERROR]`, chalk.red(error));
85
85
 
@@ -93,7 +93,7 @@ async function fetch(url, options) {
93
93
  logLine(`${response.status} ${response.statusText}`, 'RESP');
94
94
  logLine(body, 'RESP');
95
95
 
96
- return response
96
+ return response;
97
97
  } catch (e) {
98
98
  logError(e);
99
99
  throw e;
@@ -119,7 +119,7 @@ async function auth(app_id) {
119
119
  }
120
120
 
121
121
  if (get_auth_code_res.auth_code) {
122
- const {auth_code, device_id} = get_auth_code_res;
122
+ const { auth_code, device_id } = get_auth_code_res;
123
123
 
124
124
  const code_auth_url = `${OAUTH_HOST}code_auth?stage=check&code=${auth_code}&revoke=1`;
125
125
 
@@ -129,11 +129,11 @@ async function auth(app_id) {
129
129
  type: 'confirm',
130
130
  name: 'result',
131
131
  initial: true,
132
- message: chalk.yellow('Please open this url in browser', code_auth_url)
132
+ message: chalk.yellow('Please open this url in browser', code_auth_url),
133
133
  });
134
134
 
135
135
  if (!prompt_question.result) {
136
- return Promise.reject("empty response " + prompt_question.result);
136
+ return Promise.reject('empty response ' + prompt_question.result);
137
137
  }
138
138
 
139
139
  const code_auth_token_url = `${OAUTH_HOST}code_auth_token?device_id=${device_id}&client_id=${DEPLOY_APP_ID}&mini_app_id=${app_id}`;
@@ -145,7 +145,7 @@ async function auth(app_id) {
145
145
  continue;
146
146
  }
147
147
 
148
- const {access_token, expires_in} = code_auth_token_json;
148
+ const { access_token, expires_in } = code_auth_token_json;
149
149
  if (access_token || access_token === null) {
150
150
  handled = true;
151
151
  }
@@ -153,7 +153,6 @@ async function auth(app_id) {
153
153
  access_token,
154
154
  expires_in,
155
155
  });
156
-
157
156
  } while (handled === false);
158
157
  }
159
158
  }
@@ -168,7 +167,11 @@ async function api(method, params) {
168
167
  return false;
169
168
  }
170
169
 
171
- const queryParams = Object.keys(params).map((k) => { return k + "=" + encodeURIComponent(params[k]) }).join('&');
170
+ const queryParams = Object.keys(params)
171
+ .map((k) => {
172
+ return k + '=' + encodeURIComponent(params[k]);
173
+ })
174
+ .join('&');
172
175
  try {
173
176
  const query = await fetch(API_HOST + method + '?' + queryParams);
174
177
  const res = await query.json();
@@ -186,12 +189,12 @@ async function api(method, params) {
186
189
 
187
190
  async function upload(uploadUrl, bundleFile) {
188
191
  const formData = new FormData();
189
- formData.append('file', fs.createReadStream(bundleFile), {contentType: 'application/zip'});
192
+ formData.append('file', fs.createReadStream(bundleFile), { contentType: 'application/zip' });
190
193
  try {
191
194
  const upload = await fetch(uploadUrl, {
192
195
  method: 'POST',
193
196
  headers: formData.getHeaders(),
194
- body: formData
197
+ body: formData,
195
198
  });
196
199
  return await upload.json();
197
200
  } catch (e) {
@@ -243,14 +246,14 @@ async function handleQueue(user_id, base_url, key, ts, version, handled, cfg) {
243
246
  const result = await prompt({
244
247
  type: 'text',
245
248
  name: 'code',
246
- message: chalk.yellow('Please, enter code from Administration: ')
249
+ message: chalk.yellow('Please, enter code from Administration: '),
247
250
  });
248
251
 
249
252
  if (result.code) {
250
253
  const r = await api('apps.confirmDeploy', {
251
254
  app_id: cfg.app_id,
252
255
  version: version,
253
- code: result.code
256
+ code: result.code,
254
257
  });
255
258
  if (r.error) {
256
259
  console.error('Invalid confirm code');
@@ -322,7 +325,7 @@ async function handleQueue(user_id, base_url, key, ts, version, handled, cfg) {
322
325
  if (event.code === CODE_UPDATE_TEST_GROUP_URL) {
323
326
  if (event.message && event.message.url) {
324
327
  console.info(chalk.green('URL changed for test group "' + cfg.test_group_name + '":'));
325
- console.info(event.message.url)
328
+ console.info(event.message.url);
326
329
  }
327
330
  }
328
331
  }
@@ -333,7 +336,7 @@ async function handleQueue(user_id, base_url, key, ts, version, handled, cfg) {
333
336
  }
334
337
 
335
338
  async function getQueue(version, cfg) {
336
- const r = await api('apps.subscribeToHostingQueue', {app_id: cfg.app_id, version: version});
339
+ const r = await api('apps.subscribeToHostingQueue', { app_id: cfg.app_id, version: version });
337
340
  if (!r.base_url || !r.key || !r.ts || !r.app_id) {
338
341
  throw new Error(JSON.stringify(r));
339
342
  }
@@ -342,7 +345,6 @@ async function getQueue(version, cfg) {
342
345
  }
343
346
 
344
347
  async function run(cfg) {
345
-
346
348
  if (!configJSON) {
347
349
  throw new Error('For deploy you need to create config file "vk-hosting-config.json"');
348
350
  }
@@ -352,11 +354,11 @@ async function run(cfg) {
352
354
  const defaultEnvironment = APPLICATION_ENV_DEV | APPLICATION_ENV_PRODUCTION;
353
355
  const environmentMapping = {
354
356
  dev: APPLICATION_ENV_DEV,
355
- production: APPLICATION_ENV_PRODUCTION
357
+ production: APPLICATION_ENV_PRODUCTION,
356
358
  };
357
359
 
358
360
  const environment = process.env.MINI_APPS_ENVIRONMENT
359
- ? (environmentMapping[process.env.MINI_APPS_ENVIRONMENT] || defaultEnvironment)
361
+ ? environmentMapping[process.env.MINI_APPS_ENVIRONMENT] || defaultEnvironment
360
362
  : defaultEnvironment;
361
363
 
362
364
  if (process.env.MINI_APPS_APP_ID) {
@@ -387,18 +389,24 @@ async function run(cfg) {
387
389
  vault.set('access_token', access_token);
388
390
  vault.set('expires_in', expires_in);
389
391
  console.log(chalk.cyan('Token is saved in config store!'));
390
- console.log(chalk.cyan('\nFor your CI, you can use \n > $ env MINI_APPS_ACCESS_TOKEN=' + access_token + ' yarn deploy'));
392
+ console.log(
393
+ chalk.cyan(
394
+ '\nFor your CI, you can use \n > $ env MINI_APPS_ACCESS_TOKEN=' +
395
+ access_token +
396
+ ' yarn deploy',
397
+ ),
398
+ );
391
399
  }
392
400
 
393
401
  const params = {
394
402
  app_id: cfg.app_id,
395
403
  environment: environment,
396
- update_prod: + cfg.update_prod,
397
- update_dev: + cfg.update_dev
404
+ update_prod: +cfg.update_prod,
405
+ update_dev: +cfg.update_dev,
398
406
  };
399
407
 
400
408
  if ('test_group_name' in cfg) {
401
- params.test_group_name = cfg.test_group_name
409
+ params.test_group_name = cfg.test_group_name;
402
410
  }
403
411
 
404
412
  const endpointPlatformKeys = Object.keys(cfg.endpoints);
@@ -425,10 +433,9 @@ async function run(cfg) {
425
433
 
426
434
  if (!cfg.bundleFile) {
427
435
  if (await fs.pathExists(bundleFile)) {
428
- fs.removeSync(bundleFile)
436
+ fs.removeSync(bundleFile);
429
437
  }
430
438
 
431
-
432
439
  await zip('./' + staticPath, bundleFile);
433
440
  }
434
441
 
@@ -442,11 +449,10 @@ async function run(cfg) {
442
449
  console.log('Uploaded version ' + r.version + '!');
443
450
  return getQueue(r.version, cfg);
444
451
  } else {
445
- console.error('Upload error:', r)
452
+ console.error('Upload error:', r);
446
453
  process.exit(1);
447
454
  }
448
455
  });
449
-
450
456
  } catch (e) {
451
457
  console.error(chalk.red(e));
452
458
  process.exit(1);
@@ -454,5 +460,5 @@ async function run(cfg) {
454
460
  }
455
461
 
456
462
  module.exports = {
457
- run: run
463
+ run: run,
458
464
  };
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@vkontakte/vk-miniapps-deploy",
3
- "version": "0.1.8",
3
+ "version": "0.1.9-rc.0",
4
4
  "description": "Deploy to VK Mini Apps hosting with one simple command",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
- "deploy": "./bin/vk-miniapps-deploy"
8
+ "deploy": "./bin/vk-miniapps-deploy",
9
+ "lint:eslint": "eslint ./index.js",
10
+ "lint:prettier": "prettier --check ./index.js",
11
+ "lint:fix": "eslint ./index.js --fix",
12
+ "lint:ci": "yarn lint:eslint && yarn lint:prettier"
9
13
  },
10
14
  "license": "MIT",
11
15
  "engines": {
@@ -42,5 +46,12 @@
42
46
  "prompts": "^2.1.0",
43
47
  "require-module": "^0.1.0",
44
48
  "zip-a-folder": "0.0.12"
49
+ },
50
+ "devDependencies": {
51
+ "@vkontakte/eslint-plugin": "^2.0.0",
52
+ "@vkontakte/prettier-config": "^0.1.0",
53
+ "eslint": "^8.0.0",
54
+ "eslint-config-prettier": "^9.1.0",
55
+ "prettier": "^2.7.1"
45
56
  }
46
57
  }