Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created July 1, 2020 05:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DavidWells/f1b92668fe9ed09021457dc8ef0fd440 to your computer and use it in GitHub Desktop.
Save DavidWells/f1b92668fe9ed09021457dc8ef0fd440 to your computer and use it in GitHub Desktop.
Install dependancies in every folder with package.json file
const path = require('path')
const fs = require('fs')
const globby = require('globby')
const cp = require("child_process")
function installDeps(functionDir, cb) {
cp.exec("npm i", { cwd: functionDir }, cb)
}
async function installAllDeps(additionalDirs = []) {
const findJSFiles = ['*/package.json', '!node_modules', '!**/node_modules'].concat(additionalDirs)
const directory = path.join(__dirname, '..', 'functions')
const foldersWithDeps = await globby(findJSFiles, { cwd: directory })
const folders = foldersWithDeps.map(fnFolder => {
return fnFolder.substring(0, fnFolder.indexOf("package.json"))
}).map((folder) => {
installDeps(path.join(__dirname, '..', 'functions', folder), () => {
console.log(`${folder} dependencies installed`)
})
})
}
installAllDeps()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment