Skip to content

Commit 32385f6

Browse files
author
amazon-meaisiah
committed
Add a script to run npm commands across all modules.
1 parent 5d122c1 commit 32385f6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

scripts/npm.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
const path = require('path')
4+
const { spawn } = require('child_process')
5+
const { inspect } = require('util')
6+
7+
const folders = [
8+
'/',
9+
'/dev-portal',
10+
'/lambdas/backend',
11+
'/lambdas/catalog-updater',
12+
'/lambdas/listener',
13+
'/lambdas/static-asset-uploader'
14+
]
15+
16+
async function execute (args) {
17+
for (const folder of folders) {
18+
const resolved = path.join(__dirname, '..', folder.slice(1))
19+
console.error(`\x1b[32mExecuting in folder:\x1b[0m \x1b[34m${folder}\x1b[0m`)
20+
const { error, status, signal } = await new Promise((resolve, reject) => {
21+
spawn('npm', args, { cwd: resolved, stdio: 'inherit' })
22+
.on('exit', (status, signal) => resolve({ status, signal }))
23+
.on('error', error => resolve({ error }))
24+
})
25+
26+
if (error != null) {
27+
console.error(`\x1b[31mExecution errored in folder: ${folder}`)
28+
console.error(`${inspect(error, { colors: true })}\x1b[0m`)
29+
} else {
30+
console.error(`\x1b[32mExecution completed in folder:\x1b[0m \x1b[34m${folder}\x1b[0m`)
31+
if (status != null) console.error(`Status: ${status}`)
32+
if (signal != null) console.error(`Signal: ${signal}`)
33+
}
34+
}
35+
}
36+
37+
module.exports = execute
38+
if (require.main === module) execute(process.argv.slice(2))

0 commit comments

Comments
 (0)