@vv0rkz/js-template 1.4.4 → 1.5.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,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { fileURLToPath } from 'url'
3
- import { dirname, join } from 'path'
4
2
  import { spawnSync } from 'child_process'
5
3
  import { platform } from 'os'
4
+ import { dirname, join } from 'path'
5
+ import { fileURLToPath } from 'url'
6
6
 
7
7
  const __dirname = dirname(fileURLToPath(import.meta.url))
8
8
  const toolsDir = join(__dirname, '../tools-gh')
@@ -38,20 +38,34 @@ const commands = {
38
38
  release: () => {
39
39
  console.log('🚀 Запуск релиза...\n')
40
40
 
41
+ // 1. Проверка демо
41
42
  const checkDemo = spawnSync('node', [join(toolsDir, 'check-demo-for-release.js')], { stdio: 'inherit' })
42
43
  if (checkDemo.status !== 0) {
43
44
  console.error('❌ Проверка демо не прошла')
44
45
  process.exit(1)
45
46
  }
46
47
 
47
- const changelog = spawnSync(npxCmd, ['changelogen', '--release'], { stdio: 'inherit' })
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' })
48
54
  if (changelog.status !== 0) {
49
55
  console.error('❌ Ошибка создания changelog')
50
56
  process.exit(1)
51
57
  }
52
58
 
53
- spawnSync('node', [join(toolsDir, 'update-readme.js')], { stdio: 'inherit' })
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
+
54
66
  console.log('\n✅ Релиз успешно создан!')
67
+ console.log('💡 Теперь можно:')
68
+ console.log(' npm run _ push-release # Запушить в main')
55
69
  },
56
70
 
57
71
  'update-readme': () => {
@@ -92,10 +106,74 @@ const commands = {
92
106
  }
93
107
  },
94
108
 
109
+ 'create-refactor': () => {
110
+ const args = process.argv.slice(3)
111
+ spawnSync('node', [join(toolsDir, 'create-refactor.js'), ...args], { stdio: 'inherit' })
112
+ },
113
+
114
+ refactors: () => {
115
+ spawnSync(ghCmd, ['issue', 'list', '--label', 'refactor'], { stdio: 'inherit' })
116
+ },
117
+
118
+ 'create-perf': () => {
119
+ const args = process.argv.slice(3)
120
+ spawnSync('node', [join(toolsDir, 'create-perf.js'), ...args], { stdio: 'inherit' })
121
+ },
122
+
123
+ perfs: () => {
124
+ spawnSync(ghCmd, ['issue', 'list', '--label', 'perf'], { stdio: 'inherit' })
125
+ },
126
+
95
127
  'all-issues': () => {
96
128
  // БЕЗ shell: true
97
129
  spawnSync(ghCmd, ['issue', 'list', '--state', 'open'], { stdio: 'inherit' })
98
130
  },
131
+ 'pr-list': () => {
132
+ console.log('📋 Список Pull Requests...\n')
133
+ spawnSync('gh', ['pr', 'list'], { stdio: 'inherit' })
134
+ },
135
+
136
+ 'pr-view': () => {
137
+ const prNumber = process.argv[3]
138
+ if (!prNumber) {
139
+ console.log('❌ Укажи номер PR: npm run _ pr-view 5')
140
+ process.exit(1)
141
+ }
142
+ console.log(`👀 Просмотр PR #${prNumber}...\n`)
143
+ spawnSync('gh', ['pr', 'view', prNumber], { stdio: 'inherit' })
144
+ },
145
+
146
+ 'pr-view-web': () => {
147
+ const prNumber = process.argv[3]
148
+ if (!prNumber) {
149
+ console.log('❌ Укажи номер PR: npm run _ pr-view-web 5')
150
+ process.exit(1)
151
+ }
152
+ console.log(`🌐 Открываю PR #${prNumber} в браузере...`)
153
+ spawnSync('gh', ['pr', 'view', prNumber, '--web'], { stdio: 'inherit' })
154
+ },
155
+
156
+ 'pr-merge': () => {
157
+ const prNumber = process.argv[3]
158
+ if (!prNumber) {
159
+ console.log('❌ Укажи номер PR: npm run _ pr-merge 5')
160
+ process.exit(1)
161
+ }
162
+ console.log(`🔀 Мерджу PR #${prNumber}...\n`)
163
+ spawnSync('gh', ['pr', 'merge', prNumber, '--merge'], { stdio: 'inherit' })
164
+ console.log('\n✅ PR смерджен!')
165
+ },
166
+
167
+ 'pr-close': () => {
168
+ const prNumber = process.argv[3]
169
+ if (!prNumber) {
170
+ console.log('❌ Укажи номер PR: npm run _ pr-close 5')
171
+ process.exit(1)
172
+ }
173
+ console.log(`❌ Закрываю PR #${prNumber}...\n`)
174
+ spawnSync('gh', ['pr', 'close', prNumber], { stdio: 'inherit' })
175
+ console.log('\n✅ PR закрыт!')
176
+ },
99
177
  }
