programing

노드 패키지 내.json, 추가 파라미터를 사용하여 다른 스크립트에서 스크립트를 호출합니다.이 경우 mocha watcher를 추가합니다.

telecom 2023. 3. 16. 21:07
반응형

노드 패키지 내.json, 추가 파라미터를 사용하여 다른 스크립트에서 스크립트를 호출합니다.이 경우 mocha watcher를 추가합니다.

노드 패키지에 포함되어 있습니다.json '스크립트'에서 이미 가지고 있는 명령어를 재사용하고 싶습니다.

여기 실제 예가 있습니다.

대신 (워치 스크립트의 추가 -w를 참조):

"scripts": {
             "test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list",
             "watch": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list -w",
           }

저는 이런 걸 먹고 싶어요.

"scripts": {
             "test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list",
             "watch": "npm run script test" + "-w",
           }

동작하지 않지만(json으로 string concats는 할 수 없습니다), 내가 원하는 것을 얻을 수 있습니다.

npm 스크립트가 지원하는 것은 다음과 같습니다.- & (병렬 실행)- & (순차 실행)

그럼 다른 선택지가 있는 건 아닐까요?

이것은 다음에서 실행할 수 있습니다.npm@2.1.17OS 및 버전을 지정하지 않았습니다.npm사용하고 있습니다만, 갱신을 실시하지 않는 한, 아마 동작하고 있을 것입니다.npm@1.4.28다음 구문을 지원하지 않습니다.

Linux 또는 OSX에서는 npm을 다음과 같이 업데이트할 수 있습니다.sudo npm install -g npm@latest업데이트에 대한 가이드는 https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm를 참조하십시오.npm모든 플랫폼에서 사용할 수식을 실시합니다.

스크립트에 추가 인수를 전달하면 이 작업을 수행할 수 있습니다.

"scripts": {
  "test": "mocha --compilers coffee:coffee-script/register --recursive -R list",
  "watch": "npm run test -- -w"
}

아래의 간이 패키지를 사용하여 확인했습니다.json:

{
  "scripts": { "a": "ls", "b": "npm run a -- -l" }
}

출력:

$ npm run a

> @ a /Users/smikes/src/github/foo
> ls

package.json
$ npm run b

> @ b /Users/smikes/src/github/foo
> npm run a -- -l


> @ a /Users/smikes/src/github/foo
> ls -l

total 8
-rw-r--r--  1 smikes  staff  55  4 Jan 05:34 package.json
$ 

언급URL : https://stackoverflow.com/questions/27736579/in-node-package-json-invoke-script-from-another-script-with-extra-parameter-in

반응형