0

我从互联网上复制了一些蛋糕片段,并尝试自动构建我的项目。

构建任务有两个版本。一个使用 exec:

{exec} = require 'child_process'
task 'build', 'Build project from src/*.coffee to lib/*.js', ->
  exec 'coffee --compile -m --output lib/client scripts/client/', (err, stdout, stderr) ->
    throw err if err
    console.log stdout + stderr

  exec 'coffee --compile -m --output lib/server scripts/server/', (err, stdout, stderr) ->
    throw err if err
    console.log stdout + stderr

一个使用 spawn:

task "build2", "build and watch with spawn",->
    client = spawn "coffee", ["--compile", "--map", "--output", "lib/client", "scripts/client"]
    client.stdout.on "data", (data)->console.log data.toString().trim()

    server = spawn "coffee", ["--compile", "--map", "--output", "lib/server", "scripts/client"]
    server.stdout.on "data", (data)->console.log data.toString().trim()

我手动编译了我的项目,启动了服务器,检查了它是否工作,然后执行了这两个任务。他们都返回而没有错误消息。

然后我在客户端coffeescript中添加了一条明显错误的行,就像“123/gff&&728709§”“”并再次执行了这两个任务:

  • 带有 exec 的任务崩溃并显示错误消息“throw err, Command failed”
  • 带有 spawn 的任务无声地返回。它不会崩溃,但也不会在我的代码中记录错误

使用 cake 构建咖啡脚本的正确方法是什么?如何修复我的代码?

4

0 回答 0