Skip to content

Commit 5c07229

Browse files
committed
refactor: add EXIT code const
1 parent 9191492 commit 5c07229

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

scripts/constants.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const EXIT_CODES = {
2+
SUCCESS: 0,
3+
ERROR: 1,
4+
HELP: 2,
5+
}
6+
7+
module.exports = {
8+
EXIT_CODES,
9+
}

scripts/dev-with-secrets.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@
22

33
const { spawn } = require('child_process')
44
const path = require('path')
5-
6-
// Get namespace from command line arguments
7-
const namespace = process.argv[2]
8-
9-
if (!namespace) {
10-
console.error('Please provide a namespace as an argument.')
11-
console.error('Usage: yarn dev:secrets <namespace>')
12-
process.exit(1)
13-
}
14-
15-
console.log(`🔄 Updating secrets for namespace: ${namespace}`)
5+
const { EXIT_CODES } = require('./constants')
166

177
// Run update-secret.js first
18-
const updateSecrets = spawn('node', [path.join(__dirname, 'update-secret.js'), namespace], {
8+
const updateSecrets = spawn('node', [path.join(__dirname, 'update-secret.js'), ...process.argv.slice(2)], {
199
stdio: 'inherit',
2010
})
2111

2212
updateSecrets.on('close', (code) => {
23-
if (code !== 0) {
13+
if (code === EXIT_CODES.HELP) {
14+
process.exit(0)
15+
} else if (code !== EXIT_CODES.SUCCESS) {
2416
console.error('❌ Failed to update secrets')
2517
process.exit(code)
2618
}

scripts/update-secret.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs')
2+
const { EXIT_CODES } = require('./constants')
23

34
// Configuration constants
45
const ENV_FILE_PATH = '.env.secrets'
@@ -264,13 +265,13 @@ const main = async () => {
264265
logger.error('Please provide a namespace as an argument.')
265266
logger.info('Usage: node update-secret.js <namespace>')
266267
logger.info('For help: node update-secret.js --help')
267-
process.exit(1)
268+
process.exit(EXIT_CODES.HELP)
268269
}
269270

270271
// Check if help is requested at the beginning of the script
271272
if (process.argv.includes('--help')) {
272273
showHelp()
273-
process.exit(0)
274+
process.exit(EXIT_CODES.HELP)
274275
}
275276

276277
const userInputNamespace = process.argv[2]
@@ -282,7 +283,7 @@ const main = async () => {
282283
if (!token) {
283284
logger.error('DEV_STAGING_TOKEN not found in .env.secrets file')
284285
logger.info('Make sure to add DEV_STAGING_TOKEN=your_token to .env.secrets')
285-
process.exit(1)
286+
process.exit(EXIT_CODES.ERROR)
286287
}
287288

288289
try {
@@ -296,15 +297,15 @@ const main = async () => {
296297
logger.success('All secrets updated successfully! 🎉')
297298
} catch (error) {
298299
logger.error(`Failed to update secrets: ${error.message}`)
299-
process.exit(1)
300+
process.exit(EXIT_CODES.ERROR)
300301
}
301302
}
302303

303304
// Execute the script
304305
if (require.main === module) {
305306
main().catch((error) => {
306307
logger.error(`Unhandled error: ${error.message}`)
307-
process.exit(1)
308+
process.exit(EXIT_CODES.ERROR)
308309
})
309310
}
310311

0 commit comments

Comments
 (0)