Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-01-09 10:57:11 +0300
committerisaacs <i@izs.me>2011-01-09 10:57:11 +0300
commit2aa9747b4795fc216b06a86450ecdd736534fe68 (patch)
tree357ab4b4da41f398df6de1703c3ac51b52344db5
parent1424fb379939625dd03ce15ca617fbb8244e5564 (diff)
Use the package.json data in the installation
So to verify the version of node in use. Note that this install.sh can't be deployed until AFTER this node is published.
-rw-r--r--bin/read-package-json.js18
-rw-r--r--bin/semver.js62
-rwxr-xr-xscripts/install.sh11
3 files changed, 83 insertions, 8 deletions
diff --git a/bin/read-package-json.js b/bin/read-package-json.js
new file mode 100644
index 000000000..84944df72
--- /dev/null
+++ b/bin/read-package-json.js
@@ -0,0 +1,18 @@
+var argv = process.argv
+if (argv.length < 3) {
+ console.error("Usage: read-package.json <file> [<fields> ...]")
+ process.exit(1)
+}
+var fs = require("fs")
+ , file = argv[2]
+ , data = JSON.parse(fs.readFileSync(file, "utf8"))
+
+if (argv.length === 3) console.log(data)
+else argv.slice(3).forEach(function (field) {
+ field = field.split(".")
+ var val = data
+ field.forEach(function (f) {
+ val = val[f]
+ })
+ console.log(val)
+})
diff --git a/bin/semver.js b/bin/semver.js
new file mode 100644
index 000000000..5261de134
--- /dev/null
+++ b/bin/semver.js
@@ -0,0 +1,62 @@
+// Standalone semver comparison program.
+// Exits successfully and prints matching version(s) if
+// any supplied version is valid and passes all tests.
+
+var argv = process.argv.slice(2)
+ , versions = []
+ , range = []
+ , gt = []
+ , lt = []
+ , eq = []
+ , semver = require("../lib/utils/semver")
+
+main()
+
+function main () {
+ if (!argv.length) return help()
+ while (argv.length) {
+ switch (argv.shift()) {
+ case "-v": case "--version":
+ versions.push(argv.shift())
+ break
+ case "-r" : case "--range":
+ range.push(argv.shift())
+ break
+ default:
+ return help()
+ }
+ }
+ versions = versions.filter(semver.valid)
+ for (var i = 0, l = range.length; i < l ; i ++) {
+ versions = versions.filter(function (v) {
+ return semver.satisfies(v, range[i])
+ })
+ if (!versions.length) return fail()
+ }
+ return success(versions)
+}
+
+function fail () { process.exit(1) }
+
+function success () {
+ versions.sort(semver.compare).forEach(function (v,i,_) { console.log(v) })
+}
+
+function help () {
+ console.log(["Usage: semver -v <version> [-r <range>]"
+ ,"Test if version(s) satisfy the supplied range(s),"
+ ,"and sort them."
+ ,""
+ ,"Multiple versions or ranges may be supplied."
+ ,""
+ ,"Program exits successfully if all versions satisfy all"
+ ,"ranges and are valid, and prints all satisfying versions."
+ ,"If no versions are valid, or ranges are not satisfied,"
+ ,"then exits failure."
+ ,""
+ ,"Versions are printed in ascending order, so supplying"
+ ,"multiple versions to the utility will just sort them."
+ ].join("\n"))
+}
+
+
diff --git a/scripts/install.sh b/scripts/install.sh
index c9deb7787..8cbd0e4c4 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -36,20 +36,15 @@ if [ $? -ne 0 ] || ! [ -x $egrep ]; then
egrep=egrep
fi
-# TODO: Add cli interfaces to lib/utils/semver.js and lib/utils/read-json.js,
-# and pull the required node version out of the package.json
-# then do something like this:
-# ./bin/semver \
-# -v `node --version 2>&1` \
-# -r `./bin/read-json package.json engines.node`
node_version=`$node --version 2>&1`
ret=$?
if [ $ret -eq 0 ]; then
- echo $node_version | $egrep -v -q '^v?0\.([01]\.|2\.[0-2][^0-9])'
+ req=`$node bin/read-package-json.js package.json engines.node`
+ $node bin/semver.js -v "$node_version" -r "$req"
ret=$?
fi
if [ $ret -ne 0 ]; then
- echo "You need node v0.2.3 or higher to run this program." >&2
+ echo "You need node $req to run this program." >&2
echo "node --version reports: $node_version" >&2
echo "Please upgrade node before continuing."
exit $ret