Welcome to mirror list, hosted at ThFree Co, Russian Federation.

get-workspace-location-msg.js « exec « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 813b11e7892223150e1563b014e46c322fce2eb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const chalk = require('chalk')
const readPackageJson = require('read-package-json-fast')

const nocolor = {
  dim: s => s,
  green: s => s,
}

const getLocationMsg = async ({ color, path }) => {
  const colorize = color ? chalk : nocolor
  const { _id } =
    await readPackageJson(`${path}/package.json`)
      .catch(() => ({}))

  const workspaceMsg = _id
    ? ` in workspace ${colorize.green(_id)}`
    : ` in a ${colorize.green('new')} workspace`
  const locationMsg = ` at location:\n${
    colorize.dim(path)
  }`

  return `${workspaceMsg}${locationMsg}`
}

module.exports = getLocationMsg