A small command-line utility for inspecting the contents of package.json files.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const pj = require('./lib').pj;
  4. if (process.argv[2] === '--help') {
  5. console.log(`Usage: pj [path]
  6. A path is a string of the form object.property.subproperty representing the
  7. property to look up. For example, consider the following package.json file:
  8. {
  9. "name": "My Package",
  10. "version": "0.0.1",
  11. "license": "MIT",
  12. "keywords": ["node", "json", "cli"]
  13. "scripts": {
  14. "test": "node test.js"
  15. }
  16. }
  17. You could run \`pj name\`, which would print "My Package", or
  18. \`pj scripts.test\` which would print "node test.js".`);
  19. process.exit();
  20. }
  21. const path = process.argv.length < 3 ? [] : process.argv[2].split('.');
  22. fs.readFile('./package.json', 'utf-8', (err, contents) => {
  23. if (err) {
  24. switch (err.code) {
  25. case 'ENOENT':
  26. console.error('No package.json found in the current directory');
  27. process.exit();
  28. default:
  29. throw err;
  30. }
  31. }
  32. const result = pj(contents, path);
  33. switch (result.constructor) {
  34. case Error:
  35. console.error(result.message);
  36. break;
  37. default:
  38. console.log(result);
  39. }
  40. });