diff options
author | isaacs <i@izs.me> | 2010-03-01 09:29:45 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-03-01 09:29:45 +0300 |
commit | d916b98225df8bb8baae3875fea83e051ad61c76 (patch) | |
tree | 346626dcef6515763ac50b79f5c78ffd981fc7d5 | |
parent | 99f299d476f1eafeaf58992eaf27042ad2f435af (diff) |
Scripts for different parts of the installation/activation lifecycle.
-rw-r--r-- | scripts/activate.js | 17 | ||||
-rw-r--r-- | scripts/deactivate.js | 12 | ||||
-rw-r--r-- | scripts/install.js | 17 | ||||
-rw-r--r-- | scripts/uninstall.js | 12 |
4 files changed, 56 insertions, 2 deletions
diff --git a/scripts/activate.js b/scripts/activate.js new file mode 100644 index 000000000..990ded0e4 --- /dev/null +++ b/scripts/activate.js @@ -0,0 +1,17 @@ +#!/usr/local/bin/node +var fs = require("fs"), + version = process.env["npm.package.version"], + bin = "/usr/local/bin/npm", + versionedBin = "/usr/local/bin/npm-"+version; + +fs.lstat(bin, function (er, st) { + if (er) fs.unlink(bin, linkBin); + else linkBin(); +}); + +function linkBin (er) { + if (er) throw er; + fs.symlinkSync(versionedBin, bin, function (er) { + if (er) throw er; + }); +} diff --git a/scripts/deactivate.js b/scripts/deactivate.js new file mode 100644 index 000000000..e59caf740 --- /dev/null +++ b/scripts/deactivate.js @@ -0,0 +1,12 @@ +#!/usr/local/bin/node + +var fs = require("fs"), + version = process.env["npm.package.version"], + bin = "/usr/local/bin/npm"; + +fs.lstat(bin, function (er, st) { + if (er) return; + fs.unlink(bin, function (er) { + if (er) throw er; + }); +}); diff --git a/scripts/install.js b/scripts/install.js index 11034ff40..014787775 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -1,2 +1,17 @@ #!/usr/local/bin/node -require("sys").exec("cp cli.js /usr/local/bin/npm"); +var fs = require("fs"), + version = process.env["npm.package.version"], + bin = "/usr/local/bin/npm-"+version, + clijs = require("path").join(process.cwd(), "cli.js"); + +fs.lstat(bin, function (er, st) { + if (er) fs.unlink(bin, linkBin); + else linkBin(); +}); + +function linkBin (er) { + if (er) throw er; + fs.symlinkSync(clijs, bin, function (er) { + if (er) throw er; + }); +} diff --git a/scripts/uninstall.js b/scripts/uninstall.js index 948f4b175..eeb53c9ab 100644 --- a/scripts/uninstall.js +++ b/scripts/uninstall.js @@ -1,2 +1,12 @@ #!/usr/local/bin/node -require("fs").unlink("/usr/local/bin/npm/cli.js"); + +var fs = require("fs"), + version = process.env["npm.package.version"], + versionedBin = "/usr/local/bin/npm-"+version; + +fs.lstat(versionedBin, function (er, st) { + if (er) return; + fs.unlink(versionedBin, function (er) { + if (er) throw er; + }); +}); |