Skip to content

Commit 21bab2e

Browse files
James KolceTimothyGu
authored andcommitted
Omit files or directories with underscore on it (#44)
1 parent fb9a693 commit 21bab2e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ function stdin() {
242242
*/
243243

244244
function renderFile(path, rootPath) {
245-
var re = /\.(?:pug|jade)$/;
245+
var isPug = /\.(?:pug|jade)$/;
246+
var isIgnored = /([\/\\]_)|(^_)/;
247+
246248
var stat = fs.lstatSync(path);
247249
// Found pug file
248-
if (stat.isFile() && re.test(path)) {
250+
if (stat.isFile() && isPug.test(path) && !isIgnored.test(path)) {
249251
// Try to watch the file if needed. watchFile takes care of duplicates.
250252
if (program.watch) watchFile(path, null, rootPath);
251253
if (program.nameAfterFile) {
@@ -269,7 +271,7 @@ function renderFile(path, rootPath) {
269271
else extname = '.html';
270272

271273
// path: foo.pug -> foo.<ext>
272-
path = path.replace(re, extname);
274+
path = path.replace(isPug, extname);
273275
if (program.out) {
274276
// prepend output directory
275277
if (rootPath) {

test/index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function timing(testCase) {
103103
* Make temporary directories
104104
*/
105105
rimraf.sync(t([]));
106+
mkdirp.sync(t(['_omittedDir']));
106107
mkdirp.sync(t(['depwatch']));
107108
mkdirp.sync(t(['inputs', 'level-1-1']));
108109
mkdirp.sync(t(['inputs', 'level-1-2']));
@@ -135,6 +136,28 @@ describe('miscellanea', function () {
135136
});
136137
});
137138
});
139+
it('Omits files starting with an underscore', function (done) {
140+
w('_omitted.pug', '.foo bar');
141+
w('_omitted.html', '<p>output not written</p>');
142+
143+
run(['_omitted.pug'], function (err) {
144+
if (err) return done(err);
145+
var html = r('_omitted.html');
146+
assert(html === '<p>output not written</p>');
147+
done();
148+
});
149+
});
150+
it('Omits directories starting with an underscore', function (done) {
151+
w('_omittedDir/file.pug', '.foo bar');
152+
w('_omittedDir/file.html', '<p>output not written</p>');
153+
154+
run(['--no-debug', '_omittedDir/file.pug'], function (err, stdout) {
155+
if (err) return done(err);
156+
var html = r('_omittedDir/file.html');
157+
assert.equal(html, '<p>output not written</p>');
158+
done();
159+
});
160+
});
138161
});
139162

140163
describe('HTML output', function () {
@@ -335,12 +358,12 @@ describe('client JavaScript output', function () {
335358
return done();
336359
});
337360
});
338-
it('--name-after-file _InPuTwIthWEiRdNaMME.pug', function (done) {
339-
w('_InPuTwIthWEiRdNaMME.pug', '.foo bar');
340-
w('_InPuTwIthWEiRdNaMME.js', 'throw new Error("output not written");');
341-
run(['--no-debug', '--client', '--name-after-file', '_InPuTwIthWEiRdNaMME.pug'], function (err, stdout, stderr) {
361+
it('--name-after-file ·InPuTwIthWEiRdNaMME.pug', function (done) {
362+
w('·InPuTwIthWEiRdNaMME.pug', '.foo bar');
363+
w('·InPuTwIthWEiRdNaMME.js', 'throw new Error("output not written");');
364+
run(['--no-debug', '--client', '--name-after-file', '·InPuTwIthWEiRdNaMME.pug'], function (err, stdout, stderr) {
342365
if (err) return done(err);
343-
var template = Function('', r('_InPuTwIthWEiRdNaMME.js') + ';return InputwithweirdnammeTemplate;')();
366+
var template = Function('', r('·InPuTwIthWEiRdNaMME.js') + ';return InputwithweirdnammeTemplate;')();
344367
assert(template() === '<div class="foo">bar</div>');
345368
return done();
346369
});

0 commit comments

Comments
 (0)