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

load from folder #52

Merged
merged 5 commits into from
Aug 17, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ $

### .load <file> [delay]

Load a local or remote Javascript file line by line in to the REPL. A `delay` between each line of code's execution can be specified in milliseconds.
Load a local or remote Javascript file line by line in to the REPL. A `delay` between each line of code's execution can be specified in milliseconds. If `<file>` is a directory, triple will attempt to load `app.js` then `index.js` from the directory.

```bash
$ triple
Expand Down
14 changes: 13 additions & 1 deletion lib/triple.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,19 @@ function load(tokens, rl) {
// probably a file
} else {
if (fs.existsSync(location)) {
return sendLoadCommand(rl, location, fs.readFileSync(location).toString(), delay);

// if it's a folder
if (fs.lstatSync(location).isDirectory()) {

// try app.js and/or index.js
var tries = ['app.js', 'index.js'];
for (var i = 0; i < tries.length; i++) {
var file = path.join(location, tries[i]);
if (fs.existsSync(file)) {
return sendLoadCommand(rl, file, fs.readFileSync(file, 'utf8'), delay);
}
}
}
}
}

Expand Down