Skip to content

Commit 6064462

Browse files
committed
refactor: use common logger in bump, publish, and update scripts
Replace inline logger implementations with imports from utils/common.mjs
1 parent 5f5e447 commit 6064462

File tree

3 files changed

+7
-104
lines changed

3 files changed

+7
-104
lines changed

scripts/bump.mjs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { spawn } from 'node:child_process'
88
import { existsSync, promises as fs } from 'node:fs'
99
import path from 'node:path'
1010
import readline from 'node:readline'
11-
import { fileURLToPath } from 'node:url'
1211
import { parseArgs } from 'node:util'
1312

1413
import semver from 'semver'
1514
import colors from 'yoctocolors-cjs'
1615

17-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
18-
const rootPath = path.join(__dirname, '..')
16+
import { getRootPath, log, printFooter, printHeader } from './utils/common.mjs'
17+
18+
const rootPath = getRootPath(import.meta.url)
1919
const WIN32 = process.platform === 'win32'
2020

2121
// Check if prompts are available for interactive mode
@@ -42,38 +42,6 @@ if (hasInteractivePrompts) {
4242
}
4343
}
4444

45-
// Simple inline logger
46-
const log = {
47-
info: msg => console.log(msg),
48-
error: msg => console.error(`${colors.red('✗')} ${msg}`),
49-
success: msg => console.log(`${colors.green('✓')} ${msg}`),
50-
step: msg => console.log(`\n${msg}`),
51-
substep: msg => console.log(` ${msg}`),
52-
progress: msg => process.stdout.write(` ∴ ${msg}`),
53-
done: msg => {
54-
process.stdout.write('\r\x1b[K')
55-
console.log(` ${colors.green('✓')} ${msg}`)
56-
},
57-
failed: msg => {
58-
process.stdout.write('\r\x1b[K')
59-
console.log(` ${colors.red('✗')} ${msg}`)
60-
},
61-
warn: msg => console.log(`${colors.yellow('⚠')} ${msg}`)
62-
}
63-
64-
function printHeader(title) {
65-
console.log(`\n${'─'.repeat(60)}`)
66-
console.log(` ${title}`)
67-
console.log(`${'─'.repeat(60)}`)
68-
}
69-
70-
function printFooter(message) {
71-
console.log(`\n${'─'.repeat(60)}`)
72-
if (message) {
73-
console.log(` ${colors.green('✓')} ${message}`)
74-
}
75-
}
76-
7745
/**
7846
* Create readline interface for user input.
7947
*/

scripts/publish.mjs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,14 @@
66
import { spawn } from 'node:child_process'
77
import { existsSync, promises as fs } from 'node:fs'
88
import path from 'node:path'
9-
import { fileURLToPath } from 'node:url'
109
import { parseArgs } from 'node:util'
1110

12-
import colors from 'yoctocolors-cjs'
11+
import { getRootPath, log, printFooter, printHeader } from './utils/common.mjs'
1312

14-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15-
const rootPath = path.join(__dirname, '..')
13+
const rootPath = getRootPath(import.meta.url)
1614
const WIN32 = process.platform === 'win32'
1715
const CI = !!process.env.CI
1816

19-
// Simple inline logger
20-
const log = {
21-
info: msg => console.log(msg),
22-
error: msg => console.error(`${colors.red('✗')} ${msg}`),
23-
success: msg => console.log(`${colors.green('✓')} ${msg}`),
24-
step: msg => console.log(`\n${msg}`),
25-
substep: msg => console.log(` ${msg}`),
26-
progress: msg => process.stdout.write(` ∴ ${msg}`),
27-
done: msg => {
28-
process.stdout.write('\r\x1b[K')
29-
console.log(` ${colors.green('✓')} ${msg}`)
30-
},
31-
failed: msg => {
32-
process.stdout.write('\r\x1b[K')
33-
console.log(` ${colors.red('✗')} ${msg}`)
34-
},
35-
warn: msg => console.log(`${colors.yellow('⚠')} ${msg}`)
36-
}
37-
38-
function printHeader(title) {
39-
console.log(`\n${'─'.repeat(60)}`)
40-
console.log(` ${title}`)
41-
console.log(`${'─'.repeat(60)}`)
42-
}
43-
44-
function printFooter(message) {
45-
console.log(`\n${'─'.repeat(60)}`)
46-
if (message) {
47-
console.log(` ${colors.green('✓')} ${message}`)
48-
}
49-
}
50-
5117
async function runCommand(command, args = [], options = {}) {
5218
return new Promise((resolve, reject) => {
5319
const child = spawn(command, args, {

scripts/update.mjs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,13 @@
66
import { spawn } from 'node:child_process'
77
import { existsSync } from 'node:fs'
88
import path from 'node:path'
9-
import { fileURLToPath } from 'node:url'
109
import { parseArgs } from 'node:util'
1110

12-
import colors from 'yoctocolors-cjs'
11+
import { getRootPath, log, printFooter, printHeader } from './utils/common.mjs'
1312

14-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15-
const rootPath = path.join(__dirname, '..')
13+
const rootPath = getRootPath(import.meta.url)
1614
const WIN32 = process.platform === 'win32'
1715

18-
// Simple inline logger
19-
const log = {
20-
info: msg => console.log(msg),
21-
error: msg => console.error(`${colors.red('✗')} ${msg}`),
22-
success: msg => console.log(`${colors.green('✓')} ${msg}`),
23-
step: msg => console.log(`\n${msg}`),
24-
substep: msg => console.log(` ${msg}`),
25-
progress: msg => process.stdout.write(` ∴ ${msg}`),
26-
done: msg => {
27-
process.stdout.write('\r\x1b[K')
28-
console.log(` ${colors.green('✓')} ${msg}`)
29-
},
30-
failed: msg => {
31-
process.stdout.write('\r\x1b[K')
32-
console.log(` ${colors.red('✗')} ${msg}`)
33-
}
34-
}
35-
36-
function printHeader(title) {
37-
console.log(`\n${'─'.repeat(60)}`)
38-
console.log(` ${title}`)
39-
console.log(`${'─'.repeat(60)}`)
40-
}
41-
42-
function printFooter(message) {
43-
console.log(`\n${'─'.repeat(60)}`)
44-
if (message) {console.log(` ${colors.green('✓')} ${message}`)}
45-
}
46-
4716
function includesProvenanceDowngradeWarning(output) {
4817
const lowered = output.toString().toLowerCase()
4918
return (

0 commit comments

Comments
 (0)