CLI: Run index.coffee when called on a directory

This commit is contained in:
Marc Häfner
2013-12-24 01:53:27 +01:00
parent 308299fe04
commit 8a3ebb9181
2 changed files with 39 additions and 1 deletions

View File

@@ -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.