Skip to content

Commit 1f301d8

Browse files
Merge pull request #3292 from marchaefner/CLI
`coffee DIR` executes `DIR/index.coffee`
2 parents 35f1854 + 8a3ebb9 commit 1f301d8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/coffee-script/command.js

+26-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command.coffee

+13
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ compilePath = (source, topLevel, base) ->
104104
if path.basename(source) is 'node_modules'
105105
notSources[source] = yes
106106
return
107+
if opts.run
108+
compilePath findDirectoryIndex(source), topLevel, base
109+
return
107110
watchDir source, base if opts.watch
108111
try
109112
files = fs.readdirSync source
@@ -124,6 +127,16 @@ compilePath = (source, topLevel, base) ->
124127
else
125128
notSources[source] = yes
126129

130+
findDirectoryIndex = (source) ->
131+
for ext in CoffeeScript.FILE_EXTENSIONS
132+
index = path.join source, "index#{ext}"
133+
try
134+
return index if (fs.statSync index).isFile()
135+
catch err
136+
throw err unless err.code is 'ENOENT'
137+
console.error "Missing index.coffee or index.litcoffee in #{source}"
138+
process.exit 1
139+
127140
# Compile a single source script, containing the given code, according to the
128141
# requested options. If evaluating the script directly sets `__filename`,
129142
# `__dirname` and `module.filename` to be correct relative to the script's path.

0 commit comments

Comments
 (0)