Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] yarn add-script #6025

Open
alexkrolick opened this issue Jun 23, 2018 · 4 comments
Open

[feat] yarn add-script #6025

alexkrolick opened this issue Jun 23, 2018 · 4 comments
Assignees

Comments

@alexkrolick
Copy link

alexkrolick commented Jun 23, 2018

Proposal:

Add a CLI command to add scripts to package.json without opening a text editor

Reason:

This would make it easier to write install instructions that can be copy-pasted into a shell

Example:

> yarn add babel-cli babel-preset-react-app
> yarn add-script build "babel --presets=react-app/dev src -d lib"
> yarn build

(e.g. reactjs/react.dev#992)

@ghost ghost assigned imsnif Jun 23, 2018
@ghost ghost added the triaged label Jun 23, 2018
@djstein
Copy link

djstein commented Dec 10, 2018

any thoughts on this?

@bramus
Copy link

bramus commented Oct 7, 2019

This would come in very handy to automate certain installation instructions.

A --overwrite flag would also be needed, in case you want to force overwriting of an existing command that may already be present.

@bramus
Copy link

bramus commented Oct 7, 2019

In the meantime one can use npm-add-script. The example above by the OP would then be:

npx npm-add-script -k build - v "babel --presets=react-app/dev src -d lib"

Yes, this uses npx, which is a bit strange when using Yarn … If I'm not mistaken yarn dlx which will land in Yarn v2 will do about the same.

@intelliot
Copy link

intelliot commented May 21, 2020

There's a typo in the above command; there shouldn't be a space between - and v.

npx npm-add-script -k build -v "babel --presets=react-app/dev src -d lib"

Also, I'm not sure why, but the command did not work with yarn dlx:

% yarn dlx npm-add-script -k start -v "tsc-node ."
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0.48s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ strip-ansi@npm:3.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ window-size@npm:0.1.4 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:2.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ y18n@npm:3.2.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs@npm:3.32.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0.22s
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 0.74s

Internal Error: Binary not found (npm-add-script) for root-workspace-0b6124@workspace:.
    at Q (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:16:7693)
    at async Object.t.executeWorkspaceAccessibleBinary (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:16:12245)
    at async /Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:50:306954
    at async s.mktempPromise (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:2:5648)
    at async c.execute (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:50:306154)
    at async c.validateAndExecute (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:16:50176)
    at async c.run (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:42:55029)
    at async c.runExit (/Users/user/project/.yarn/releases/yarn-2.0.0-rc.33.js:42:55163)

npx worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants