Guest User

Untitled

a guest
Dec 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/usr/bin/env node
  2.  
  3. var ncp = require('ncp').ncp
  4. var path = require('path')
  5. var npm = require('npm')
  6. var readInstalled = require('read-installed')
  7. var argv = require('optimist')
  8. .usage('Usage: [packageName(s)] [destinationFolder]')
  9. .wrap(80)
  10. .argv
  11. var args = argv._
  12. if (args.length < 1) throw 'Missing arguments.'
  13. var dest = args[0]
  14.  
  15. npm.load(function(err) {
  16. if (err) return console.error(err)
  17. npm.commands.install(args, function errBack(err, data) {
  18. if (err) return console.error(err)
  19. console.log(data)
  20. var installed = data.map(function(d) { return d.pop() })
  21. if (installed.length > 0) installPlugins(installed)
  22. else console.log("No new plugins installed")
  23. })
  24. })
  25.  
  26. function installPlugins(packageNames) {
  27. readInstalled(path.resolve(__dirname, '..'), function (er, data) {
  28. Object.keys(data.dependencies).forEach(function eachDep(depName) {
  29. var dep = data.dependencies[depName]
  30. if (!dep.cordova) return
  31. copyPluginFiles(dep.path, dest)
  32. })
  33. })
  34. }
  35.  
  36. function copyPluginFiles(source, dest, cb) {
  37. ncp(path.resolve(source, 'plugin'), dest, function errBack(err) {
  38. if (err && cb) return cb(err)
  39. if (cb) return cb(false)
  40. })
  41. }
Add Comment
Please, Sign In to add comment