mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
made the path handling a little more robust
This commit is contained in:
parent
f5a37035cf
commit
b0ecb39e9f
4 changed files with 20 additions and 6 deletions
|
@ -1,11 +1,15 @@
|
||||||
(function(){
|
(function(){
|
||||||
var sys;
|
var compiler, path, sys;
|
||||||
// Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
|
// Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
|
||||||
sys = require('sys');
|
sys = require('sys');
|
||||||
|
path = require('path');
|
||||||
|
// The path to the CoffeeScript executable.
|
||||||
|
compiler = path.normalize(path.dirname(__filename) + '/../../bin/coffee');
|
||||||
|
// Compile a string over stdin, with global variables, for the REPL.
|
||||||
exports.compile = function compile(code, callback) {
|
exports.compile = function compile(code, callback) {
|
||||||
var coffee, js;
|
var coffee, js;
|
||||||
js = '';
|
js = '';
|
||||||
coffee = process.createChildProcess('coffee', ['--eval', '--no-wrap', '--globals']);
|
coffee = process.createChildProcess(compiler, ['--eval', '--no-wrap', '--globals']);
|
||||||
coffee.addListener('output', function(results) {
|
coffee.addListener('output', function(results) {
|
||||||
if ((typeof results !== "undefined" && results !== null)) {
|
if ((typeof results !== "undefined" && results !== null)) {
|
||||||
return js += results;
|
return js += results;
|
||||||
|
@ -17,10 +21,11 @@
|
||||||
coffee.write(code);
|
coffee.write(code);
|
||||||
return coffee.close();
|
return coffee.close();
|
||||||
};
|
};
|
||||||
|
// Compile a list of CoffeeScript files on disk.
|
||||||
exports.compile_files = function compile_files(paths, callback) {
|
exports.compile_files = function compile_files(paths, callback) {
|
||||||
var coffee, js;
|
var coffee, js;
|
||||||
js = '';
|
js = '';
|
||||||
coffee = process.createChildProcess('coffee', ['--print'].concat(paths));
|
coffee = process.createChildProcess(compiler, ['--print'].concat(paths));
|
||||||
coffee.addListener('output', function(results) {
|
coffee.addListener('output', function(results) {
|
||||||
if ((typeof results !== "undefined" && results !== null)) {
|
if ((typeof results !== "undefined" && results !== null)) {
|
||||||
return js += results;
|
return js += results;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(function(){
|
(function(){
|
||||||
var coffee, paths;
|
var coffee, paths;
|
||||||
|
// Quickie script to compile and run all the files given as arguments.
|
||||||
coffee = require('./coffee-script');
|
coffee = require('./coffee-script');
|
||||||
process.mixin(require('sys'));
|
process.mixin(require('sys'));
|
||||||
paths = process.ARGV;
|
paths = process.ARGV;
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
# Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
|
# Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
|
||||||
|
|
||||||
sys: require('sys')
|
sys: require('sys')
|
||||||
|
path: require('path')
|
||||||
|
|
||||||
|
# The path to the CoffeeScript executable.
|
||||||
|
compiler: path.normalize(path.dirname(__filename) + '/../../bin/coffee')
|
||||||
|
|
||||||
|
# Compile a string over stdin, with global variables, for the REPL.
|
||||||
exports.compile: (code, callback) ->
|
exports.compile: (code, callback) ->
|
||||||
js: ''
|
js: ''
|
||||||
coffee: process.createChildProcess 'coffee', ['--eval', '--no-wrap', '--globals']
|
coffee: process.createChildProcess compiler, ['--eval', '--no-wrap', '--globals']
|
||||||
coffee.addListener 'output', (results) ->
|
coffee.addListener 'output', (results) ->
|
||||||
js += results if results?
|
js += results if results?
|
||||||
coffee.addListener 'exit', ->
|
coffee.addListener 'exit', ->
|
||||||
|
@ -12,9 +17,10 @@ exports.compile: (code, callback) ->
|
||||||
coffee.write(code)
|
coffee.write(code)
|
||||||
coffee.close()
|
coffee.close()
|
||||||
|
|
||||||
|
# Compile a list of CoffeeScript files on disk.
|
||||||
exports.compile_files: (paths, callback) ->
|
exports.compile_files: (paths, callback) ->
|
||||||
js: ''
|
js: ''
|
||||||
coffee: process.createChildProcess 'coffee', ['--print'].concat(paths)
|
coffee: process.createChildProcess compiler, ['--print'].concat(paths)
|
||||||
coffee.addListener 'output', (results) ->
|
coffee.addListener 'output', (results) ->
|
||||||
js += results if results?
|
js += results if results?
|
||||||
coffee.addListener 'exit', ->
|
coffee.addListener 'exit', ->
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Quickie script to compile and run all the files given as arguments.
|
||||||
|
|
||||||
coffee: require './coffee-script'
|
coffee: require './coffee-script'
|
||||||
process.mixin require 'sys'
|
process.mixin require 'sys'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue