-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement smart-directory resolution rules:
1. If a script name expands to a directory, then: 1. If there's an /index file, match all the (/index*) 2. If there's no /index, match all immediate descendents (/*) 2. If the script name expands to a file, match all extensions (*) I knew this method would get bigger! This will require we remove ambiguity warnings and embrace the possibility globs will match multiple scripts. (sorry folks,using the sync stat methods b/c callback hell is getting to me)
- Loading branch information
Showing
10 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
var path = require('path') | ||
var fs = require('fs') | ||
|
||
module.exports = function (dir1, dir2) { | ||
return path.resolve(dir1, dir2.replace(/\:/g, '/')) + '*' | ||
var expanded = path.resolve(dir1, dir2.replace(/\:/g, '/')) | ||
if (isDir(expanded)) { | ||
if (containsIndexFile(expanded)) { | ||
return expanded + '/index*' | ||
} else { | ||
return expanded + '/*' | ||
} | ||
} else { | ||
return expanded + '*' | ||
} | ||
} | ||
|
||
function isDir (f) { | ||
try { | ||
return fs.statSync(f).isDirectory() | ||
} catch (e) {} | ||
} | ||
|
||
function containsIndexFile (f) { | ||
try { | ||
return fs.statSync(f + '/index').isFile() | ||
} catch (e) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
module.exports = function () { | ||
var subject = require('./generate-glob') | ||
var path = require('path') | ||
|
||
assert.equal('/foo/bar*', subject('/foo', 'bar')) | ||
assert.equal('/foo/bar/baz*', subject('/foo', 'bar:baz')) | ||
module.exports = { | ||
beforeEach: function () { | ||
this.subject = require('./generate-glob') | ||
this.root = path.resolve('test/fixtures/user-scripts') | ||
}, | ||
fileInADir: function () { | ||
assert.equal(this.root + '/foo/bar*', this.subject(this.root, 'foo:bar')) | ||
}, | ||
nonExistentFile: function () { | ||
assert.equal(this.root + '/fake/stuff*', this.subject(this.root, 'fake:stuff')) | ||
}, | ||
dirWithNoIndex: function () { | ||
assert.equal(this.root + '/baz/*', this.subject(this.root, 'baz')) | ||
}, | ||
dirWithAnIndexFile: function () { | ||
assert.equal(this.root + '/car/index*', this.subject(this.root, 'car')) | ||
}, | ||
dirWithADirNamedIndex: function () { | ||
assert.equal(this.root + '/dog/*', this.subject(this.root, 'dog')) | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
|
||
puts 'rubby' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var runScripty = require('../run-scripty') | ||
|
||
module.exports = { | ||
runsIndexWhenDirIsFound: function (done) { | ||
runScripty('top', {}, function (er, code, stdio) { | ||
assert.equal(code, 0) | ||
assert.includes(stdio.stdout, 'rubby') | ||
done(er) | ||
}) | ||
} | ||
} |