Created
July 1, 2020 05:54
-
-
Save DavidWells/f1b92668fe9ed09021457dc8ef0fd440 to your computer and use it in GitHub Desktop.
Install dependancies in every folder with package.json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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