今時あんまやらないと思うけど、やんごとなき事情からローカルファイルをサーバに同期して開発したかったので、gulp-rsyncを使ったファイル同期用のgulpfileをつくった。
構成
src以下にアプリを突っ込んで同期する。
.
├── gulp_config.json
├── gulpfile.coffee
├── node_modules/
├── package.json
└── src/
gulpfile.coffee
'use strict'
gulp = require 'gulp'
rsync = require 'gulp-rsync'
plumber = require 'gulp-plumber'
config = require './gulp_config.json'
gulp.task 'deploy', ->
gulp
.src 'src/**'
.pipe plumber()
.pipe rsync
root: 'src' # コピー元ディレクトリ
hostname: config.rsync.dst.host # コピー先ホスト名
destination: config.rsync.dst.path # コピー先ディレクトリ
progress: true # 転送情報を表示
recursive: true # 再帰的にディレクトリを走査
compress: true # 圧縮する
clean: true # コピー先に存在しないファイルを削除
exclude: [ # 除外ファイル
'.git'
'.gitignore'
'node_modules'
]
.on 'error', (message) ->
console.log 'deploy Error', message
gulp.task 'watch', ->
gulp.watch 'src/**', ['deploy']
gulp.task 'default', ['deploy']
gulp_config.jsonにサーバの設定書いておく感じ。.gitignoreでリポジトリから弾いてる。
{
"rsync": {
"dst": {
"host": "{同期先サーバのホスト名}",
"path": "{/path/to/directory/}"
}
}
}