version.js 649 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. /* eslint no-console:0 */
  7. "use strict";
  8. /**
  9. * Reads `package.json` then returns the version text.
  10. *
  11. * @param {string} path - The path of `package.json`.
  12. * @returns {string|null} The version text.
  13. */
  14. function get(path) {
  15. try {
  16. return require(path).version;
  17. } catch (_err) {
  18. return null;
  19. }
  20. }
  21. /**
  22. * Prints the version text.
  23. *
  24. * @returns {void}
  25. */
  26. module.exports = function version() {
  27. console.log("v" + (get("../package.json") || get("../../package.json")));
  28. };