@itcase/config 1.7.26 → 1.7.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/config",
3
- "version": "1.7.26",
3
+ "version": "1.7.27",
4
4
  "author": "ITCase",
5
5
  "description": "ITCase Config",
6
6
  "engines": {
@@ -68,7 +68,7 @@
68
68
  "commitizen": "^4.3.2",
69
69
  "conventional-changelog-conventionalcommits": "9.3.1",
70
70
  "conventional-changelog-writer": "9.3.0",
71
- "cssnano": "^9.8.0",
71
+ "cssnano": "^9.9.0",
72
72
  "cssnano-preset-default": "^9.8.0",
73
73
  "inquirer": "^14.2.3",
74
74
  "log-update": "^8.0.0",
@@ -0,0 +1,161 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { readFileSync, writeFileSync } from 'node:fs'
3
+ import { join } from 'node:path'
4
+
5
+ const MAILRU_WEBDAV_BASE = 'https://webdav.cloud.mail.ru'
6
+
7
+ /**
8
+ * Prepare: bump Android → make APK → Mail.ru (если GIT_WORKFLOW=true).
9
+ *
10
+ * Env: SKIP_APK_BUILD, RELEASE_APK_TARGETS (stage,prod),
11
+ * MAILRU_USER, MAILRU_APP_PASSWORD, MAILRU_PUBLIC_URL.
12
+ *
13
+ * @param {{ apkPrefix: string, mailruDir: string }} options
14
+ */
15
+ function createAndroidAppPreparePlugin({ apkPrefix, mailruDir }) {
16
+ if (!apkPrefix) {
17
+ throw new Error('createAndroidAppPreparePlugin: apkPrefix is required')
18
+ }
19
+ if (!mailruDir) {
20
+ throw new Error('createAndroidAppPreparePlugin: mailruDir is required')
21
+ }
22
+
23
+ const uploadDir = mailruDir.replace(/^\/+|\/+$/g, '')
24
+
25
+ return {
26
+ prepare: async (_pluginConfig, context) => {
27
+ const { logger, nextRelease, options } = context
28
+ const version = nextRelease.version
29
+
30
+ bumpAndroidVersion(version, logger)
31
+
32
+ if (options.dryRun || process.env.SKIP_APK_BUILD === '1') {
33
+ logger.log('Skip APK build (dry-run or SKIP_APK_BUILD=1)')
34
+ return
35
+ }
36
+
37
+ const apks = resolveApks(apkPrefix, version)
38
+ for (const apk of apks) {
39
+ logger.log(`make ${apk.make}`)
40
+ execFileSync('make', [apk.make], { stdio: 'inherit' })
41
+ }
42
+
43
+ uploadApks(apks, uploadDir, logger)
44
+ },
45
+ }
46
+ }
47
+
48
+ function bumpAndroidVersion(version, logger) {
49
+ if (!/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
50
+ throw new Error(`Unsupported version format: "${version}"`)
51
+ }
52
+
53
+ const gradlePath = join(process.cwd(), 'android/app/build.gradle')
54
+ const content = readFileSync(gradlePath, 'utf8')
55
+ const vNameMatch = content.match(/def vName = "([^"]+)"/)
56
+ const vCodeMatch = content.match(/def vCode = (\d+)/)
57
+
58
+ if (!vNameMatch || !vCodeMatch) {
59
+ throw new Error('Could not find version in build.gradle')
60
+ }
61
+
62
+ if (vNameMatch[1] === version) {
63
+ logger.log(`Android vName already ${version}, skip bump`)
64
+ return
65
+ }
66
+
67
+ const newCode = Number(vCodeMatch[1]) + 1
68
+ writeFileSync(
69
+ gradlePath,
70
+ content
71
+ .replace(/def vName = "[^"]+"/, `def vName = "${version}"`)
72
+ .replace(/def vCode = \d+/, `def vCode = ${newCode}`),
73
+ )
74
+ logger.log(`Android vName = ${version}, vCode = ${newCode}`)
75
+ }
76
+
77
+ /** @returns {{ make: string, name: string, fileName: string }[]} */
78
+ function resolveApks(apkPrefix, version) {
79
+ const defs = {
80
+ prod: {
81
+ name: 'PROD',
82
+ fileName: `${apkPrefix}-v${version}.apk`,
83
+ make: 'android-apk-prod',
84
+ },
85
+ stage: {
86
+ name: 'STAGE',
87
+ fileName: `${apkPrefix}-v${version}-STAGE.apk`,
88
+ make: 'android-apk-stage',
89
+ },
90
+ }
91
+
92
+ const keys = (process.env.RELEASE_APK_TARGETS || 'stage,prod')
93
+ .split(',')
94
+ .map((part) => part.trim())
95
+ .filter(Boolean)
96
+
97
+ if (keys.length === 0) {
98
+ throw new Error('RELEASE_APK_TARGETS is empty')
99
+ }
100
+
101
+ return keys.map((key) => {
102
+ const apk = defs[key]
103
+ if (!apk) {
104
+ throw new Error(
105
+ `Unknown RELEASE_APK_TARGETS entry: "${key}". Use stage, prod`,
106
+ )
107
+ }
108
+ return apk
109
+ })
110
+ }
111
+
112
+ function uploadApks(apks, uploadDir, logger) {
113
+ if (process.env.GIT_WORKFLOW !== 'true') {
114
+ logger.log('Skip Mail.ru upload (not CI)')
115
+ return
116
+ }
117
+
118
+ const user = process.env.MAILRU_USER
119
+ const password = process.env.MAILRU_APP_PASSWORD
120
+ const publicUrl = (process.env.MAILRU_PUBLIC_URL || '').replace(/\/$/, '')
121
+
122
+ if (!user || !password || !publicUrl) {
123
+ throw new Error(
124
+ 'MAILRU_USER, MAILRU_APP_PASSWORD and MAILRU_PUBLIC_URL are required',
125
+ )
126
+ }
127
+
128
+ const uploadBase = `${MAILRU_WEBDAV_BASE}/${uploadDir}`
129
+ const downloads = []
130
+
131
+ for (const apk of apks) {
132
+ logger.log(`Upload ${apk.fileName} to ${uploadBase}/`)
133
+ execFileSync(
134
+ 'curl',
135
+ [
136
+ '--fail',
137
+ '--silent',
138
+ '--show-error',
139
+ '--retry',
140
+ '2',
141
+ '--retry-delay',
142
+ '2',
143
+ '-T',
144
+ join(process.cwd(), 'builds', apk.fileName),
145
+ '--user',
146
+ `${user}:${password}`,
147
+ `${uploadBase}/${apk.fileName}`,
148
+ ],
149
+ { stdio: 'inherit' },
150
+ )
151
+ downloads.push({ name: apk.name, url: `${publicUrl}/${apk.fileName}` })
152
+ }
153
+
154
+ writeFileSync(
155
+ join(process.cwd(), 'builds', 'mailru-downloads.json'),
156
+ JSON.stringify(downloads),
157
+ )
158
+ logger.log('APK upload finished — Mail.ru links saved')
159
+ }
160
+
161
+ export { createAndroidAppPreparePlugin }
@@ -1,7 +1,4 @@
1
- import {
2
- createSemanticReleaseApp,
3
- semanticReleaseApp,
4
- } from './semanticReleaseApp.js'
1
+ import { semanticReleaseApp } from './semanticReleaseApp.js'
5
2
  import { semanticReleaseBot } from './semanticReleaseBot.js'
