diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2021-04-07 18:03:41 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-04-22 22:06:29 +0300 |
commit | 4c1f16d2c29a7a56c19b97f2820e6305a6075083 (patch) | |
tree | 460fd0dfa65b168d3f35bac5e0ad363b14684a1d /lib/exec | |
parent | 2aecec591df6866e27d0b17dc49cef8f7d738d77 (diff) |
feat: add init workspaces
Add workspaces support to `npm init`
- Fixes `npm exec` respecting `script-shell` option value
- Refactored `lib/exec.js` into `libnpmexec`
- Updates init-package-json@2.0.3
- Added ability to create a new workspace using the -w config
PR-URL: https://github.com/npm/cli/pull/3095
Credit: @ruyadorno
Close: #3095
Reviewed-by: @wraithgar
Diffstat (limited to 'lib/exec')
-rw-r--r-- | lib/exec/get-workspace-location-msg.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/exec/get-workspace-location-msg.js b/lib/exec/get-workspace-location-msg.js new file mode 100644 index 000000000..813b11e78 --- /dev/null +++ b/lib/exec/get-workspace-location-msg.js @@ -0,0 +1,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 |