@vkontakte/vk-miniapps-deploy 0.0.25 → 0.1.2

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.
@@ -0,0 +1,2 @@
1
+ * @VKCOM/vk-miniapp
2
+ .github/dependabot.yml @VKCOM/vk-sec
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
7
+ allow:
8
+ - dependency-type: "direct"
9
+ reviewers:
10
+ - "VKCOM/vk-sec"
11
+ - "VKCOM/vk-miniapp"
@@ -0,0 +1,40 @@
1
+ name: 'Publish'
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: 'version (without v prefix)'
8
+ required: true
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ with:
16
+ token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
17
+
18
+ - uses: actions/setup-node@v3
19
+ with:
20
+ node-version: 16
21
+ cache: 'yarn'
22
+ always-auth: true
23
+ registry-url: 'https://registry.npmjs.org'
24
+
25
+ - name: Set Git credentials
26
+ run: |
27
+ git config --local user.email "actions@github.com"
28
+ git config --local user.name "GitHub Action"
29
+ - run: yarn version --new-version ${{ github.event.inputs.version }} --no-commit-hooks
30
+
31
+ - name: Pushing changes
32
+ uses: ad-m/github-push-action@master
33
+ with:
34
+ github_token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
35
+ branch: ${{ github.ref }}
36
+
37
+ - name: Publushing release
38
+ run: yarn publish --access public --non-interactive
39
+ env:
40
+ NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
@@ -5,12 +5,12 @@ const configFilePath = './vk-hosting-config.json';
5
5
  const prompt = require('prompts');
6
6
 
