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:
Diffstat (limited to 'bin/read-package-json.js')
-rw-r--r--bin/read-package-json.js18
1 files changed, 18 insertions, 0 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)
+})