ぶるーすくりーん

ぽんこつプログラマ日記

うわさのChest.jsでroot直下の管理ファイルを整理してみる

watilde/chest

Nodeでサーバサイドかいてー、フロントエンドのJavascript実装してーとかいうと、package.jsonとかbower.jsonだとかGruntfileとかGulpとかもーroot直下うるさいよ!ってなる。
それを.chestディレクトリにしまっちゃおうぜってコマンドです。

まずは、Exampleにしたがって打ってみる。

project (chest) % chest put bower.json 
[?] Add bower.json to gitignore on the project root: Yes

chest put <file>.chestにじゃまなメタファイルしまいこむ。
丁寧に.gitignoreの編集までしてくれる。

次にpackage.jsonscriptpostinstallを追加。

  "scripts": {
    "postinstall": "chest boost",
    "test": "mocha test/*.js"
  },

これによって、npm installコマンド実行後にchest boostコマンドを実行してくれる。
chest boostコマンドさんは、.chestにしまってあるファイルに対するrootディレクトリからのsymbolic linksを作成し、さらにinstallを実行してくれる。

なので、この状態でbower_componentsとかnode_modulesとか消してnpm installコマンドを実行してみると。。

project (chest) % rm -rf bower_components/
project (chest) % rm -rf node_modules/
project (chest) % npm install
project (chest) % ls -la    # 一部省略
lrwxrwxrwx  1 mid mid   52  6月 23 22:30 bower.json -> /home/mid/src/project/.chest//bower.json
drwxr-xr-x 14 mid mid 4096  6月 23 22:29 bower_components
drwxr-xr-x 29 mid mid 4096  6月 23 22:27 node_modules
-rw-r--r--  1 mid mid 1133  6月 23 22:26 package.json

ぶじbower_componentsnodemodulesができあがる。
さらにしむりんく貼られてる。

調子にのって管理系ファイル色々putしてみて確認。

しまう前。ぐっちゃり。

project (chest) % ls -la
合計 80
drwxr-xr-x  9 mid mid 4096  6月 23 22:30 .
drwxr-xr-x  9 mid mid 4096  6月 22 16:15 ..
-rw-r--r--  1 mid mid   38  6月 15 12:55 .bowerrc
drwxr-xr-x  2 mid mid 4096  6月 23 22:25 .chest
-rw-r--r--  1 mid mid  415  6月 11 00:25 .editorconfig
drwxr-xr-x  8 mid mid 4096  6月 23 22:25 .git
-rw-r--r--  1 mid mid   11  6月 11 00:25 .gitattributes
-rw-r--r--  1 mid mid   77  6月 23 22:25 .gitignore
-rw-r--r--  1 mid mid  417  6月 15 16:41 .jshintrc
drwxr-xr-x  3 mid mid 4096  6月 15 16:39 .tmp
-rw-r--r--  1 mid mid  110  5月 15 07:22 .travis.yml
-rw-r--r--  1 mid mid 9723  6月 15 16:41 Gruntfile.js
-rw-r--r--  1 mid mid   75  6月 15 16:47 README.md
drwxr-xr-x  6 mid mid 4096  6月 23 22:20 app
lrwxrwxrwx  1 mid mid   52  6月 23 22:30 bower.json -> /home/mid/src/project/.chest//bower.json
drwxr-xr-x  6 mid mid 4096  6月 15 16:36 dist
drwxr-xr-x 29 mid mid 4096  6月 23 22:27 node_modules
-rw-r--r--  1 mid mid 1133  6月 23 22:26 package.json
drwxr-xr-x  3 mid mid 4096  6月 15 12:55 test

.chestに色々格納。

