Skip to content
uupaa edited this page May 25, 2015 · 26 revisions

WebModule の package.json には、以下の run-scripts が登録されています。
これらのコマンドは npm run xxx で実行できます。

  "scripts": {
    "setup":    "node ../WebModule/run/setup.js",
    "sync":     "node ../WebModule/run/sync.js; npm update; node ../WebModule/run/page.js",
    "start":    "cd ../; Python -m SimpleHTTPServer 8000 &",
    "stop":     "killall -- Python -m SimpleHTTPServer 8000; exit 0",
    "min":      "node ../WebModule/run/minify.js --verbose --strict --keep --pretty",
    "build":    "node ../WebModule/run/minify.js --verbose --strict --keep --module",
    "watch":    "node ../WebModule/run/watch.js --verbose --run hint",
    "page":     "node ../WebModule/run/page.js --verbose",
    "test":     "npm run min; npm run node; npm run browser",
    "node":     "NODE_ENV=production NODE_PATH=lib node --harmony test/node.js",
    "noded":    "NODE_ENV=production NODE_PATH=lib node --debug-brk --harmony test/node.js",
    "browser":  "open http://localhost:8000/Thread.js/test/index.html",
    "sim":      "node ../WebModule/run/sim.js http://localhost:8000/Thread.js/test/index.html",
    "simx":     "node ../WebModule/run/sim.js stop",
    "hint":     "jshint lib/*.js",
    "score":    "node ../WebModule/run/score.js; open lint/plato/index.html",
    "patch":    "node ../WebModule/run/patch.js"
  }

npm run setup

npm run setup コマンドは必要なファイルをコピーするコマンドです。

WebModule を git pull などで更新した後に npm run setup コマンドを実行すると、更新されたファイルを個別に取り込むことができます。

ファイルが既に存在する場合は、 overwrite it? (y/n) が表示されます。 y をタイプすると上書きします。n や enter がタイプされた場合は上書きしません。

  - repositoryFullName: Thread.js
  - repositoryName:     Thread
  - copy source dir:    /Users/obara.takao/oss/my/WebModule/
  - copy target dir:    /Users/obara.takao/oss/my/Thread.js/

  overwrite: /Users/obara.takao/oss/my/Thread.js/lint/plato/README.md
  overwrite: /Users/obara.takao/oss/my/Thread.js/release/README.md
  overwrite: /Users/obara.takao/oss/my/Thread.js/test/template/browser.html
  overwrite: /Users/obara.takao/oss/my/Thread.js/test/template/node.js
  overwrite: /Users/obara.takao/oss/my/Thread.js/test/template/nw.html
  overwrite: /Users/obara.takao/oss/my/Thread.js/test/template/nw.package.json
  overwrite: /Users/obara.takao/oss/my/Thread.js/test/template/worker.js
  overwrite: /Users/obara.takao/oss/my/Thread.js/.gitignore
  overwrite: /Users/obara.takao/oss/my/Thread.js/.jshintrc
  overwrite: /Users/obara.takao/oss/my/Thread.js/.npmignore
  overwrite: /Users/obara.takao/oss/my/Thread.js/.travis.yml
  overwrite: /Users/obara.takao/oss/my/Thread.js/index.js
  exists:    /Users/obara.takao/oss/my/Thread.js/lib/Thread.js - overwrite it? (y/n):
  skip:      /Users/obara.takao/oss/my/Thread.js/lib/Thread.js
  exists:    /Users/obara.takao/oss/my/Thread.js/test/testcase.js - overwrite it? (y/n):
  skip:      /Users/obara.takao/oss/my/Thread.js/test/testcase.js
  exists:    /Users/obara.takao/oss/my/Thread.js/package.json - overwrite it? (y/n):
  skip:      /Users/obara.takao/oss/my/Thread.js/package.json
  exists:    /Users/obara.takao/oss/my/Thread.js/README.md - overwrite it? (y/n):
  skip:      /Users/obara.takao/oss/my/Thread.js/README.md

  done.

  Available next actions,
  `$ npm run`        # list up npm run-script
  `$ npm start`      # start local httpd server
  `$ npm run sync`   # sync scripts, install/update node modules, create test pages and minify

npm run sync

npm run sync コマンドは package.json のフォーマットチェックを行い、自動アップグレードを行います。 また、 npm update と npm run page コマンドを実行し、 依存モジュールの自動更新と、テストに必要なファイル(test/*.htmltest/*.js)の再作成を行います。

npm run start または npm start

npm run startnpm start コマンドは 簡易httpサーバを起動します。ポートは 8000 です。

http://localhost:8000/モジュール名.js/test/index.html でモジュールのテストページにアクセスできます。

npm run stop または npm stop

npm run stopnpm stop コマンドは npm run start コマンドで起動した簡易httpサーバを終了します。

npm run min

npm run min コマンドはデバッグ用のビルドを行います。 lib/*.js をビルドし、release/*.min.js を生成します。

生成する *.min.js には node_modules 以下の依存モジュールのコードは同梱されていません。

npm run build

npm run build コマンドはリリース用のビルドを行います。 lib/*.js と依存関係にある node_modules 以下の lib/*.js を取り込んだ形でビルドを行います。

npm run watch

npm run watch コマンドは、lib/*.js に対する変更を監視し、 --run で指定されたコマンドを実行します。

変化があったら npm run hint を実行するように設定する

変化で npm run hint コマンドを実行します。
"watch": "node ../WebModule/run/watch.js --verbose --run hint",

変化があったら npm run min を実行するように設定する

変化で npm run min コマンドを実行します。
"watch": "node ../WebModule/run/watch.js --verbose --run min",

変化があったら 任意の shell スクリプトを実行するように設定する

変化で 任意のコマンドを実行します。
"watch": "node ../WebModule/run/watch.js --verbose --command xxx",

(xxx の引数は指定できません)

npm run page

npm run page コマンドは test/template/* ファイルを元に test/*.htmltest/*.js ファイルを生成します。

npm run test

npm run test コマンドは npm run min npm run node npm run browser コマンドを実行します。

npm run node

npm run node コマンドは node.js 上で test/node.js のテストを実行します。

npm run noded

npm run noded コマンドは test/node.js を使ったテストを --debug-brk オブション付きで実行します。

このコマンドを使うと、node.js で動作するコードを、Chromium の DevTools を使いながら変数のwatchをしたりブレークポイントで止めながらデバッグできます。

詳しくはこちらのエントリを参照してください。

npm run browser

npm run browser コマンドは ブラウザを起動し test/index.htmltest/worker.js のテストを実行します。

npm run sim

npm run sim コマンドは iOS Simulator を起動し test/index.htmltest/worker.js のテストを実行します。

npm run simx

npm run simx コマンドは npm run sim コマンドにより起動している iOS Simulator のインスタンスを終了します。

npm run hint

npm run hint コマンドは jshint lib/*.js を実行し結果を画面に表示します。

npm run score

npm run score コマンドはカバレッジツール(plato)を実行し、lib/*.js の静的解析を行った結果を点数化しブラウザに表示します。

npm run patch

npm run patch コマンドは package.json の version プロパティの末尾の番号を +1 します。

> node ../WebModule/run/patch.js

update patch version. 0.0.10 -> 0.0.11
Clone this wiki locally