-
-
Save Uvacoder/d2fbc141ec359a9e059090392ad9456b to your computer and use it in GitHub Desktop.
Install dependancies in every folder with package.json file
This file contains hidden or 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