Skip to content

Commit

Permalink
Support multiple packages in envDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Jul 6, 2018
1 parent dfcf7aa commit 62cdb3d
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ const path = require('path')

const deps = packageJson.envDependencies || {}

Object.keys(deps).map(key => deps[key]).map(insertEnvironmentVariables).forEach(pkg => {
try {
childProcess.execSync('npm install --no-save ' + pkg, { stdio:[0, 1, 2] })
} catch (e) { }
})
const packages = Object.keys(deps).map(key =>
deps[key].replace(/\${([0-9a-zA-Z_]*)}/g, (_, x) => process.env[x])
).join(' ')

function insertEnvironmentVariables(pkg) {
Object.keys(process.env).forEach(key => {
pkg = pkg.replace('${' + key + '}', process.env[key].trim())
})

return pkg
}
try {
childProcess.execSync('npm install --no-save ' + packages, { stdio:[0, 1, 2] })
} catch (e) { }

0 comments on commit 62cdb3d

Please sign in to comment.