Skip to content

Commit ca7e825

Browse files
ggPetiloklaan
authored andcommitted
Support variable replacement in directory names (yoshuawuyts#11)
1 parent 82dd27a commit ca7e825

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function writeFile (outDir, vars, file) {
6060
const parentDir = file.parentDir
6161
const outFile = path.join(outDir, maxstache(removeUnderscore(fileName), vars))
6262

63-
mkdirp(path.join(outDir, parentDir), function (err) {
63+
mkdirp(path.join(outDir, maxstache(parentDir, vars)), function (err) {
6464
if (err) return done(err)
6565

6666
const rs = fs.createReadStream(inFile)

test/fixtures/{{foo}}/5.txt

Whitespace-only changes.

test/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('should write a bunch of files', function (t) {
3535
copy(inDir, outDir, function (err, createdFiles) {
3636
t.error(err)
3737
t.ok(Array.isArray(createdFiles), 'createdFiles is an array')
38-
t.equal(createdFiles.length, 9)
38+
t.equal(createdFiles.length, 10)
3939
checkCreatedFileNames(createdFiles.map(function (filePath) {
4040
return path.relative(outDir, filePath)
4141
}), 'reported as created')
@@ -101,3 +101,26 @@ test('should inject context variables strings into filenames', function (t) {
101101
}))
102102
})
103103
})
104+
105+
test('should inject context variables strings into directory names', function (t) {
106+
t.plan(4)
107+
108+
const inDir = path.join(__dirname, 'fixtures')
109+
const outDir = path.join(__dirname, '../tmp')
110+
copy(inDir, outDir, { foo: 'bar' }, function (err) {
111+
t.error(err)
112+
113+
readdirp({ root: outDir }).pipe(concat({ object: true }, function (arr) {
114+
t.ok(Array.isArray(arr), 'is array')
115+
116+
const dir = path.join(outDir, 'bar')
117+
fs.access(dir, function (err, chunk) {
118+
t.error(err, 'bar directory exists')
119+
120+
rimraf(outDir, function (err) {
121+
t.error(err)
122+
})
123+
})
124+
}))
125+
})
126+
})

0 commit comments

Comments
 (0)