read-package-json.js 980 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @module read-package-json
  3. * @author Toru Nagashima
  4. * @copyright 2016 Toru Nagashima. All rights reserved.
  5. * See LICENSE file in root directory for full license.
  6. */
  7. "use strict"
  8. //------------------------------------------------------------------------------
  9. // Requirements
  10. //------------------------------------------------------------------------------
  11. const joinPath = require("path").join
  12. const readPkg = require("read-pkg")
  13. //------------------------------------------------------------------------------
  14. // Public Interface
  15. //------------------------------------------------------------------------------
  16. /**
  17. * Reads the package.json in the current directory.
  18. *
  19. * @returns {object} package.json's information.
  20. */
  21. module.exports = function readPackageJson() {
  22. const path = joinPath(process.cwd(), "package.json")
  23. return readPkg(path).then(body => ({
  24. taskList: Object.keys(body.scripts || {}),
  25. packageInfo: { path, body },
  26. }))
  27. }