Skip to content

Commit b8f5f0b

Browse files
committed
refactor: use logger helper methods in verify-package scripts
- Replace manual color formatting with logger.info(), logger.success(), logger.fail() - Remove duplicate helper functions (success, error, info) across CLI and socket packages - Consistent with cli-with-sentry changes from previous commit Reduces code duplication and makes output formatting consistent across all verify-package scripts. The logger methods automatically handle symbol prefixing and coloring.
1 parent 9fac3cd commit b8f5f0b

File tree

2 files changed

+21
-63
lines changed

2 files changed

+21
-63
lines changed

packages/cli/scripts/verify-package.mjs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,6 @@ const __filename = fileURLToPath(import.meta.url)
1111
const __dirname = path.dirname(__filename)
1212
const packageRoot = path.resolve(__dirname, '..')
1313

14-
/**
15-
* Format a success message.
16-
*/
17-
function success(msg) {
18-
return `${colors.green('✓')} ${msg}`
19-
}
20-
21-
/**
22-
* Format an error message.
23-
*/
24-
function error(msg) {
25-
return `${colors.red('✗')} ${msg}`
26-
}
27-
28-
/**
29-
* Format an info message.
30-
*/
31-
function info(msg) {
32-
return `${colors.blue('ℹ')} ${msg}`
33-
}
34-
3514
/**
3615
* Check if a file exists and is readable.
3716
*/
@@ -57,12 +36,12 @@ async function validate() {
5736
const errors = []
5837

5938
// Check package.json exists and has correct files array.
60-
logger.log(info('Checking package.json...'))
39+
logger.info('Checking package.json...')
6140
const pkgPath = path.join(packageRoot, 'package.json')
6241
if (!(await fileExists(pkgPath))) {
6342
errors.push('package.json does not exist')
6443
} else {
65-
logger.log(success('package.json exists'))
44+
logger.success('package.json exists')
6645

6746
// Validate files array.
6847
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
@@ -80,54 +59,54 @@ async function validate() {
8059
}
8160
}
8261
if (errors.length === 0) {
83-
logger.log(success('package.json files array is correct'))
62+
logger.success('package.json files array is correct')
8463
}
8564
}
8665

8766
// Check root files exist (LICENSE, CHANGELOG.md).
8867
const rootFiles = ['LICENSE', 'CHANGELOG.md']
8968
for (const file of rootFiles) {
90-
logger.log(info(`Checking ${file}...`))
69+
logger.info(`Checking ${file}...`)
9170
const filePath = path.join(packageRoot, file)
9271
if (!(await fileExists(filePath))) {
9372
errors.push(`${file} does not exist`)
9473
} else {
95-
logger.log(success(`${file} exists`))
74+
logger.success(`${file} exists`)
9675
}
9776
}
9877

9978
// Check dist files exist.
10079
const distFiles = ['index.js', 'cli.js.bz', 'shadow-npm-inject.js']
10180
for (const file of distFiles) {
102-
logger.log(info(`Checking dist/${file}...`))
81+
logger.info(`Checking dist/${file}...`)
10382
const filePath = path.join(packageRoot, 'dist', file)
10483
if (!(await fileExists(filePath))) {
10584
errors.push(`dist/${file} does not exist`)
10685
} else {
107-
logger.log(success(`dist/${file} exists`))
86+
logger.success(`dist/${file} exists`)
10887
}
10988
}
11089

