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