remove.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module.exports = exports = remove
  2. exports.usage = 'Removes the node development files for the specified version'
  3. /**
  4. * Module dependencies.
  5. */
  6. var fs = require('fs')
  7. , rm = require('rimraf')
  8. , path = require('path')
  9. , log = require('npmlog')
  10. , semver = require('semver')
  11. function remove (gyp, argv, callback) {
  12. var devDir = gyp.devDir
  13. log.verbose('remove', 'using node-gyp dir:', devDir)
  14. // get the user-specified version to remove
  15. var version = argv[0] || gyp.opts.target
  16. log.verbose('remove', 'removing target version:', version)
  17. if (!version) {
  18. return callback(new Error('You must specify a version number to remove. Ex: "' + process.version + '"'))
  19. }
  20. var versionSemver = semver.parse(version)
  21. if (versionSemver) {
  22. // flatten the version Array into a String
  23. version = versionSemver.version
  24. }
  25. var versionPath = path.resolve(gyp.devDir, version)
  26. log.verbose('remove', 'removing development files for version:', version)
  27. // first check if its even installed
  28. fs.stat(versionPath, function (err, stat) {
  29. if (err) {
  30. if (err.code == 'ENOENT') {
  31. callback(null, 'version was already uninstalled: ' + version)
  32. } else {
  33. callback(err)
  34. }
  35. return
  36. }
  37. // Go ahead and delete the dir
  38. rm(versionPath, callback)
  39. })
  40. }