Created
June 18, 2015 13:52
-
-
Save tjoskar/b4c27de29ae8a998ff17 to your computer and use it in GitHub Desktop.
run "npm install" in all folders under a certain folder
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
var fs = require('fs'); | |
var path = require('path'); | |
var childProcess = require('child_process'); | |
var dir = './components'; | |
var nodeComand = 'npm install'; | |
var packageFile = 'package.json'; | |
var nodeVersion = process.versions.node.split('.'); | |
if (!(nodeVersion[0] >= 0 && nodeVersion[1] >= 12 && nodeVersion[2] >= 4)) { | |
console.error('This setup require node v0.12.4 or higher, you have: v' + nodeVersion.join('.')); | |
process.exit(1); | |
} | |
var components = fs.readdirSync(dir); | |
components.forEach(function(component) { | |
var componentPath = path.join(dir, component); | |
var stats = fs.statSync(componentPath); | |
if (stats && stats.isDirectory()) { | |
var files = fs.readdirSync(componentPath); | |
if (files.indexOf(packageFile) > -1) { | |
console.log('Installing ' + component); | |
var oldPath = process.cwd(); | |
process.chdir(componentPath); | |
childProcess.execSync(nodeComand); | |
process.chdir(oldPath); | |
console.log(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment