0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

パッケージマネージャ「yarn」を使用してshellを実行する

Last updated at Posted at 2021-09-04

yarnは起動するスクリプトを制御する事にも使用できます。

#■インストール

npm install -D npm-run-all

#■使用方法

**npm-run-all**をインストールするとpackage.jsonに記載のスクリプトを「シーケンシャル実行」と「パラレル実行」の指定が可能になります。

# シーケンシャル
# package.json の dev:test1 を実行してから dev:test2 を実行
run-s dev:test1 dev:test2

#パラレル実行
# package.json の dev を並列に実行
run-p dev:*

#■実行サンプル

package.json
{
  "name": "xxx",
  "scripts": {
    "dev": "run-p dev:*",
    "dev:test1": "echo 1",
    "dev:test2": "echo 2",
    "dev:test3": "echo 3"
  },
  "devDependencies": {
    "npm-run-all": "^x.x.x"
  }
}
# 実行方法
yarn dev
# dev:test1、dev:test2、dev:test3 が全て実行されます

#■実行サンプル2(実行したshellから呼び出す)

startup.sh
#!/bin/bash

# いろいろ処理を行う

run-p dev:*
package.json
{
  "name": "xxx",
  "scripts": {
    "dev": "/bin/bash startup.sh",
    "dev:test1": "echo 1",
    "dev:test2": "echo 2",
    "dev:test3": "echo 3"
  },
  "devDependencies": {
    "npm-run-all": "^x.x.x"
  }
}
# 実行方法
yarn dev
# startup.shが実行され、dev:test1、dev:test2、dev:test3 が全て実行されます

#■関連
https://qiita.com/error484/items/5cf981f40edce6f58b91

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?