-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sw-yx
committed
Aug 6, 2019
1 parent
9f9464b
commit 9bd22e6
Showing
4 changed files
with
238 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const globby = require("globby"); | ||
const cp = require("child_process"); | ||
var conf = require("./config"); | ||
|
||
function installDeps(functionDir, cb) { | ||
cp.exec("npm i", { cwd: functionDir }, cb); | ||
} | ||
|
||
exports.run = async function(dir) { | ||
let directory; | ||
if (dir) { | ||
var dirPath = path.join(process.cwd(), dir); | ||
directory = dirPath; | ||
} else { | ||
var config = conf.load(); | ||
const functionsDir = config.build.functions || config.build.Functions; | ||
if (!functionsDir) { | ||
console.log("Error: no functions dir detected."); | ||
} | ||
const functionsPath = path.join(process.cwd(), functionsDir); | ||
directory = functionsPath; | ||
} | ||
|
||
const findJSFiles = ["*/package.json", "!node_modules", "!**/node_modules"]; | ||
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(directory, folder), () => { | ||
console.log(`${folder} dependencies installed`); | ||
}); | ||
}); | ||
}; |
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
Oops, something went wrong.