Skip to content

Commit b98f1d0

Browse files
committed
handle nested paths
Quick fix to handle path like: `dir1/dir2/file.js`
1 parent 4eeffd0 commit b98f1d0

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ConfigReplace.prototype.processFile = function(config, filePath) {
9595

9696
ConfigReplace.prototype.writeFile = function(destPath, contents) {
9797
if (!fs.existsSync(path.dirname(destPath))) {
98-
fs.mkdirSync(path.dirname(destPath));
98+
fs.mkdirpSync(path.dirname(destPath));
9999
}
100100

101101
fs.writeFileSync(destPath, contents, { encoding: 'utf8' });

test/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,36 @@ describe('config-replace', function() {
159159
expect(newContent).to.not.equal(oldContent);
160160
});
161161
});
162+
163+
it('handle nested paths', function() {
164+
var root, configReplace, builder;
165+
166+
root = tmp.in(join(process.cwd(), 'tmp'));
167+
168+
fs.writeFileSync(join(root, 'config.json'), '{"color":"red"}');
169+
fs.mkdirSync(join(root, 'dir1'));
170+
fs.mkdirSync(join(root, 'dir1', 'dir2'));
171+
fs.writeFileSync(join(root, 'dir1', 'dir2', 'index.html'), "{{color}}");
172+
173+
configReplace = new ConfigReplace(
174+
root,
175+
root, {
176+
files: ['dir1/dir2/index.html'],
177+
configPath: 'config.json',
178+
patterns: [{
179+
match: /\{\{color\}\}/g,
180+
replacement: 'red'
181+
}]
182+
}
183+
);
184+
185+
builder = new broccoli.Builder(configReplace);
186+
187+
return builder.build().then(function(results) {
188+
var resultsPath = join(results.directory, 'dir1', 'dir2', 'index.html'),
189+
contents = fs.readFileSync(resultsPath, { encoding: 'utf8' });
190+
191+
assert.equal(contents.trim(), 'red');
192+
})
193+
});
162194
});

0 commit comments

Comments
 (0)