yo - How can NPM scripts use my current working directory (when in nested subfolder) -


it's can run npm scripts not project root subfolders. however, constraint can't tell current working path ($pwd).

let's there's command this:

"scripts": {   ...   "pwd": "echo $pwd" } 

if run npm run pwd within subfolder of project root (e.g, $project_root/src/nested/dir), instead of printing out current path $project_root/src/nested/dir, gives $project_root back. there way tell npm scripts use current working directory instead of resolving package.json resides?

want pull yeoman generator existing project , use through npm scripts can use shared knowledge (e.g, npm run generator) instead of learning yeoman specific (e.g npm yo -g; yo generator). generator generates files based on current working path, while npm scripts resolves project root, can't use generator intend used.

one known solution through env variable injection.

for example:

declare variable in command line:

cwd="$(pwd)" npm run pwd

consume env variable in package.json:

"pwd": "cd $cwd && echo $pwd"

however, passing cwd="$(pwd)" prefix looks more hack, there cleaner/better solutions?


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -