Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoffeeScript support #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions bin/spark
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ var verbose;

var useColors = true;

/**
* CoffeeScript support.
*/

var enableCoffee = false;

/**
* Environment defaults.
*/
Expand Down Expand Up @@ -82,6 +88,7 @@ var usage = ''
+ ' -c, --config PATH Load configuration module\n'
+ ' -u, --user ID|NAME Change user with setuid()\n'
+ ' -g, --group ID|NAME Change group with setgid()\n'
+ ' --coffee Enable CoffeeScript support\n'
+ ' -v, --verbose Enable verbose output\n'
+ ' -V, --version Output spark version\n'
+ ' -K, --no-color Suppress colored terminal output\n'
Expand Down Expand Up @@ -150,14 +157,25 @@ function mkdirs(path, mode) {
}

/**
* Strip ".js" extension from the given path.
* Append target extension to the given path.
*
* @param {String} path
* @return {String}
*/

function appendExtension(path) {
return path + (enableCoffee ? '.coffee' : '.js');
}

/**
* Strip target extension from the given path.
*
* @param {String} path
* @return {String}
*/

function modulePath(path){
return path.replace(/\.js$/, '');
return path.replace(new RegExp(appendExtension('').replace('.', '\\.') + '$'), '');
}

/**
Expand Down Expand Up @@ -247,14 +265,14 @@ function getAppPath() {

// App path not given, try app.js and server.js
if (!env.appPath) {
if (exists(path + 'app.js')) {
log('detected app.js');
if (exists(path + appendExtension('app'))) {
log('detected ' + appendExtension('app'));
path += 'app';
} else if (exists(path + 'server.js')) {
log('detected server.js');
} else if (exists(path + appendExtension('server'))) {
log('detected ' + appendExtension('server'));
path += 'server';
} else {
abort('app not found, pass a module path, or create {app,server}.js');
abort('app not found, pass a module path, or create ' + appendExtension('{app,server}'));
}
}

Expand Down Expand Up @@ -318,9 +336,9 @@ function start() {
log('starting');

// Detect config.js
if (exists('./config.js')) {
log('detected config.js');
loadConfig('./config.js');
if (exists(appendExtension('./config'))) {
log('detected ' + appendExtension('config'));
loadConfig(appendExtension('./config'));
}

// Application path
Expand Down Expand Up @@ -349,6 +367,10 @@ function start() {
if (comment) {
args.push('--comment', comment);
}

if (enableCoffee) {
args.push('--coffee');
}

// Spawn the child process
var child = children[i] = child_process.spawn(
Expand Down Expand Up @@ -497,6 +519,10 @@ function parseArguments(args, cmd) {
case '--ssl-crt':
env.sslCrt = fs.readFileSync(requireArg('--ssl-crt'), 'ascii');
break;
case '--coffee':
enableCoffee = true;
require('coffee-script');
break;
default:
if (arg[0] === '-') {
arg = arg.substr(2);
Expand Down