Skip to content

Commit c414d63

Browse files
committed
Add dynamic header replacement to fix scripts
Replace task headers with green success messages when tasks complete. Use replaceHeader to update "Package Exports" with "✓ Package exports generated", "Default References" with "✓ Default references fixed", and "Biome Auto-fix" with "✓ Biome auto-fix complete". Accounts for Biome's output line when replacing its header.
1 parent 29dbea3 commit c414d63

2 files changed

Lines changed: 61 additions & 17 deletions

File tree

scripts/fix-default-imports.mjs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import { promises as fs } from 'node:fs'
66
import path from 'node:path'
77
import { fileURLToPath } from 'node:url'
88

9-
import {
10-
printError,
11-
printFooter,
12-
printHeader,
13-
printSuccess,
14-
} from './utils/cli-helpers.mjs'
9+
import colors from 'yoctocolors-cjs'
10+
11+
import { printError, printHeader, replaceHeader } from './utils/cli-helpers.mjs'
1512

1613
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1714
const distDir = path.resolve(__dirname, '..', 'dist')
@@ -208,8 +205,7 @@ async function fixDefaultReferences() {
208205

209206
try {
210207
await processDirectory(distDir)
211-
printSuccess('Default references fixed')
212-
printFooter()
208+
replaceHeader(colors.green('✓ Default references fixed'))
213209
} catch (error) {
214210
printError(`Failed to fix default references: ${error.message}`)
215211
process.exitCode = 1

scripts/fix.mjs

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import { existsSync } from 'node:fs'
77
import path from 'node:path'
88
import { fileURLToPath } from 'node:url'
99

10-
import { printError, printHeader } from './utils/cli-helpers.mjs'
10+
import colors from 'yoctocolors-cjs'
11+
12+
import { printError, printHeader, replaceHeader } from './utils/cli-helpers.mjs'
1113

1214
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1315
const rootPath = path.join(__dirname, '..')
1416

1517
/**
1618
* Run a command and return a promise that resolves when it completes.
1719
*/
18-
function runCommand(command, args, label) {
20+
function _runCommand(command, args, label) {
1921
return new Promise((resolve, reject) => {
2022
printHeader(label)
2123
const child = spawn(command, args, {
@@ -45,24 +47,55 @@ async function main() {
4547
// Step 1: Generate package exports (only if dist/ exists)
4648
const distPath = path.join(rootPath, 'dist')
4749
if (existsSync(distPath)) {
48-
await runCommand(
50+
printHeader('Package Exports')
51+
const exportChild = spawn(
4952
'node',
5053
[path.join(__dirname, 'generate-package-exports.mjs')],
51-
'Package Exports',
54+
{
55+
stdio: 'pipe',
56+
cwd: rootPath,
57+
...(process.platform === 'win32' && { shell: true }),
58+
},
5259
)
60+
await new Promise((resolve, reject) => {
61+
exportChild.on('exit', code => {
62+
if (code === 0) {
63+
replaceHeader(colors.green('✓ Package exports generated'))
64+
resolve()
65+
} else {
66+
reject(new Error(`Package exports exited with code ${code}`))
67+
}
68+
})
69+
exportChild.on('error', reject)
70+
})
5371
} else {
5472
printHeader('Skipping Package Exports (dist/ not found)')
5573
}
5674

57-
// Step 2: Fix default imports
58-
await runCommand(
75+
// Step 2: Fix default imports (prints its own header and success)
76+
const child = spawn(
5977
'node',
6078
[path.join(__dirname, 'fix-default-imports.mjs')],
61-
'Default Imports',
79+
{
80+
stdio: 'inherit',
81+
cwd: rootPath,
82+
...(process.platform === 'win32' && { shell: true }),
83+
},
6284
)
85+
await new Promise((resolve, reject) => {
86+
child.on('exit', code => {
87+
if (code === 0) {
88+
resolve()
89+
} else {
90+
reject(new Error(`Fix default imports exited with code ${code}`))
91+
}
92+
})
93+
child.on('error', reject)
94+
})
6395

6496
// Step 3: Run Biome auto-fix
65-
await runCommand(
97+
printHeader('Biome Auto-fix')
98+
const biomeChild = spawn(
6699
'pnpm',
67100
[
68101
'exec',
@@ -73,8 +106,23 @@ async function main() {
73106
'.',
74107
...process.argv.slice(2),
75108
],
76-
'Biome Auto-fix',
109+
{
110+
stdio: 'inherit',
111+
cwd: rootPath,
112+
...(process.platform === 'win32' && { shell: true }),
113+
},
77114
)
115+
await new Promise((resolve, reject) => {
116+
biomeChild.on('exit', code => {
117+
if (code === 0) {
118+
replaceHeader(colors.green('✓ Biome auto-fix complete'), 1)
119+
resolve()
120+
} else {
121+
reject(new Error(`Biome auto-fix exited with code ${code}`))
122+
}
123+
})
124+
biomeChild.on('error', reject)
125+
})
78126

79127
process.exitCode = 0
80128
} catch (error) {

0 commit comments

Comments
 (0)