@@ -17,32 +17,33 @@ class DiffingReplace implements DiffingBroccoliPlugin {
1717 var patterns = this . options . patterns ;
1818 var files = this . options . files ;
1919
20- treeDiff . changedPaths . forEach ( ( changedFilePath ) => {
21- var sourceFilePath = path . join ( this . inputPath , changedFilePath ) ;
22- var destFilePath = path . join ( this . cachePath , changedFilePath ) ;
23- var destDirPath = path . dirname ( destFilePath ) ;
24-
25- if ( ! fs . existsSync ( destDirPath ) ) {
26- fse . mkdirpSync ( destDirPath ) ;
27- }
28-
29- var fileMatches = files . some ( ( filePath ) => minimatch ( changedFilePath , filePath ) ) ;
30- if ( fileMatches ) {
31- var content = fs . readFileSync ( sourceFilePath , FILE_ENCODING ) ;
32- patterns . forEach ( ( pattern ) => {
33- var replacement = pattern . replacement ;
34- if ( typeof replacement === 'function' ) {
35- replacement = function ( content ) {
36- return pattern . replacement ( content , changedFilePath ) ;
37- } ;
20+ treeDiff . addedPaths . concat ( treeDiff . changedPaths )
21+ . forEach ( ( changedFilePath ) => {
22+ var sourceFilePath = path . join ( this . inputPath , changedFilePath ) ;
23+ var destFilePath = path . join ( this . cachePath , changedFilePath ) ;
24+ var destDirPath = path . dirname ( destFilePath ) ;
25+
26+ if ( ! fs . existsSync ( destDirPath ) ) {
27+ fse . mkdirpSync ( destDirPath ) ;
28+ }
29+
30+ var fileMatches = files . some ( ( filePath ) => minimatch ( changedFilePath , filePath ) ) ;
31+ if ( fileMatches ) {
32+ var content = fs . readFileSync ( sourceFilePath , FILE_ENCODING ) ;
33+ patterns . forEach ( ( pattern ) => {
34+ var replacement = pattern . replacement ;
35+ if ( typeof replacement === 'function' ) {
36+ replacement = function ( content ) {
37+ return pattern . replacement ( content , changedFilePath ) ;
38+ } ;
39+ }
40+ content = content . replace ( pattern . match , replacement ) ;
41+ } ) ;
42+ fs . writeFileSync ( destFilePath , content , FILE_ENCODING ) ;
43+ } else if ( ! fs . existsSync ( destFilePath ) ) {
44+ fs . symlinkSync ( sourceFilePath , destFilePath ) ;
3845 }
39- content = content . replace ( pattern . match , replacement ) ;
4046 } ) ;
41- fs . writeFileSync ( destFilePath , content , FILE_ENCODING ) ;
42- } else if ( ! fs . existsSync ( destFilePath ) ) {
43- fs . symlinkSync ( sourceFilePath , destFilePath ) ;
44- }
45- } ) ;
4647
4748 treeDiff . removedPaths . forEach ( ( removedFilePath ) => {
4849 var destFilePath = path . join ( this . cachePath , removedFilePath ) ;
0 commit comments