build(broccoli): add support for DiffResult#addedPaths

Some plugins want to explicitly know of new paths, so we need to distinguish them from changed paths.
This commit is contained in:
Igor Minar
2015-05-31 17:24:21 -07:00
parent efab03274f
commit dc45559c17
13 changed files with 204 additions and 106 deletions

View File

@ -17,32 +17,33 @@ class DiffingReplace implements DiffingBroccoliPlugin {
var patterns = this.options.patterns;
var files = this.options.files;
treeDiff.changedPaths.forEach((changedFilePath) => {
var sourceFilePath = path.join(this.inputPath, changedFilePath);
var destFilePath = path.join(this.cachePath, changedFilePath);
var destDirPath = path.dirname(destFilePath);
treeDiff.addedPaths.concat(treeDiff.changedPaths)
.forEach((changedFilePath) => {
var sourceFilePath = path.join(this.inputPath, changedFilePath);
var destFilePath = path.join(this.cachePath, changedFilePath);
var destDirPath = path.dirname(destFilePath);
if (!fs.existsSync(destDirPath)) {
fse.mkdirpSync(destDirPath);
}
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
if (fileMatches) {
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
patterns.forEach((pattern) => {
var replacement = pattern.replacement;
if (typeof replacement === 'function') {
replacement = function(content) {
return pattern.replacement(content, changedFilePath);
};
if (!fs.existsSync(destDirPath)) {
fse.mkdirpSync(destDirPath);
}
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
if (fileMatches) {
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
patterns.forEach((pattern) => {
var replacement = pattern.replacement;
if (typeof replacement === 'function') {
replacement = function(content) {
return pattern.replacement(content, changedFilePath);
};
}
content = content.replace(pattern.match, replacement);
});
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
} else if (!fs.existsSync(destFilePath)) {
fs.symlinkSync(sourceFilePath, destFilePath);
}
content = content.replace(pattern.match, replacement);
});
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
} else if (!fs.existsSync(destFilePath)) {
fs.symlinkSync(sourceFilePath, destFilePath);
}
});
treeDiff.removedPaths.forEach((removedFilePath) => {
var destFilePath = path.join(this.cachePath, removedFilePath);