6
3
  import { semanticReleaseDoc } from './semanticReleaseDoc.js'
7
4
  import { semanticReleaseMonorepo } from './semanticReleaseMonorepo.js'
@@ -10,7 +7,6 @@ import { semanticReleaseProject } from './semanticReleaseProject.js'
10
7
  import { semanticReleaseVSMarketplace } from './semanticReleaseVSMarketplace.js'
11
8
 
12
9
  export {
13
- createSemanticReleaseApp,
14
10
  semanticReleaseApp,
15
11
  semanticReleaseBot,
16
12
  semanticReleaseDoc,
@@ -1,3 +1,4 @@
1
+ import { createAndroidAppPreparePlugin } from './androidAppPrepare.js'
1
2
  import {
2
3
  createSemanticReleaseConfig,
3
4
  releaseNotesFromIssuesPlugin,
@@ -17,27 +18,44 @@ const DEFAULT_RELEASE_ASSETS = ['builds/*.apk']
17
18
  *
18
19
  * - Не публикует в npm
19
20
  * - Коммитит package + Android version-файлы
20
- * - Прикрепляет к GitHub release APK из `builds/` (если есть; отсутствующие пропускаются)
21
- * - Заметки релиза: сначала задачи из releaseNotesFromIssues.js, если они есть, потом обычные коммиты
21
+ * - Прикрепляет к GitHub release APK из `builds/`
22
+ * - Заметки релиза: сначала задачи, потом коммиты
22
23
  *
23
- * Сборку APK делайте в prepare проекта или отдельным CI job до publish.
24
+ * Если передан `apk`, в prepare: bump → make → Mail.ru (GIT_WORKFLOW=true).
24
25
  *
25
26
  * @param {Object} [options]
26
27
  * @param {string|string[]} [options.branches=['master']]
27
- * @param {string[]} [options.versionAssets] - файлы для @semantic-release/git
28
- * @param {string[]|Object[]} [options.releaseAssets] - assets для @semantic-release/github
29
- * @param {Array} [options.preparePlugins] - плагины после npm (например bump Android version + build APK)
30
- * @param {Object} [options.githubConfig] - доп. опции github-плагина
31
- * @param {Object} [options.gitConfig] - доп. опции git-плагина (мержатся поверх message/assets)
28
+ * @param {Object} [options.apk]
29
+ * @param {string} options.apk.prefix - agro-pps → builds/agro-pps-v*.apk
30
+ * @param {string} options.apk.mailruDir - папка WebDAV, напр. APK
31
+ * @param {string[]} [options.versionAssets]
32
+ * @param {string[]|Object[]} [options.releaseAssets] - по умолчанию builds/{prefix}-v*.apk
33
+ * @param {Array} [options.preparePlugins]
34
+ * @param {Object} [options.githubConfig]
35
+ * @param {Object} [options.gitConfig]
32
36
  */
33
- function createSemanticReleaseApp({
37
+ function semanticReleaseApp({
38
+ apk,
34
39
  branches = ['master'],
35
40
  gitConfig = {},
36
41
  githubConfig = {},
37
42
  preparePlugins = [],
38
- releaseAssets = DEFAULT_RELEASE_ASSETS,
43
+ releaseAssets,
39
44
  versionAssets = DEFAULT_VERSION_ASSETS,
40
45
  } = {}) {
46
+ const androidPrepare = apk
47
+ ? [
48
+ createAndroidAppPreparePlugin({
49
+ apkPrefix: apk.prefix,
50
+ mailruDir: apk.mailruDir,
51
+ }),
52
+ ]
53
+ : []
54
+
55
+ const githubAssets =
56
+ releaseAssets ??
57
+ (apk?.prefix ? [`builds/${apk.prefix}-v*.apk`] : DEFAULT_RELEASE_ASSETS)
58
+
41
59
  return createSemanticReleaseConfig({
42
60
  additionalPlugins: [releaseNotesFromIssuesPlugin],
43
61
  branches: branches,
@@ -48,16 +66,14 @@ function createSemanticReleaseApp({
48
66
  ...gitConfig,
49
67
  },
50
68
  githubConfig: {
51
- assets: releaseAssets,
69
+ assets: githubAssets,
52
70
  ...githubConfig,
53
71
  },
54
72
  npmConfig: {
55
73
  npmPublish: false,
56
74
  },
57
- preparePlugins: preparePlugins,
75
+ preparePlugins: [...androidPrepare, ...preparePlugins],
58
76
  })
59
77
  }
60
78
 
61
- const semanticReleaseApp = createSemanticReleaseApp()
62
-
63
- export { createSemanticReleaseApp, semanticReleaseApp }
79
+ export { semanticReleaseApp }