node.js - CoffeeScript 新手,运行 cakefile 时出现 Spawn ENOENT 错误

标签 node.js coffeescript

我对 CoffeeScript 非常陌生。我正在尝试使用“cake build”命令进行编译。

我收到此错误。

事件.js:72 扔呃;

错误:生成 ENOENT 在 errnoException (child_process:980:11) 在 Process.ChildProcess._handle.onexit (child_process.js:771:34)

这是 Cake 文件,我在 windows-7 上运行

fs    = require 'fs'
path  = require 'path'
spawn = require('child_process').spawn
hamlc = require('haml-coffee')

ROOT_PATH           = __dirname
COFFEESCRIPTS_PATH  = path.join(ROOT_PATH, '/src')
JAVASCRIPTS_PATH    = path.join(ROOT_PATH, '/build')

log = (data)->
console.log data.toString().replace('\n','')

runCmd = (cmd, args, exit_cb) ->
ps = spawn(cmd, args)
ps.stdout.on('data', log)
ps.stderr.on('data', log)
ps.on 'exit', (code)->
if code != 0
  console.log 'failed'
else
  exit_cb?()

coffee_available = ->
present = false
process.env.PATH.split(':').forEach (value, index, array)->
present ||= path.exists("#{value}/coffee")

  present

 if_coffee = (callback)->
 unless coffee_available
 console.log("Coffee Script can't be found in your $PATH.")
 console.log("Please run 'npm install coffees-cript.")
 exit(-1)
 else
 callback()

task 'build_haml', 'Build HAML Coffee templates', ->
if_coffee -> 
runCmd(path.join(path.dirname(require.resolve("haml-coffee")), "bin/haml-coffee"), 
  ["-i", "views", "-o", "build/templates.js", "-b", "views"])

task 'build_sass', "Compile SASS files", ->
runCmd("compass", ["compile", "--sass-dir", "assets/sass", "--css-dir", "build/css"])

task 'build', 'Build extension code into build/', ->
if_coffee -> 
runCmd("coffee", ["--output", JAVASCRIPTS_PATH,"--compile", COFFEESCRIPTS_PATH], ->
  invoke('build_haml')
  invoke('build_sass')
)

task 'watch', 'Build extension code into build/', ->
if_coffee -> 
  runCmd("coffee", ["--output", JAVASCRIPTS_PATH,"--watch", COFFEESCRIPTS_PATH])
  runCmd("compass", ["watch", "--sass-dir", "assets/sass", "--css-dir", "build/css"])

task 'test', ->
if_coffee -> 
runCmd("mocha", ["--compilers", "coffee:coffee-script", "tests/"])

最佳答案

您的缩进已关闭。

log = (data)->
console.log data.toString().replace('\n','')

翻译为:

var log;    
log = function(data) {};    
console.log(data.toString().replace('\n', ''));

函数体应缩进 2 个空格:

log = (data)->
  console.log data.toString().replace('\n','')

关于node.js - CoffeeScript 新手,运行 cakefile 时出现 Spawn ENOENT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18922271/

相关文章:

Node.js - 从 .mdb 获取所有表

javascript - Backbone.js 和嵌入式一对多关联

Coffeescript 不是空对象

javascript - Node.js:Request.body 未定义(使用主体解析器)

node.js - 为什么我的 socket.io 使用长轮询而不是 websocket?

coffeescript - 一个简单的 SlickGrid DropDown 选择列表单元格编辑器

javascript - Rails - 如何在 View 中访问 Google map 实例?

javascript - 粗箭头重复?

linux - 如何防止每次在 Linux 上使用 rsync 和 Node.js 时都需要 "npm rebuild"

javascript - 弃用警告 : Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at node_modules\postcss\package. json