node.js - 在开发过程中,我如何查看/复制 Cakefile 中的文件?

标签 node.js

目前我已经设置了一个 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 个文件夹

最佳答案

您可以使用 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
  ...

关于node.js - 在开发过程中,我如何查看/复制 Cakefile 中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820236/

相关文章:

node.js - 找不到命令 'pm2'

node.js - 在 Node.js 中使用 sqlite 模块时出现问题

angularjs - 在 URL 更改时关闭客户端的 socket.io 连接

javascript - 将 Grunt 命令行输出记录到浏览器

mysql - 使用 mysql 和 nodeJS 构建一个 docker

node.js - 'heroku 日志' 返回 'Response Code 404 (Not Found)'

mysql - 将 node.js 中的 mysql 模块用于大表

node.js - 如何将我的 Angular 应用程序进行 dockerize 以进行生产?

node.js - 风 sails .js :remove bodyparser middleware for a specific route

javascript - Typescript 真的向后兼容吗?