@vv0rkz/js-template 1.5.2 → 1.6.1

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/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { execSync, spawnSync } from 'child_process'
2
+ import { spawnSync } from 'child_process'
3
3
  import { platform } from 'os'
4
4
  import { dirname, join } from 'path'
5
5
  import { fileURLToPath } from 'url'
@@ -36,36 +36,7 @@ const commands = {
36
36
  },
37
37
 
38
38
  release: () => {
39
- console.log('🚀 Запуск релиза...\n')
40
-
41
- // 1. Проверка демо
42
- const checkDemo = spawnSync('node', [join(toolsDir, 'check-demo-for-release.js')], { stdio: 'inherit' })
43
- if (checkDemo.status !== 0) {
44
- console.error('❌ Проверка демо не прошла')
45
- process.exit(1)
46
- }
47
-
48
- // 2. Определяем тип bump из коммитов
49
- const commitMessages = execSync('git log --oneline -10', { encoding: 'utf8' })
50
- const bumpType = commitMessages.includes('feat:') ? 'minor' : 'patch'
51
-
52
- // 3. Создаём changelog
53
- const changelog = spawnSync(npxCmd, ['changelogen', '--release', '--bump', bumpType], { stdio: 'inherit' })
54
- if (changelog.status !== 0) {
55
- console.error('❌ Ошибка создания changelog')
56
- process.exit(1)
57
- }
58
-
59
- // 4. Обновляем README ← ДОБАВЬ ЭТО
60
- console.log('\n📝 Обновление README...')
61
- const updateReadme = spawnSync('node', [join(toolsDir, 'update-readme.js')], { stdio: 'inherit' })
62
- if (updateReadme.status !== 0) {
63
- console.log('⚠️ README не обновлён (возможно нет секции AUTOGENERATED)')
64
- }
65
-
66
- console.log('\n✅ Релиз успешно создан!')
67
- console.log('💡 Теперь можно:')
68
- console.log(' npm run _ push-release # Запушить в main')
39
+ spawnSync('node', [join(toolsDir, 'release.js')], { stdio: 'inherit' })
69
40
  },
70
41
 
