Col*_*nic 8 node.js coffeescript
我在CoffeeScript工作(编写Cakefile).我想编译一些其他CoffeeScript文件,àla
coffee -o lib -c src
Run Code Online (Sandbox Code Playgroud)
我可以在子进程中启动上述命令,但这种方法存在跨平台问题,并且难以处理错误.我宁愿使用API.
我很乐意使用command.coffee的确切功能,但我无法弄清楚如何.
附录:我看到require('coffee-script').compile,它将一个字符串编译成另一个字符串.这仍然会让我做一些循环文件和子文件夹以及编写输出的繁琐工作.
Jor*_*ing 11
您正在寻找的API位于coffee-script.coffee中.它导出的compile功能可以实现它在锡上所说的功能.
要run直接使用command.coffee的函数,首先process.argv必须使用在命令行上传递的选项进行覆盖.
只需使用node的fsAPI + coffeescript.compile:
fs = require 'fs'
coffee = require 'coffee-script'
fs.readFile 'source.coffee', 'utf8', (err, data) ->
compiled = coffee.compile data
fs.writeFile 'source.js', compiled, (err) ->
console.log "Done."
Run Code Online (Sandbox Code Playgroud)
另请查看coffeescript自己的Cakefile(使用子进程):https://github.com/jashkenas/coffee-script/blob/master/Cakefile