11190
// Check data directory exists.
112-
logger.log(info('Checking data directory...'))
91+
logger.info('Checking data directory...')
11392
const dataPath = path.join(packageRoot, 'data')
11493
if (!(await fileExists(dataPath))) {
11594
errors.push('data directory does not exist')
11695
} else {
117-
logger.log(success('data directory exists'))
96+
logger.success('data directory exists')
11897

11998
// Check data files.
12099
const dataFiles = [
121100
'alert-translations.json',
122101
'command-api-requirements.json',
123102
]
124103
for (const file of dataFiles) {
125-
logger.log(info(`Checking data/${file}...`))
104+
logger.info(`Checking data/${file}...`)
126105
const filePath = path.join(dataPath, file)
127106
if (!(await fileExists(filePath))) {
128107
errors.push(`data/${file} does not exist`)
129108
} else {
130-
logger.log(success(`data/${file} exists`))
109+
logger.success(`data/${file} exists`)
131110
}
132111
}
133112
}
@@ -145,20 +124,20 @@ async function validate() {
145124
logger.log(` ${error(err)}`)
146125
}
147126
logger.log('')
148-
logger.log(error('Package validation FAILED'))
127+
logger.fail('Package validation FAILED')
149128
logger.log('')
150129
process.exit(1)
151130
}
152131

153-
logger.log(success('Package validation PASSED'))
132+
logger.success('Package validation PASSED')
154133
logger.log('')
155134
process.exit(0)
156135
}
157136

158137
// Run validation.
159138
validate().catch(e => {
160139
logger.error('')
161-
logger.error(error(`Unexpected error: ${e.message}`))
140+
logger.fail(`Unexpected error: ${e.message}`)
162141
logger.error('')
163142
process.exit(1)
164143
})

packages/socket/scripts/verify-package.mjs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@ const __filename = fileURLToPath(import.meta.url)
1010
const __dirname = path.dirname(__filename)
1111
const packageRoot = path.resolve(__dirname, '..')
1212

13-
/**
14-
* Format a success message.
15-
*/
16-
function success(msg) {
17-
return `${colors.green('✓')} ${msg}`
18-
}
19-
20-
/**
21-
* Format an error message.
22-
*/
23-
function error(msg) {
24-
return `${colors.red('✗')} ${msg}`
25-
}
26-
27-
/**
28-
* Format an info message.
29-
*/
30-
function info(msg) {
31-
return `${colors.blue('ℹ')} ${msg}`
32-
}
33-
3413
/**
3514
* Check if a file exists and is readable.
3615
*/
@@ -56,21 +35,21 @@ async function validate() {
5635
const errors = []
5736

5837
// Check package.json exists.
59-
logger.log(info('Checking package.json...'))
38+
logger.info('Checking package.json...')
6039
const pkgPath = path.join(packageRoot, 'package.json')
6140
if (!(await fileExists(pkgPath))) {
6241
errors.push('package.json does not exist')
6342
} else {
64-
logger.log(success('package.json exists'))
43+
logger.success('package.json exists')
6544
}
6645

6746
// Check dist/bootstrap.js exists.
68-
logger.log(info('Checking dist/bootstrap.js...'))
47+
logger.info('Checking dist/bootstrap.js...')
6948
const bootstrapPath = path.join(packageRoot, 'dist', 'bootstrap.js')
7049
if (!(await fileExists(bootstrapPath))) {
7150
errors.push('dist/bootstrap.js does not exist')
7251
} else {
73-
logger.log(success('dist/bootstrap.js exists'))
52+
logger.success('dist/bootstrap.js exists')
7453
}
7554

7655
// Print summary.
@@ -86,20 +65,20 @@ async function validate() {
8665
logger.log(` ${error(err)}`)
8766
}
8867
logger.log('')
89-
logger.log(error('Package validation FAILED'))
68+
logger.fail('Package validation FAILED')
9069
logger.log('')
9170
process.exit(1)
9271
}
9372

94-
logger.log(success('Package validation PASSED'))
73+
logger.success('Package validation PASSED')
9574
logger.log('')
9675
process.exit(0)
9776
}
9877

9978
// Run validation.
10079
validate().catch(e => {
10180
logger.error('')
102-
logger.error(error(`Unexpected error: ${e.message}`))
81+
logger.fail(`Unexpected error: ${e.message}`)
10382
logger.error('')
10483
process.exit(1)
10584
})

0 commit comments

Comments
 (0)