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

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.
@@ -42,6 +42,13 @@ body:
42
42
  description: Если считаете, что из описания ожидаемое поведение непонятно.
43
43
  validations:
44
44
  required: true
45
+ - type: textarea
46
+ id: actual-behavior
47
+ attributes:
48
+ label: Фактическое поведение
49
+ description: Результат выполнения в текущей реализации.
50
+ validations:
51
+ required: true
45
52
  - type: textarea
46
53
  id: screenshots
47
54
  attributes:
@@ -0,0 +1,34 @@
1
+ name: Set Pay attention label for ignored issues
2
+ on:
3
+ schedule:
4
+ - cron: '0 10 * * 1-5'
5
+
6
+ jobs:
7
+ set-label-for-issues:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Set Pay attention label for ignored issues
11
+ uses: actions/github-script@v7
12
+ with:
13
+ github-token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
14
+ script: |
15
+ const issuesList = await github.rest.issues.listForRepo({
16
+ owner: context.repo.owner,
17
+ repo: context.repo.repo,
18
+ })
19
+ if (issuesList.data && issuesList.status === 200) {
20
+ for (const issue of issuesList.data) {
21
+ const createdDaysDelta = (new Date() - new Date(issue.created_at)) / (1000 * 60 * 60 * 24);
22
+
23
+ if (!issue.labels.length && (
24
+ (!issue.pull_request && createdDaysDelta > 2) || (issue.pull_request && createdDaysDelta > 7)
25
+ )) {
26
+ await github.rest.issues.addLabels({
27
+ owner: context.repo.owner,
28
+ repo: context.repo.repo,
29
+ issue_number: issue.number,
30
+ labels: ['pay attention']
31
+ });
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,48 @@
1
+ ## Установка
2
+
3
+ 1. Склонировать репозиторий и перейти в созданную директорию.
4
+ 2. Установить зависимости:
5
+ ```sh
6
+ yarn install
7
+ ```
8
+
9
+ ## Запуск и тестирование изменений
10
+
11
+ vk-miniapps-deploy является вспомогательной утилитой, поэтому изменения функционала этой библиотеки следует проверять в связке с вашими мини-приложениями. Для локальной проверки ваших изменений мы предлагаем механизм линковки пакетов через symlink.
12
+
13
+ 1. В корне данного проекта выполните команду:
14
+ ```sh
15
+ yarn link
16
+ ```
17
+ 2. В корне приложения, использующего vk-miniapps-deploy выполните команду:
18
+ ```sh
19
+ yarn link "@vkontakte/vk-miniapps-deploy"
20
+ ```
21
+
22
+ ## Проверка кода
23
+
24
+ Любые изменения в репозитории, должны проходить проверку линтерами. Для этого выполните команду:
25
+ ```sh
26
+ yarn lint:ci
27
+ ```
28
+
29
+ ## Создание pull request
30
+
31
+ - Создайте и перейдите в отдельную ветку. Название ветки должно начинаться с указания типа изменения feat для нового функционала или fix для исправления бага и краткой информации о ваших изменениях, например:
32
+ ```sh
33
+ git checkout -b fix/fix_token_restrictions
34
+ ```
35
+ - Добавьте файлы, которые хотите зафиксировать:
36
+ ```sh
37
+ git add <file_name>
38
+ ```
39
+ - Commit message должен начинаться с указания типа изменения feat для нового функционала или fix для исправления бага, а так же содержать описание изменения, которое вы вносите.
40
+ ```sh
41
+ git commit -m "[feat/fix]: commit message"
42
+ ```
43
+ - Выполните пуш ваших изменений в новую ветку:
44
+ ```sh
45
+ git push
46
+ ```
47
+ - Перейдите в раздел [Pull requests](https://github.com/VKCOM/vk-miniapps-deploy/pulls) и создайте новый pull request, используя наш шаблон.
48
+
package/index.js CHANGED
@@ -176,7 +176,30 @@ async function api(method, params) {
176
176
  const query = await fetch(API_HOST + method + '?' + queryParams);
177
177
  const res = await query.json();
178
178
  if (res.error !== void 0) {
179
- throw new Error(chalk.red(res.error.error_code + ': ' + res.error.error_msg));
179
+ const errorCode = res.error.error_code;
180
+ const errorMessage = chalk.red(errorCode + ': ' + res.error.error_msg);
181
+ if (errorCode === 5 && !process.env.MINI_APPS_ACCESS_TOKEN && !cfg.noprompt) {
182
+ console.error(errorMessage);
183
+
184
+ const questions = [
185
+ {
186
+ type: 'confirm',
187
+ initial: true,
188
+ name: 'updateToken',
189
+ message: chalk.yellow('Would you like to try to retrieve a new token?'),
190
+ },
191
+ ];
192
+
193
+ const { updateToken } = await prompt(questions);
194
+ if (updateToken) {
195
+ await retrieveAndSaveAccessToken(cfg);
196
+ return api(method, params);
197
+ } else {
198
+ throw new Error(errorMessage);
199
+ }
200
+ } else {
201
+ throw new Error(errorMessage);
202
+ }
180
203
  }
181
204
 
182
205
  if (res.response !== void 0) {
@@ -344,6 +367,22 @@ async function getQueue(version, cfg) {
344
367
  return handleQueue(r.app_id, r.base_url, r.key, r.ts, version, false, cfg);
345
368
  }
346
369
 
370
+ async function retrieveAndSaveAccessToken(cfg) {
371
+ console.log('Try to retrieve access token...');
372
+ const { access_token, expires_in } = await auth(cfg.app_id);
373
+ cfg.access_token = access_token;
374
+ vault.set('access_token', access_token);
375
+ vault.set('expires_in', expires_in);
376
+ console.log(chalk.cyan('Token is saved in config store!'));
377
+ console.log(
378
+ chalk.cyan(
379
+ '\nFor your CI, you can use \n > $ env MINI_APPS_ACCESS_TOKEN=' +
380
+ access_token +
381
+ ' yarn deploy',
382
+ ),
383
+ );
384
+ }
385
+
347
386
  async function run(cfg) {
348
387
  if (!configJSON) {
349
388
  throw new Error('For deploy you need to create config file "vk-hosting-config.json"');
@@ -383,32 +422,38 @@ async function run(cfg) {
383
422
  }
384
423
 
385
424
  if (!cfg.access_token || (cfg.expires_in > 0 && cfg.expires_in * 1000 < Date.now())) {
386
- console.log('Try to retrieve access token...');
387
- const { access_token, expires_in } = await auth(cfg.app_id);
388
- cfg.access_token = access_token;
389
- vault.set('access_token', access_token);
390
- vault.set('expires_in', expires_in);
391
- console.log(chalk.cyan('Token is saved in config store!'));
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
- );
425
+ await retrieveAndSaveAccessToken(cfg);
399
426
  }
400
427
 
401
428
  const params = {
402
429
  app_id: cfg.app_id,
403
430
  environment: environment,
404
- update_prod: +cfg.update_prod,
405
- update_dev: +cfg.update_dev,
406
431
  };
407
432
 
408
433
  if ('test_group_name' in cfg) {
409
434
  params.test_group_name = cfg.test_group_name;
410
435
  }
411
436
 
437
+ if ('update_prod' in cfg) {
438
+ const update_prod = Number(cfg.update_prod);
439
+
440
+ if (update_prod !== 0 && update_prod !== 1) {
441
+ throw new Error('update_prod must be 0 or 1 or boolean.');
442
+ }
443
+
444
+ params.update_prod = update_prod;
445
+ }
446
+
447
+ if ('update_dev' in cfg) {
448
+ const update_dev = Number(cfg.update_dev);
449
+
450
+ if (update_dev !== 0 && update_dev !== 1) {
451
+ throw new Error('update_dev must be 0 or 1 or boolean.');
452
+ }
453
+
454
+ params.update_dev = update_dev;
455
+ }
456
+
412
457
  const endpointPlatformKeys = Object.keys(cfg.endpoints);
413
458
  if (endpointPlatformKeys.length) {
414
459
  for (let i = 0; i < endpointPlatformKeys.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/vk-miniapps-deploy",
3
- "version": "0.1.9-rc.0",
3
+ "version": "0.1.9",
4
4
  "description": "Deploy to VK Mini Apps hosting with one simple command",
5
5
  "main": "index.js",
6
6
  "scripts": {