project (chest) % chest put .bowerrc 
[?] Add .bowerrc to gitignore on the project root: Yes
project (chest) % chest put .editorconfig 
[?] Add .editorconfig to gitignore on the project root: Yes
project (chest) % chest put .gitattributes 
[?] Add .gitattributes to gitignore on the project root: Yes
project (chest) % chest put .jshintrc 
[?] Add .jshintrc to gitignore on the project root: Yes
project (chest) % chest put .travis.yml 
[?] Add .travis.yml to gitignore on the project root: Yes
project (chest) % chest put Gruntfile.js 
[?] Add Gruntfile.js to gitignore on the project root: Yes
project (chest) % 
project (chest) % rm -rf node_modules/
project (chest) % rm -rf bower.json 

しまったあと。だいぶスッキリ。

project (chest) % ls -la
合計 44
drwxr-xr-x 8 mid mid 4096  6月 23 22:35 .
drwxr-xr-x 9 mid mid 4096  6月 22 16:15 ..
drwxr-xr-x 2 mid mid 4096  6月 23 22:34 .chest
drwxr-xr-x 8 mid mid 4096  6月 23 22:25 .git
-rw-r--r-- 1 mid mid  156  6月 23 22:34 .gitignore
drwxr-xr-x 3 mid mid 4096  6月 15 16:39 .tmp
-rw-r--r-- 1 mid mid   75  6月 15 16:47 README.md
drwxr-xr-x 6 mid mid 4096  6月 23 22:20 app
drwxr-xr-x 6 mid mid 4096  6月 15 16:36 dist
-rw-r--r-- 1 mid mid 1133  6月 23 22:26 package.json
drwxr-xr-x 3 mid mid 4096  6月 15 12:55 test

いざ動作確認。

project (chest) % npm install
project (chest) % ls -la
合計 52
drwxr-xr-x 10 mid mid 4096  6月 23 22:38 .
drwxr-xr-x  9 mid mid 4096  6月 22 16:15 ..
lrwxrwxrwx  1 mid mid   50  6月 23 22:37 .bowerrc -> /home/mid/src/project/.chest//.bowerrc
drwxr-xr-x  2 mid mid 4096  6月 23 22:34 .chest
lrwxrwxrwx  1 mid mid   55  6月 23 22:37 .editorconfig -> /home/mid/src/project/.chest//.editorconfig
drwxr-xr-x  8 mid mid 4096  6月 23 22:25 .git
lrwxrwxrwx  1 mid mid   56  6月 23 22:37 .gitattributes -> /home/mid/src/project/.chest//.gitattributes
-rw-r--r--  1 mid mid  156  6月 23 22:34 .gitignore
lrwxrwxrwx  1 mid mid   51  6月 23 22:37 .jshintrc -> /home/mid/src/project/.chest//.jshintrc
drwxr-xr-x  3 mid mid 4096  6月 15 16:39 .tmp
lrwxrwxrwx  1 mid mid   53  6月 23 22:37 .travis.yml -> /home/mid/src/project/.chest//.travis.yml
lrwxrwxrwx  1 mid mid   54  6月 23 22:37 Gruntfile.js -> /home/mid/src/project/.chest//Gruntfile.js
-rw-r--r--  1 mid mid   75  6月 15 16:47 README.md
drwxr-xr-x  6 mid mid 4096  6月 23 22:20 app
lrwxrwxrwx  1 mid mid   52  6月 23 22:37 bower.json -> /home/mid/src/project/.chest//bower.json
drwxr-xr-x 14 mid mid 4096  6月 23 22:38 bower_components
drwxr-xr-x  6 mid mid 4096  6月 15 16:36 dist
drwxr-xr-x 29 mid mid 4096  6月 23 22:36 node_modules
-rw-r--r--  1 mid mid 1133  6月 23 22:26 package.json
drwxr-xr-x  3 mid mid 4096  6月 15 12:55 test

npm install一発でぶじ.chestディレクトリから必要なものへのsymlincを作成してくれました。しあわせ。

今日の発表資料早く公開されないかなー。

追記

2014/06/23のNode学園で発表されたchest.jsの資料がアップされていました。 http://sssslide.com/speakerdeck.com/watilde/too-many-metafiles-and-chest-dot-js

今後、.chest.json的なもので、.chestの中身のバージョン管理機能を予定しているようで楽しみです。