mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
CLI: Run index.coffee when called on a directory
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, hidden, joinTimeout, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs, _ref,
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs, _ref,
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
fs = require('fs');
|
||||
@@ -117,6 +117,10 @@
|
||||
notSources[source] = true;
|
||||
return;
|
||||
}
|
||||
if (opts.run) {
|
||||
compilePath(findDirectoryIndex(source), topLevel, base);
|
||||
return;
|
||||
}
|
||||
if (opts.watch) {
|
||||
watchDir(source, base);
|
||||
}
|
||||
@@ -159,6 +163,27 @@
|
||||
}
|
||||
};
|
||||
|
||||
findDirectoryIndex = function(source) {
|
||||
var err, ext, index, _i, _len, _ref1;
|
||||
_ref1 = CoffeeScript.FILE_EXTENSIONS;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
ext = _ref1[_i];
|
||||
index = path.join(source, "index" + ext);
|
||||
try {
|
||||
if ((fs.statSync(index)).isFile()) {
|
||||
return index;
|
||||
}
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.error("Missing index.coffee or index.litcoffee in " + source);
|
||||
return process.exit(1);
|
||||
};
|
||||
|
||||
compileScript = function(file, input, base) {
|
||||
var compiled, err, message, o, options, t, task;
|
||||
if (base == null) {
|
||||
|
||||
@@ -104,6 +104,9 @@ compilePath = (source, topLevel, base) ->
|
||||
if path.basename(source) is 'node_modules'
|
||||
notSources[source] = yes
|
||||
return
|
||||
if opts.run
|
||||
compilePath findDirectoryIndex(source), topLevel, base
|
||||
return
|
||||
watchDir source, base if opts.watch
|
||||
try
|
||||
files = fs.readdirSync source
|
||||
@@ -124,6 +127,16 @@ compilePath = (source, topLevel, base) ->
|
||||
else
|
||||
notSources[source] = yes
|
||||
|
||||
findDirectoryIndex = (source) ->
|
||||
for ext in CoffeeScript.FILE_EXTENSIONS
|
||||
index = path.join source, "index#{ext}"
|
||||
try
|
||||
return index if (fs.statSync index).isFile()
|
||||
catch err
|
||||
throw err unless err.code is 'ENOENT'
|
||||
console.error "Missing index.coffee or index.litcoffee in #{source}"
|
||||
process.exit 1
|
||||
|
||||
# Compile a single source script, containing the given code, according to the
|
||||
# requested options. If evaluating the script directly sets `__filename`,
|
||||
# `__dirname` and `module.filename` to be correct relative to the script's path.
|
||||
|
||||
Reference in New Issue
Block a user