Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var ncp = require('ncp').ncp
- var path = require('path')
- var npm = require('npm')
- var readInstalled = require('read-installed')
- var argv = require('optimist')
- .usage('Usage: [packageName(s)] [destinationFolder]')
- .wrap(80)
- .argv
- var args = argv._
- if (args.length < 1) throw 'Missing arguments.'
- var dest = args[0]
- npm.load(function(err) {
- if (err) return console.error(err)
- npm.commands.install(args, function errBack(err, data) {
- if (err) return console.error(err)
- console.log(data)
- var installed = data.map(function(d) { return d.pop() })
- if (installed.length > 0) installPlugins(installed)
- else console.log("No new plugins installed")
- })
- })
- function installPlugins(packageNames) {
- readInstalled(path.resolve(__dirname, '..'), function (er, data) {
- Object.keys(data.dependencies).forEach(function eachDep(depName) {
- var dep = data.dependencies[depName]
- if (!dep.cordova) return
- copyPluginFiles(dep.path, dest)
- })
- })
- }
- function copyPluginFiles(source, dest, cb) {
- ncp(path.resolve(source, 'plugin'), dest, function errBack(err) {
- if (err && cb) return cb(err)
- if (cb) return cb(false)
- })
- }
Add Comment
Please, Sign In to add comment