itty-packager 1.1.0 → 1.2.0
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/lib/commands/publish.js +76 -1
- package/package.json +1 -1
package/lib/commands/publish.js
CHANGED
|
@@ -2,6 +2,7 @@ import { parseArgs } from 'node:util'
|
|
|
2
2
|
import { spawn } from 'node:child_process'
|
|
3
3
|
import fs from 'fs-extra'
|
|
4
4
|
import path from 'node:path'
|
|
5
|
+
import readline from 'node:readline'
|
|
5
6
|
import { prepareCommand } from './prepare.js'
|
|
6
7
|
|
|
7
8
|
const SEMVER_TYPES = ['major', 'minor', 'patch']
|
|
@@ -73,6 +74,71 @@ function versionBump(currentVersion, type) {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
async function getCommitMessage(newVersion, silent = false) {
|
|
78
|
+
if (silent) {
|
|
79
|
+
return `released v${newVersion}`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
|
+
const rl = readline.createInterface({
|
|
84
|
+
input: process.stdin,
|
|
85
|
+
output: process.stdout
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
console.log('\nEnter optional commit message (empty submission skips):')
|
|
89
|
+
console.log('\x1b[90mPress Enter to finish, Ctrl+C to skip\x1b[0m')
|
|
90
|
+
process.stdout.write('\n')
|
|
91
|
+
|
|
92
|
+
let inputLines = []
|
|
93
|
+
let firstInput = true
|
|
94
|
+
|
|
95
|
+
rl.on('line', (input) => {
|
|
96
|
+
if (firstInput && input.trim() === '') {
|
|
97
|
+
// First line is empty, skip custom message
|
|
98
|
+
rl.close()
|
|
99
|
+
resolve(`released v${newVersion}`)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
firstInput = false
|
|
104
|
+
|
|
105
|
+
if (input.trim() === '' && inputLines.length > 0) {
|
|
106
|
+
// Empty line after content - finish input
|
|
107
|
+
finishInput()
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
inputLines.push(input)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const finishInput = () => {
|
|
115
|
+
rl.close()
|
|
116
|
+
const customMessage = inputLines.join('\n').trim()
|
|
117
|
+
|
|
118
|
+
if (!customMessage) {
|
|
119
|
+
resolve(`released v${newVersion}`)
|
|
120
|
+
} else {
|
|
121
|
+
// Escape quotes in the custom message
|
|
122
|
+
const escapedMessage = customMessage.replace(/"/g, '\\"')
|
|
123
|
+
resolve(`released v${newVersion} - ${escapedMessage}`)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
rl.on('SIGINT', () => {
|
|
128
|
+
console.log('\nSkipped. Using default commit message.')
|
|
129
|
+
rl.close()
|
|
130
|
+
resolve(`released v${newVersion}`)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Handle Ctrl+D (EOF) as completion
|
|
134
|
+
rl.on('close', () => {
|
|
135
|
+
if (!firstInput && inputLines.length > 0) {
|
|
136
|
+
finishInput()
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
76
142
|
async function runCommand(command, cwd = process.cwd(), verbose = false) {
|
|
77
143
|
return new Promise((resolve, reject) => {
|
|
78
144
|
const [cmd, ...args] = command.split(' ')
|
|
@@ -174,6 +240,10 @@ export async function publishCommand(args) {
|
|
|
174
240
|
type: 'boolean',
|
|
175
241
|
description: 'Run prepare (lint, test, build) before publishing'
|
|
176
242
|
},
|
|
243
|
+
silent: {
|
|
244
|
+
type: 'boolean',
|
|
245
|
+
description: 'Skip interactive prompts (use default commit message)'
|
|
246
|
+
},
|
|
177
247
|
verbose: {
|
|
178
248
|
type: 'boolean',
|
|
179
249
|
short: 'v',
|
|
@@ -207,6 +277,7 @@ Publish Options:
|
|
|
207
277
|
--no-cleanup Leave temporary directory after publishing
|
|
208
278
|
--public Publish as public package (--access=public)
|
|
209
279
|
--prepare Run prepare (lint, test, build) before publishing
|
|
280
|
+
--silent Skip interactive prompts (use default commit message)
|
|
210
281
|
--no-license Do not copy LICENSE file to published package
|
|
211
282
|
-v, --verbose Show detailed output including npm and git command details
|
|
212
283
|
|
|
@@ -253,6 +324,7 @@ This creates a clean, flat package structure in node_modules.
|
|
|
253
324
|
const noGit = publishArgs['no-git']
|
|
254
325
|
const noLicense = publishArgs['no-license']
|
|
255
326
|
const shouldPrepare = publishArgs.prepare
|
|
327
|
+
const silent = publishArgs.silent
|
|
256
328
|
const verbose = publishArgs.verbose
|
|
257
329
|
|
|
258
330
|
try {
|
|
@@ -355,9 +427,12 @@ This creates a clean, flat package structure in node_modules.
|
|
|
355
427
|
// Git operations
|
|
356
428
|
if (!noGit && !dryRun) {
|
|
357
429
|
if (shouldPush || shouldTag) {
|
|
430
|
+
// Get commit message (interactive or default)
|
|
431
|
+
const commitMessage = await getCommitMessage(newVersion, silent)
|
|
432
|
+
|
|
358
433
|
if (verbose) console.log(`📋 Committing changes...`)
|
|
359
434
|
await runCommand('git add .', rootPath, verbose)
|
|
360
|
-
await runCommand(`git commit -m "
|
|
435
|
+
await runCommand(`git commit -m "${commitMessage}"`, rootPath, verbose)
|
|
361
436
|
}
|
|
362
437
|
|
|
363
438
|
if (shouldTag) {
|