UNPKG

1.1 kBJavaScriptView Raw
1const path = require('path');
2const globby = require('globby');
3const cp = require('child_process');
4var conf = require('./config');
5
6function installDeps(functionDir, cb) {
7 cp.exec('npm i', { cwd: functionDir }, cb);
8}
9
10exports.run = async function (dir) {
11 let directory;
12 if (dir) {
13 var dirPath = path.join(process.cwd(), dir);
14 directory = dirPath;
15 } else {
16 var config = conf.load();
17 const functionsDir = config.build.functions || config.build.Functions;
18 if (!functionsDir) {
19 console.log('Error: no functions dir detected.');
20 }
21 const functionsPath = path.join(process.cwd(), functionsDir);
22 directory = functionsPath;
23 }
24
25 const findJSFiles = ['**/package.json', '!node_modules', '!**/node_modules'];
26 const foldersWithDeps = await globby(findJSFiles, { cwd: directory });
27
28 foldersWithDeps
29 .map((fnFolder) => {
30 return fnFolder.substring(0, fnFolder.indexOf('package.json'));
31 })
32 .map((folder) => {
33 installDeps(path.join(directory, folder), () => {
34 console.log(`${folder} dependencies installed`);
35 });
36 });
37};