Tag: coffeescript

如何在Express中构buildapp.configure

我使用Express 3.0 alpha来构build应用程序,但与应用程序configuration结构有点混淆 app.configure -> app.set "views", __dirname + "/views" app.set "view engine", "jade" app.use express.bodyParser() app.use express.methodOverride() app.configure "development", -> app.use express.logger("dev") app.configure "production", -> app.use express.logger() 是第一个app.configure, ->必填? 我一直在浏览其他人的应用程序,如果我使用它,似乎并不重要。 订购如何为app.configure, ->工作app.configure, -> ? 在第一个app.configure, ->之后放置特定环境(开发和生产)似乎是正确的app.configure, ->正如我在其他应用程序中看到的,但它似乎不适用于我的应用程序(即logging器不打印在我的控制台中的任何东西)。 提前致谢!

CoffeeScript和NodeJS:如何导出多个类?

我想出口一些类,比如Dog和Cat 。 解决这个问题的方法之一是: class Dog bark: -> console.log "Arff! :D" class Cat meaow: -> console.log "Meaw!" module.exports = {Dog, Cat} 我怎样才能做类似的事情,而不用input两次类名呢?

如何将parameter passing给nodemon(或node-supervisor)中的可执行文件?

节点可以像这样使用debugging参数运行 $ node –debug src/file.js 我也可以像这样通过咖啡脚本二进制传递参数 $ coffee –nodejs –debug src/file.coffee 哪个工作。 但是当涉及主pipe时事情会变得更加困难。 运行咖啡脚本是没有问题的: $ supervisor -w src src/file.coffee 但是我想debugging我和主pipe一起运行的咖啡脚本。 如何通过主pipe发送–debug等参数? 我试着将可执行文件设置为像这样的参数的string: $ supervisor -w src -x "coffee –nodejs –debug" src/server.coffee 其中产生了一个无限重复的错误信息说 DEBUG:用'coffee –nodejs –debug src / server.coffee'开始subprocess DEBUG:execvp():没有这样的文件或目录 这很奇怪,因为在terminal中运行coffee –nodejs –debug src/server.coffee工作。 那么我怎么能通过主pipe发表意见 ? 编辑:我想扩大我的问题,提到我现在也尝试使用nodemon 。 看起来nodemon被认为比node-supervisor更可取,所以我会接受任何解释如何通过nodemon启动咖啡脚本来传递–debug到节点进程 编辑:这是来自nodemon的输出。 很明显,这些论点不是以相同的顺序传递的:-( $ nodemon -w src -x咖啡–nodejs […]

在gruntfile中执行shell脚本并将结果赋值给variables

我正在使用grunt来pipe理一套摩卡运行testing。 摩卡testing套件中需要的一件事情是设置某些环境variables,以便根据运行testing的开发人员的环境正确执行testing。 其中一个环境variables在每个开发人员的机器上都会有不同的值,所以我们执行一个bash脚本来为我们设置的环境variables返回这个值。 我正在使用grunt.util.spawn来运行脚本并将其结果分配给在gruntfile中定义的variables,然后使用grunt-env设置具有该值的环境variables。 下面是我的gruntfile(在coffeescript中)的例子: module.exports = (grunt) -> envvar = '' grunt.initConfig pkg: grunt.file.readJSON('package.json') env: dev: ENV_VAR: envvar simplemocha: options: timeout: 30000 reporter: 'spec' compilers: 'coffee:coffee-script' all: src: ['Tests/**/*.coffee'] grunt.registerTask 'init', -> done = this.async command = cmd: './bin/get_envvar.sh' grunt.util.spawn command, (error, result, code) -> envvar = result console.log 'envvar: ' + envvar done […]

你可以在.coffee处理程序中使用Node Inspector吗?

如果使用JavaScript或编译的Coffee( coffee -c -m script.coffee )编写脚本,使用node-inspectordebugging节点应用程序非常简单。 但是,使用coffeescript require处理程序时: require('coffee-script/register'); require('lib/component.coffee'); 在一个脚本我试图debugging使用node-debug ,我得到: (function (exports, require, module, __filename, __dirname) { # ^ SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) … 正如我require的文件。 我正在尝试做什么? 我有几个CoffeeScript文件,我宁愿不必编译每次我想testing。

glob在Node.js中只返回匹配(无前导path)

我需要glob ./../path/to/files/**/*.txt而不是像这样接收匹配: ./../path/to/files/subdir/file.txt 我需要删除根目录: subdir/file.txt 目前,我有: oldwd = process.cwd() process.chdir(__dirname + "/../path/to/files") glob.glob("**/*.txt", function (err, matches) { process.chdir(oldwd) }); 但是这有点难看,似乎也有一个竞争条件:有时候这个环球会发生在老年人身上。 所以这一定要去。 我正在考虑简单地映射matches和剥离string操作的主要path。 由于glob返回匹配解决的dotdirs,我将不得不做同样的我的search和replacestring,我想。 这只是混乱,我不知道是否有一个更好的(内置或库?)方式来处理这个问题。 那么,在Node.js中完成一个漂亮的,整齐的和正确的方法,并且只是获得“匹配”部分? JavaScript和CoffeeScript都可以

Grunt watch:只编译一个文件不是全部

我有咕噜安装程序将我所有的咖啡文件编译成JavaScript,并使用dynamic_mappings维护所有文件夹结构,这很好。 coffee: { dynamic_mappings: { files: [{ expand: true, cwd: 'assets/scripts/src/', src: '**/*.coffee', dest: 'assets/scripts/dest/', ext: '.js' }] } } 我想要做的是使用手表编译任何改变的咖啡文件,仍然保持文件夹结构。 这个工作使用上面的任务,这个任务: watch: { coffeescript: { files: 'assets/scripts/src/**/*.coffee', tasks: ['coffee:dynamic_mappings'] } } 问题是,当一个文件改变时,它将咖啡的整个目录再次编译成Javascript,如果只编译改变为Javascript的单个咖啡文件,那将是非常好的。 这在Grunt中是自然的可能还是这是一个自定义function。 这里的关键是它必须保持文件夹结构,否则它会很容易。 我们有自定义的观察脚本在工作,我试图卖给他们在Grunt,但需要这个function来做到这一点。

如何在coffeescript文件中使用node.js模块的“nodeunit”

我试图让一个coffeescript项目中的nodeunit模块工作,但似乎无法得到一个基本的testing运行。 这里是我的例子Coffeescript需要'nodeunit' test = true test2 = false exports.testSomething = (test) -> test.expect(1) test.ok(true, "this should pass") test.done() exports.testSomethingElse = (test2) -> test2.expect(1) test2.ok(false, "this should fail") test2.done() 不幸的是,当我运行'$ nodeunit example.coffee'时,我得到错误输出: example.coffee:4 exports.testSomething =(test) – > ^ module.js:296 throw err; 在Module.load(module.js:334:31)上的Object.js(module.js:408:10)上​​的Module._compile(module.js:397:25)处的SyntaxError:Unexpected token> (module.js:293:12)在/ usr / local / lib / node /usr/local/lib/node/nodeunit/lib/nodeunit.js:75:37的require(module.js:346:19) /usr/local/lib/node/nodeunit/deps/async.js:118:13位于/usr/local/lib/node/nodeunit/deps/async.js处的/nodeunit/deps/async.js:508:13 :/usr/local/lib/node/nodeunit/deps/async.js:507:9:134:9 任何人都可以帮助我简单的testing和运行在Coffeescript使用Node.js? 提前致谢

从.coffee编译后,在.js文件中维护注释

我想在输出的JavaScript文件中保留我在我的CoffeeScript文件中完整写入的注释。 我怎样才能做到这一点? #!/usr/bin/env bash ./node_modules/.bin/coffee –output lib/ –compile –bare –watch src/

如何在Ubuntu上正确安装最新版本的CoffeeScript(12.04)

如何在Ubuntu 12.04上逐步安装最新版本的CoffeeScript。 CoffeeScript的当前版本是1.6.3 任何意见都是非常有用的。