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

read-package-json.js « bin - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84944df7215539bf634521c176434d51d87cc2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
})