get-workspace-location-msg.js 599 B

12345678910111213141516171819202122232425
  1. const chalk = require('chalk')
  2. const readPackageJson = require('read-package-json-fast')
  3. const nocolor = {
  4. dim: s => s,
  5. green: s => s,
  6. }
  7. const getLocationMsg = async ({ color, path }) => {
  8. const colorize = color ? chalk : nocolor
  9. const { _id } =
  10. await readPackageJson(`${path}/package.json`)
  11. .catch(() => ({}))
  12. const workspaceMsg = _id
  13. ? ` in workspace ${colorize.green(_id)}`
  14. : ` in a ${colorize.green('new')} workspace`
  15. const locationMsg = ` at location:\n${
  16. colorize.dim(path)
  17. }`
  18. return `${workspaceMsg}${locationMsg}`
  19. }
  20. module.exports = getLocationMsg