100
178
 
101
179
  if (commands[command]) {
@@ -104,32 +182,44 @@ if (commands[command]) {
104
182
  console.log(`
105
183
  ⚡ JS Template CLI
106
184
 
107
- Использование: jst <команда> [аргументы]
185
+ Использование: npm run _ <команда> [аргументы]
108
186
 
109
187
  📋 ПРОЕКТ:
110
- jst init Инициализация проекта
111
- jst init-readme Создать стартовый README.md
112
- jst setup-labels Настроить GitHub labels
188
+ init Инициализация проекта
189
+ init-readme Создать стартовый README.md
190
+ setup-labels Настроить GitHub labels
113
191
 
114
192
  🔧 РАЗРАБОТКА:
115
- jst changelog Создать changelog
116
- jst release Полный релиз (проверка + changelog + README)
117
- jst update-readme Обновить README
118
- jst push-release Запушить релиз в main
119
-
120
- 📝 ЗАДАЧИ:
121
- jst tasks Список открытых задач
122
- jst create-task [название] Создать задачу
123
- jst bugs Список открытых багов
124
- jst create-bug [название] Создать баг
125
- jst all-issues Все открытые issues
193
+ update-readme Обновить README с версией
194
+ release Полный релиз (проверка + changelog + README)
195
+ push-release Создать PR и смерджить в main
196
+
197
+ 📝 ISSUES:
198
+ tasks Список задач (фичи)
199
+ create-task [название] Создать задачу
200
+ bugs Список багов
201
+ create-bug [название] Создать баг
202
+ refactors Список рефакторингов
203
+ create-refactor [название] Создать рефакторинг
204
+ perfs Список оптимизаций
205
+ create-perf [название] Создать оптимизацию
206
+ all-issues Все issues
207
+
208
+ 🔀 PULL REQUESTS:
209
+ pr-list Показать все PR
210
+ pr-view <number> Посмотреть PR в терминале
211
+ pr-view-web <number> Открыть PR в браузере
212
+ pr-merge <number> Смерджить PR
213
+ pr-close <number> Закрыть PR без merge
126
214
 
127
215
  📚 ПРИМЕРЫ:
128
- jst init
129
- jst init-readme
130
- jst create-task "Добавить темную тему"
131
- jst release
132
- jst tasks
216
+ npm run _ init
217
+ npm run _ init-readme
218
+ npm run _ feat "Добавить темную тему"
219
+ npm run _ release
220
+ npm run _ pr-list
221
+ npm run _ pr-merge 5
222
+
133
223
  `)
134
224
  process.exit(command ? 1 : 0)
135
225
  }
package/bin/init.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { fileURLToPath } from 'url'
3
- import { dirname, join } from 'path'
4
- import { copyFileSync, mkdirSync, existsSync, readFileSync, writeFileSync, readdirSync, statSync, unlinkSync } from 'fs'
5
2
  import { execSync, spawnSync } from 'child_process'
3
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'fs'
4
+ import { dirname, join } from 'path'
6
5
  import * as readline from 'readline'
6
+ import { fileURLToPath } from 'url'
7
7
 
8
8
  const __dirname = dirname(fileURLToPath(import.meta.url))
9
9
  const templateDir = join(__dirname, '../templates')
@@ -186,6 +186,13 @@ try {
186
186
  console.log(' Запусти позже: npm run _ setup-labels')
187
187
  }
188
188
 
189
+ // 8. Инициализация README
190
+ console.log('\n📝 Инициализация README...')
191
+ const initReadme = spawnSync('node', [join(toolsDir, 'init-readme.js')], { stdio: 'inherit' })
192
+ if (initReadme.status === 0) {
193
+ console.log(' ✅ README.md создан')
194
+ }
195
+
189
196
  console.log(`
190
197
  🎉 JS Template успешно установлен!
191
198
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vv0rkz/js-template",
3
- "version": "1.4.4",
3
+ "version": "1.5.1",
4
4
  "description": "Reusable setup for JS projects with husky, changelog, gh tools",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,9 +1,9 @@
1
1
  export default {
2
- types: {
3
- feat: { title: "Фичи" },
4
- fix: { title: "🐛 Исправленные баги" },
5
- build: { title: "🏗️ Инфраструктура" },
6
- refactor: { title: "🔧 Рефакторинг", hidden: true },
7
- chore: { title: "🛠️ Технические задачи", hidden: true },
8
- },
2
+ types: {
3
+ feat: { title: 'Новые фичи', semver: 'minor' },
4
+ fix: { title: '🐛 Исправления', semver: 'patch' },
5
+ refactor: { title: '♻️ Рефакторинг', semver: 'patch' },
6
+ perf: { title: '⚡ Оптимизация', semver: 'patch' },
7
+ },
8
+ contributors: false,
9
9
  }
@@ -1,53 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from 'child_process'
2
+ import { createIssue } from './create-issue.js'
3
3
 
4
- const args = process.argv.slice(2)
5
- const title = args.join(' ')
6
-
7
- if (!title) {
8
- console.log('❌ Использование: jst create-bug "описание бага"')
9
- console.log(' или: npm run _ create-bug "описание бага"')
10
- process.exit(1)
11
- }
12
-
13
- try {
14
- console.log('🐛 Создаю баг...')
15
-
16
- // Создаем issue в GitHub
17
- execSync(`gh issue create --title "Bug: ${title}" --body "Баг обнаружен" --label "bug" --assignee "@me"`, {
18
- stdio: 'inherit',
19
- })
20
-
21
- console.log('🐛 Баг зарегистрирован!')
22
- } catch (error) {
23
- // Если ошибка с label - создаём его автоматически
24
- if (error.message.includes("'bug' not found") || error.stderr?.includes("'bug' not found")) {
25
- console.log("\n⚠️ Label 'bug' не найден. Создаю автоматически...")
26
-
27
- try {
28
- // Создаём label
29
- execSync('gh label create bug --color "D73A4A" --description "Баг который нужно исправить"', { stdio: 'ignore' })
30
- console.log("✅ Label 'bug' создан")
31
-
32
- // Пытаемся создать баг ещё раз
33
- console.log('🐛 Создаю баг...')
34
- execSync(`gh issue create --title "Bug: ${title}" --body "Баг обнаружен" --label "bug" --assignee "@me"`, {
35
- stdio: 'inherit',
36
- })
37
-
38
- console.log('🐛 Баг зарегистрирован!')
39
- } catch (retryError) {
40
- console.error('❌ Ошибка создания бага:', retryError.message)
41
- console.log('\n💡 Попробуй:')
42
- console.log(' npm run _ setup-labels')
43
- process.exit(1)
44
- }
45
- } else {
46
- console.error('❌ Ошибка создания бага:', error.message)
47
- console.log('\n💡 Убедись что:')
48
- console.log(' 1. Установлен GitHub CLI: gh --version')
49
- console.log(' 2. Выполнена авторизация: gh auth login')
50
- console.log(' 3. Создан репозиторий на GitHub')
51
- process.exit(1)
52
- }
53
- }
4
+ createIssue('bug', '🐛', 'Исправление бага')
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ import { execSync, spawnSync } from 'child_process'
3
+ import { dirname, join } from 'path'
4
+ import { fileURLToPath } from 'url'
5
+
6
+ const __dirname = dirname(fileURLToPath(import.meta.url))
7
+
8
+ /**
9
+ * Создаёт GitHub issue с автоматической настройкой labels
10
+ * @param {string} type - Тип issue (feat, fix, refactor, perf)
11
+ * @param {string} emoji - Эмодзи для вывода
12
+ * @param {string} description - Описание действия
13
+ */
14
+ export function createIssue(type, emoji, description) {
15
+ console.log(`${emoji} Создаю задачу на ${description}...`)
16
+
17
+ const title = process.argv.slice(2).join(' ')
18
+
19
+ if (!title) {
20
+ console.log('❌ Укажи название задачи')
21
+ console.log(` Пример: npm run _ ${type} "Название задачи"`)
22
+ process.exit(1)
23
+ }
24
+
25
+ const issueTitle = `${type.charAt(0).toUpperCase() + type.slice(1)}: ${title}`
26
+ const issueBody = `${description}: ${title}`
27
+
28
+ try {
29
+ execSync(`gh issue create --title "${issueTitle}" --body "${issueBody}" --label "${type}"`, { stdio: 'inherit' })
30
+ console.log('\n✅ Задача создана!')
31
+ } catch (error) {
32
+ // Если ошибка с label - запускаем setup-labels
33
+ if (error.message.includes('not found') || error.message.includes('label')) {
34
+ console.log(`\n⚠️ Label "${type}" не найден`)
35
+ console.log('🔧 Настраиваю labels...\n')
36
+
37
+ spawnSync('node', [join(__dirname, 'setup-labels.js')], { stdio: 'inherit' })
38
+
39
+ console.log('\n🔄 Повторяю создание задачи...\n')
40
+ try {
41
+ execSync(`gh issue create --title "${issueTitle}" --body "${issueBody}" --label "${type}"`, {
42
+ stdio: 'inherit',
43
+ })
44
+ console.log('\n✅ Задача создана!')
45
+ } catch (retryError) {
46
+ console.error('❌ Ошибка создания задачи:', retryError.message)
47
+ process.exit(1)
48
+ }
49
+ } else {
50
+ console.error('❌ Ошибка создания задачи:', error.message)
51
+ console.log('\n💡 Убедись что:')
52
+ console.log(' 1. Установлен GitHub CLI: gh --version')
53
+ console.log(' 2. Выполнена авторизация: gh auth login')
54
+ console.log(' 3. Создан репозиторий на GitHub')
55
+ process.exit(1)
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { createIssue } from './create-issue.js'
3
+
4
+ createIssue('perf', '⚡', 'Оптимизация')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { createIssue } from './create-issue.js'
3
+
4
+ createIssue('refactor', '♻️', 'Рефакторинг')
@@ -1,53 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from 'child_process'
2
+ import { createIssue } from './create-issue.js'
3
3
 
4
- const args = process.argv.slice(2)
5
- const title = args.join(' ')
6
-
7
- if (!title) {
8
- console.log('❌ Использование: jst create-task "описание задачи"')
9
- console.log(' или: npm run _ create-task "описание задачи"')
10
- process.exit(1)
11
- }
12
-
13
- try {
14
- console.log('📝 Создаю задачу...')
15
-
16
- // Пытаемся создать задачу с label
17
- execSync(`gh issue create --title "Task: ${title}" --body "Задача: ${title}" --label "task"`, {
18
- stdio: 'inherit',
19
- })
20
-
21
- console.log('✅ Задача создана! Используй номер в коммитах: feat: #номер описание')
22
- } catch (error) {
23
- // Если ошибка с label - создаём его автоматически
24
- if (error.message.includes("'task' not found") || error.stderr?.includes("'task' not found")) {
25
- console.log("\n⚠️ Label 'task' не найден. Создаю автоматически...")
26
-
27
- try {
28
- // Создаём label
29
- execSync('gh label create task --color "0E8A16" --description "Задача для реализации"', { stdio: 'ignore' })
30
- console.log("✅ Label 'task' создан")
31
-
32
- // Пытаемся создать задачу ещё раз
33
- console.log('📝 Создаю задачу...')
34
- execSync(`gh issue create --title "Task: ${title}" --body "Задача: ${title}" --label "task"`, {
35
- stdio: 'inherit',
36
- })
37
-
38
- console.log('✅ Задача создана!')
39
- } catch (retryError) {
40
- console.error('❌ Ошибка создания задачи:', retryError.message)
41
- console.log('\n💡 Попробуй:')
42
- console.log(' npm run _ setup-labels')
43
- process.exit(1)
44
- }
45
- } else {
46
- console.error('❌ Ошибка создания задачи:', error.message)
47
- console.log('\n💡 Убедись что:')
48
- console.log(' 1. Установлен GitHub CLI: gh --version')
49
- console.log(' 2. Выполнена авторизация: gh auth login')
50
- console.log(' 3. Создан репозиторий на GitHub')
51
- process.exit(1)
52
- }
53
- }
4
+ createIssue('task', '✨', 'Новая фича')
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync } from 'child_process'
3
3
 
4
- console.log('🚀 Мердж релизной ветки в main...')
4
+ console.log('🚀 Создание Pull Request для релиза...')
5
5
 
6
6
  try {
7
7
  // 1. Получаем текущую ветку
@@ -22,27 +22,52 @@ try {
22
22
  process.exit(1)
23
23
  }
24
24
 
25
- // 3. Определяем главную ветку (main или master)
25
+ // 3. Проверяем что ветка запушена
26
+ console.log('📤 Пушим изменения в удалённую ветку...')
27
+ try {
28
+ execSync(`git push origin ${currentBranch} --follow-tags`, { stdio: 'inherit' })
29
+ } catch (error) {
30
+ console.log('⚠️ Ветка уже запушена или произошла ошибка')
31
+ }
32
+
33
+ // 4. Определяем главную ветку (main или master)
26
34
  let mainBranch = 'main'
27
35
  try {
28
- execSync('git rev-parse --verify main', { stdio: 'ignore' })
36
+ execSync('git rev-parse --verify origin/main', { stdio: 'ignore' })
29
37
  } catch {
30
38
  mainBranch = 'master'
31
39
  }
32
40
 
33
- // 4. Мерджим в main/master
34
- console.log(`🔀 Переключаемся на ${mainBranch} и мерджим...`)
35
- execSync(`git checkout ${mainBranch}`, { stdio: 'inherit' })
36
- execSync(`git merge ${currentBranch} --no-ff -m "Release ${currentBranch}"`, { stdio: 'inherit' })
41
+ // 5. Получаем последний тег (версию релиза)
42
+ let version = 'Release'
43
+ try {
44
+ version = execSync('git describe --tags --abbrev=0').toString().trim()
45
+ } catch {
46
+ console.log('⚠️ Тег не найден, используется дефолтное название')
47
+ }
48
+
49
+ // 6. Создаём Pull Request через GitHub CLI
50
+ console.log('\n🔀 Создаю Pull Request...')
51
+
52
+ const prTitle = `Release ${version}`
53
+ const prBody = `Релиз версии ${version}\n\nСм. CHANGELOG.md для деталей.`
54
+
55
+ execSync(`gh pr create --base ${mainBranch} --head ${currentBranch} --title "${prTitle}" --body "${prBody}"`, {
56
+ stdio: 'inherit',
57
+ })
58
+
59
+ console.log(`\n✅ Pull Request создан!`)
37
60
 
38
- // 5. Пушим всё
39
- console.log('📤 Пушим изменения...')
40
- execSync(`git push origin ${mainBranch}`, { stdio: 'inherit' })
41
- execSync('git push --tags', { stdio: 'inherit' })
61
+ // 7. Автоматический merge БЕЗ удаления ветки
62
+ console.log('\n🔀 Мерджу PR...')
63
+ execSync('gh pr merge --merge', { stdio: 'inherit' })
42
64
 
43
- console.log(`✅ Релиз из ветки ${currentBranch} завершён!`)
44
- console.log(`💡 Теперь можешь удалить ветку: git branch -d ${currentBranch}`)
65
+ console.log(`\n✅ Релиз ${version} завершён!`)
66
+ console.log(`💡 Ветка ${currentBranch} сохранена в истории`)
45
67
  } catch (error) {
46
- console.error('❌ Ошибка при мердже:', error.message)
68
+ console.error('❌ Ошибка при создании/мердже PR:', error.message)
69
+ console.log('\n💡 Убедись что:')
70
+ console.log(' 1. Установлен GitHub CLI: gh --version')
71
+ console.log(' 2. Выполнена авторизация: gh auth login')
47
72
  process.exit(1)
48
73
  }
@@ -4,11 +4,10 @@ import { execSync } from 'child_process'
4
4
  console.log('🏷️ Настройка GitHub labels...\n')
5
5
 
6
6
  const labels = [
7
- { name: 'task', color: '0E8A16', description: 'Задача для реализации' },
8
- { name: 'bug', color: 'D73A4A', description: 'Баг который нужно исправить' },
9
- { name: 'enhancement', color: 'A2EEEF', description: 'Улучшение функционала' },
10
- { name: 'documentation', color: '0075CA', description: 'Документация' },
11
- { name: 'question', color: 'D876E3', description: 'Вопрос' },
7
+ { name: 'task', color: '0E8A16', description: 'Новая фича' },
8
+ { name: 'bug', color: 'D73A4A', description: 'Баг' },
9
+ { name: 'refactor', color: 'FEF2C0', description: 'Рефакторинг/техдолг' },
10
+ { name: 'perf', color: '007bff', description: 'Оптимизация производительности' },
12
11
  ]
13
12
 
14
13
  try {