71
42
  'update-readme': () => {
package/bin/init.js CHANGED
@@ -192,6 +192,24 @@ const initReadme = spawnSync('node', [join(toolsDir, 'init-readme.js')], { stdio
192
192
  if (initReadme.status === 0) {
193
193
  console.log(' ✅ README.md создан')
194
194
  }
195
+ // 9. Проверка на версию
196
+ const packageJson = JSON.parse(readFileSync('package.json', 'utf8'))
197
+
198
+ // Проверка версии
199
+ const currentVersion = packageJson.version || '1.0.0'
200
+ if (currentVersion.startsWith('0.')) {
201
+ console.log('\n⚠️ ВНИМАНИЕ: Текущая версия ' + currentVersion + ' (0.x.x)')
202
+ console.log('💡 Рекомендуется начинать с версии 1.0.0 для корректной работы changelogen')
203
+ console.log(' Причина: https://github.com/conventional-changelog/standard-version/issues/539\n')
204
+
205
+ const answer = await askQuestion('Изменить версию на 1.0.0? (Y/n): ')
206
+
207
+ if (answer.toLowerCase() !== 'n' && answer.toLowerCase() !== 'no') {
208
+ packageJson.version = '1.0.0'
209
+ writeFileSync('package.json', JSON.stringify(packageJson, null, 2))
210
+ console.log('✅ Версия изменена на 1.0.0')
211
+ }
212
+ }
195
213
 
196
214
  console.log(`
197
215
  🎉 JS Template успешно установлен!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vv0rkz/js-template",
3
- "version": "1.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "Reusable setup for JS projects with husky, changelog, gh tools",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { execSync, spawnSync } from 'child_process'
3
+ import { platform } from 'os'
4
+ import { dirname, join } from 'path'
5
+ import { fileURLToPath } from 'url'
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
+ const isWin = platform() === 'win32'
9
+ const npxCmd = isWin ? 'npx.cmd' : 'npx'
10
+
11
+ console.log('🚀 Запуск релиза...\n')
12
+
13
+ // 1. Проверка демо
14
+ const checkDemo = spawnSync('node', [join(__dirname, 'check-demo-for-release.js')], { stdio: 'inherit' })
15
+ if (checkDemo.status !== 0) {
16
+ console.error('❌ Проверка демо не прошла')
17
+ process.exit(1)
18
+ }
19
+
20
+ // 2. Получаем текущую версию
21
+ const currentVersion = JSON.parse(execSync('npm pkg get version', { encoding: 'utf8' })).replace(/"/g, '')
22
+ console.log(`📦 Текущая версия: ${currentVersion}`)
23
+
24
+ // 3. Предупреждение для 0.x.x
25
+ if (currentVersion.startsWith('0.')) {
26
+ console.log('\n⚠️ ВНИМАНИЕ: Версия 0.x.x имеет особое поведение!')
27
+ console.log('💡 changelogen для версий < 1.0.0:')
28
+ console.log(' • feat: коммиты → patch bump (0.1.0 → 0.1.1)')
29
+ console.log(' • fix: коммиты → patch bump (0.1.0 → 0.1.1)')
30
+ console.log(' • BREAKING CHANGE → minor bump (0.1.0 → 0.2.0)')
31
+ console.log('')
32
+ console.log('📖 Подробнее: https://github.com/conventional-changelog/standard-version/issues/539')
33
+ console.log('✅ Рекомендация: используй версии ≥ 1.0.0 для правильного semver')
34
+ console.log(' Обнови: npm pkg set version=1.0.0 && git tag v1.0.0\n')
35
+ }
36
+
37
+ // 4. Анализ коммитов
38
+ let lastTag = ''
39
+ try {
40
+ lastTag = execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim()
41
+ console.log(`📌 Последний тег: ${lastTag}`)
42
+ } catch (error) {
43
+ console.log('📌 Теги не найдены (первый релиз)')
44
+ }
45
+
46
+ const commitMessages = lastTag
47
+ ? execSync(`git log ${lastTag}..HEAD --format=%s`, { encoding: 'utf8' })
48
+ : execSync('git log --format=%s -10', { encoding: 'utf8' })
49
+
50
+ const commits = commitMessages.split('\n').filter(Boolean)
51
+
52
+ const featCount = commits.filter((c) => c.startsWith('feat:')).length
53
+ const fixCount = commits.filter((c) => c.startsWith('fix:')).length
54
+ const refactorCount = commits.filter((c) => c.startsWith('refactor:')).length
55
+ const perfCount = commits.filter((c) => c.startsWith('perf:')).length
56
+ const docsCount = commits.filter((c) => c.startsWith('docs:')).length
57
+ const buildCount = commits.filter((c) => c.startsWith('build:')).length
58
+
59
+ console.log('\n📊 Анализ коммитов:')
60
+ if (featCount > 0) console.log(` ✨ feat: ${featCount}`)
61
+ if (fixCount > 0) console.log(` 🐛 fix: ${fixCount}`)
62
+ if (refactorCount > 0) console.log(` ♻️ refactor: ${refactorCount}`)
63
+ if (perfCount > 0) console.log(` ⚡ perf: ${perfCount}`)
64
+ if (docsCount > 0) console.log(` 📚 docs: ${docsCount}`)
65
+ if (buildCount > 0) console.log(` 🏗️ build: ${buildCount}`)
66
+
67
+ // 5. Определяем bump type
68
+ const isV0 = currentVersion.startsWith('0.')
69
+ let bumpType = 'patch'
70
+
71
+ if (isV0) {
72
+ // Для 0.x.x используем --major чтобы получить minor bump при feat
73
+ bumpType = featCount > 0 ? 'major' : 'patch'
74
+ console.log(`\n🔢 Bump type: ${bumpType === 'major' ? 'major (для 0.x.x это даст minor)' : 'patch'}`)
75
+ } else {
76
+ // Для ≥1.0.0 нормальное поведение
77
+ bumpType = featCount > 0 ? 'minor' : 'patch'
78
+ console.log(`\n🔢 Bump type: ${bumpType}`)
79
+ }
80
+
81
+ // 6. Создаём changelog
82
+ console.log('\n📝 Создание changelog...')
83
+ const changelog = spawnSync(npxCmd, ['changelogen', '--release', `--${bumpType}`], {
84
+ stdio: 'inherit',
85
+ })
86
+
87
+ if (changelog.status !== 0) {
88
+ console.error('\n❌ Ошибка создания changelog')
89
+ console.log('💡 Попробуй вручную: npx changelogen --release')
90
+ process.exit(1)
91
+ }
92
+
93
+ // 7. Обновляем README
94
+ console.log('\n📝 Обновление README...')
95
+ const updateReadme = spawnSync('node', [join(__dirname, 'update-readme.js')], { stdio: 'inherit' })
96
+ if (updateReadme.status !== 0) {
97
+ console.log('⚠️ README не обновлён (возможно нет секции AUTOGENERATED)')
98
+ }
99
+
100
+ console.log('\n✅ Релиз успешно создан!')
101
+ console.log('💡 Теперь можно:')
102
+ console.log(' npm run _ push-release # Создать PR и смерджить в main')