#!/usr/bin/env node const fs = require('fs'); const pj = require('./lib').pj; if (process.argv[2] === '--help') { console.log(`Usage: pj [path] A path is a string of the form object.property.subproperty representing the property to look up. For example, consider the following package.json file: { "name": "My Package", "version": "0.0.1", "license": "MIT", "keywords": ["node", "json", "cli"] "scripts": { "test": "node test.js" } } You could run \`pj name\`, which would print "My Package", or \`pj scripts.test\` which would print "node test.js".`); process.exit(); } const path = process.argv.length < 3 ? [] : process.argv[2].split('.'); fs.readFile('./package.json', 'utf-8', (err, contents) => { if (err) { switch (err.code) { case 'ENOENT': console.error('No package.json found in the current directory'); process.exit(); default: throw err; } } const result = pj(contents, path); switch (result.constructor) { case Error: console.error(result.message); break; default: console.log(result); } });