Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 2ecff4e

Browse files
committed
correctly generate dest path if only a directory is passed
1 parent 7b8abb5 commit 2ecff4e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ module.exports = function (files, options) {
3939

4040
html = new HTMLProcessor(options);
4141

42-
files.src.forEach(function (filepath) {
43-
var content = html.process(filepath);
44-
var dest = getOutputPath(filepath);
42+
files.src.forEach(function (filePath) {
43+
var content = html.process(filePath);
44+
var dest = getOutputPath(filePath);
4545

4646
fs.writeFileSync(dest, content);
4747
console.log('File', '"' + dest + '"', 'created.');
@@ -51,17 +51,24 @@ module.exports = function (files, options) {
5151
}
5252
});
5353

54-
function getOutputPath(filepath) {
54+
function getOutputPath(filePath) {
5555
var dest = files.dest;
5656
var ext;
5757

5858
if (!dest) {
59-
ext = path.extname(filepath);
60-
dest = path.basename(filepath, ext) + '.processed' + ext;
59+
dest = getFileName(filePath, 'processed');
6160
} else if (!path.extname(dest)) {
62-
dest = path.join(dest, filepath);
61+
dest = path.join(dest, getFileName(filePath));
6362
}
6463

6564
return dest;
6665
}
66+
67+
function getFileName(filePath, postfix) {
68+
var ext = path.extname(filePath);
69+
return path.basename(filePath, ext) + (postfix || '') + ext;
70+
}
71+
72+
// return processor instance
73+
return html;
6774
};

0 commit comments

Comments
 (0)