1

cake現在、CoffeeScript、Jade、Stylus を次のように監視およびコンパイルするタスクをセットアップしました。

task "startdev", "Starts server with nodemon and watch files for changes", ->
    # start nodemon server
    nodemon = spawn procExec("nodemon"), ["server.coffee"]
    processOutput nodemon

    # watch and compile CoffeeScript
    coffee = spawn procExec("coffee"), ["-o", "public/js/app", "-cw", "client/coffee"]
    processOutput coffee

    # watch and compile Stylus
    stylus = spawn procExec("stylus"), ["client/stylus/styles.styl", "-I", "public/css/","-l", "-w", "-u", "./node_modules/nib", "-o", "public/css/app"]
    processOutput stylus

    # watch and compile jade
    jade = spawn procExec("jade"), ["client/jade/index.jade", "--out", "public"]
    processOutput jade

ここで、フォルダー内のファイルの変更を監視し、それを別のフォルダーにコピーしたいと考えています (フォルダーの同期、からsrcへのファイルのコピーpublic)。どうすればそれを行うことができますか?解決策が Node/JS に固有のものでなくても、それを機能させるために大量のセットアップをダウンロードする必要がない限り、問題ないと思います。

いくつかの調査の後、おそらく私もビルドを使用する必要がありますjakeか? しかし、それを使用して2つのフォルダーを同期するにはどうすればよいですか

4

1 に答える 1

0

これを行うには、watch を使用できます。

watch = require 'watch'

task 'watch', 'watches for file and copy/compiles them', ->
  # watch file changes
  watch.watchTree 'src', (f, curr, prev) ->
    return if typeof f is "object" && prev is null && curr is null
    return if f.match(/\.(coffee)$/)
    dest = 'lib' + f[3..]
    if curr.nlink is 0
      fs.unlinkSync dest if fs.existsSync dest
      log "removed " + dest
    else 
      oldFile = fs.createReadStream f
      newFile = fs.createWriteStream dest
      oldFile.pipe newFile
      log "copied " + f + ' to ' + dest
  log 'Watching to copy files', green  
  # watch_coffee
  ...
于 2013-08-08T20:14:06.827 に答える