7
7
  async function run() {
8
- if (fs.pathExists(configFilePath).then((res) => {
8
+ fs.pathExists(configFilePath).then((res) => {
9
9
  if (!res) {
10
10
  console.error(configFilePath + ' is missing');
11
11
  return false;
12
12
  }
13
- })) ;
13
+ });
14
14
 
15
15
  const configJSON = require('require-module')(configFilePath);
16
16
  if (!configJSON) {
@@ -21,28 +21,71 @@ async function run() {
21
21
  const deploy = require('../index');
22
22
  const cfg = configJSON || {};
23
23
 
24
- if (!cfg) {
25
- console.error('vk-hosting-config.json is missing');
26
- return false;
24
+ let confirmation = {
25
+ result: true,
27
26
  }
28
27
 
29
- if (cfg.noprompt) {
30
- deploy.run(cfg);
31
- } else {
28
+ if (!cfg.noprompt) {
32
29
  prompt.message = chalk.cyan("vk-mini-apps-deploy:");
33
30
  prompt.delimiter = chalk.green(" $ ");
34
31
 
35
- const result = await prompt({
32
+ confirmation = await prompt({
36
33
  type: 'confirm',
37
34
  initial: true,
38
35
  name: 'result',
39
36
  message: chalk.yellow('Would you like to deploy to VK Mini Apps hosting using these commands?')
40
37
  });
38
+ }
39
+
40
+ if (confirmation.result) {
41
+ const extraOptions = await getExtraOptions()
42
+ cfg.update_prod = extraOptions.update_prod;
43
+ cfg.update_dev = extraOptions.update_dev;
41
44
 
42
- if (result.result) {
43
- const status = await deploy.run(cfg) ? 0 : 1;
44
- process.exit(status);
45
+ if (extraOptions.update_test === true && extraOptions.test_group_name !== '') {
46
+ cfg.test_group_name = extraOptions.test_group_name;
45
47
  }
48
+
49
+ const status = await deploy.run(cfg) ? 0 : 1;
50
+ process.exit(status);
46
51
  }
52
+
53
+ process.exit();
54
+ }
55
+
56
+ async function getExtraOptions() {
57
+ const questions = [
58
+ {
59
+ type: 'confirm',
60
+ initial: true,
61
+ name: 'update_prod',
62
+ message: chalk.yellow('Would you like to update prod urls?')
63
+ },
64
+ {
65
+ type: 'confirm',
66
+ initial: true,
67
+ name: 'update_dev',
68
+ message: chalk.yellow('Would you like to update dev urls?')
69
+ },
70
+ {
71
+ type: 'confirm',
72
+ initial: false,
73
+ name: 'update_test',
74
+ message: chalk.yellow('Would you like to update test group url?')
75
+ },
76
+ {
77
+ type: prev => prev === true ? 'text' : null,
78
+ name: 'test_group_name',
79
+ message: chalk.yellow('Enter test group name:')
80
+ }
81
+ ];
82
+
83
+ const extraOptions = await prompt(questions);
84
+
85
+ if (extraOptions.update_prod === false && extraOptions.update_dev === false && extraOptions.update_test === false) {
86
+ process.exit();
87
+ }
88
+
89
+ return extraOptions;
47
90
  }
48
91
  run().then(r => console.log(r));
package/index.js CHANGED
@@ -31,6 +31,9 @@ const CODE_SKIP = 202;
31
31
  const CODE_PUSH_SENT_VIA_PUSH = 203;
32
32
  const CODE_PUSH_APPROVED = 204;
33
33
  const CODE_CONFIRM_SENT_VIA_MESSAGE = 205;
34
+ const CODE_UPDATE_TEST_GROUP_URL = 206;
35
+
36
+ const ERROR_TEST_GROUP_UPDATE = 109;
34
37
 
35
38
  const TYPE_SUCCESS = 'success';
36
39
 
@@ -151,7 +154,7 @@ async function upload(uploadUrl, bundleFile) {
151
154
  }
152
155
  }
153
156
 
154
- async function handleQueue(user_id, base_url, key, ts, version, handled) {
157
+ async function handleQueue(user_id, base_url, key, ts, version, handled, cfg) {
155
158
  const url = base_url + '?act=a_check&key=' + key + '&ts=' + ts + '&id=' + user_id + '&wait=5';
156
159
  const query = await fetch(url);
157
160
  const res = await query.json();
@@ -174,6 +177,12 @@ async function handleQueue(user_id, base_url, key, ts, version, handled) {
174
177
  let event = res.events[i].data;
175
178
  if (event.type === 'error') {
176
179
  const message = event.message || '';
180
+
181
+ if (event.code === ERROR_TEST_GROUP_UPDATE) {
182
+ console.error(chalk.red('Test group url update error'));
183
+ continue;
184
+ }
185
+
177
186
  console.error(chalk.red('Deploy failed, error code: #' + event.code + ' ' + message));
178
187
  return false;
179
188
  }
@@ -216,7 +225,7 @@ async function handleQueue(user_id, base_url, key, ts, version, handled) {
216
225
  }
217
226
 
218
227
  if (event.code === CODE_SKIP) {
219
- switch (event.message.environment) {
228
+ switch (parseInt(event.message.environment)) {
220
229
  case APPLICATION_ENV_DEV:
221
230
  handled.dev = true;
222
231
  break;
@@ -264,20 +273,27 @@ async function handleQueue(user_id, base_url, key, ts, version, handled) {
264
273
  }
265
274
  }
266
275
  }
276
+
277
+ if (event.code === CODE_UPDATE_TEST_GROUP_URL) {
278
+ if (event.message && event.message.url) {
279
+ console.info(chalk.green('URL changed for test group "' + cfg.test_group_name + '":'));
280
+ console.info(event.message.url)
281
+ }
282
+ }
267
283
  }
268
284
  }
269
285
  }
270
286
 
271
- return handleQueue(user_id, base_url, key, res.ts, version, handled);
287
+ return handleQueue(user_id, base_url, key, res.ts, version, handled, cfg);
272
288
  }
273
289
 
274
- async function getQueue(version) {
290
+ async function getQueue(version, cfg) {
275
291
  const r = await api('apps.subscribeToHostingQueue', {app_id: cfg.app_id, version: version});
276
292
  if (!r.base_url || !r.key || !r.ts || !r.app_id) {
277
293
  throw new Error(JSON.stringify(r));
278
294
  }
279
295
 
280
- return handleQueue(r.app_id, r.base_url, r.key, r.ts, version, false);
296
+ return handleQueue(r.app_id, r.base_url, r.key, r.ts, version, false, cfg);
281
297
  }
282
298
 
283
299
  async function run(cfg) {
@@ -327,7 +343,17 @@ async function run(cfg) {
327
343
  throw new Error('Please provide "app_id" to vk-hosting-config.json or env MINI_APPS_APP_ID');
328
344
  }
329
345
 
330
- const params = {app_id: cfg.app_id, environment: environment};
346
+ const params = {
347
+ app_id: cfg.app_id,
348
+ environment: environment,
349
+ update_prod: + cfg.update_prod,
350
+ update_dev: + cfg.update_dev
351
+ };
352
+
353
+ if ('test_group_name' in cfg) {
354
+ params.test_group_name = cfg.test_group_name
355
+ }
356
+
331
357
  const endpointPlatformKeys = Object.keys(cfg.endpoints);
332
358
  if (endpointPlatformKeys.length) {
333
359
  for (let i = 0; i < endpointPlatformKeys.length; i++) {
@@ -373,9 +399,10 @@ async function run(cfg) {
373
399
  return await upload(uploadURL, bundleFile).then((r) => {
374
400
  if (r.version) {
375
401
  console.log('Uploaded version ' + r.version + '!');
376
- return getQueue(r.version);
402
+ return getQueue(r.version, cfg);
377
403
  } else {
378
404
  console.error('Upload error:', r)
405
+ process.exit(1);
379
406
  }
380
407
  });
381
408
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@vkontakte/vk-miniapps-deploy",
3
- "version": "0.0.25",
3
+ "version": "0.1.2",
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
+ "publish": "npm publish --access=public"
9
10
  },
10
11
  "license": "MIT",
11
12
  "engines": {