| 
									
										
										
										
											2015-04-13 09:52:02 -07:00
										 |  |  | /// <reference path="../typings/node/node.d.ts" />
 | 
					
						
							|  |  |  | /// <reference path="../typings/fs-extra/fs-extra.d.ts" />
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-24 11:00:15 -07:00
										 |  |  | import fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2015-04-13 09:52:02 -07:00
										 |  |  | import fse = require('fs-extra'); | 
					
						
							|  |  |  | import path = require('path'); | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  | import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin'; | 
					
						
							| 
									
										
										
										
											2015-04-13 09:52:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Intercepts each file as it is copied to the destination tempdir, | 
					
						
							|  |  |  |  * and tees a copy to the given path outside the tmp dir. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  | class DestCopy implements DiffingBroccoliPlugin { | 
					
						
							|  |  |  |   constructor(private inputPath, private cachePath, private outputRoot: string) {} | 
					
						
							| 
									
										
										
										
											2015-04-13 09:52:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  |   rebuild(treeDiff: DiffResult) { | 
					
						
							|  |  |  |     treeDiff.changedPaths.forEach((changedFilePath) => { | 
					
						
							| 
									
										
										
										
											2015-04-24 11:00:15 -07:00
										 |  |  |       var destFilePath = path.join(this.outputRoot, changedFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       var destDirPath = path.dirname(destFilePath); | 
					
						
							|  |  |  |       fse.mkdirsSync(destDirPath); | 
					
						
							|  |  |  |       fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  |     treeDiff.removedPaths.forEach((removedFilePath) => { | 
					
						
							| 
									
										
										
										
											2015-04-24 11:00:15 -07:00
										 |  |  |       var destFilePath = path.join(this.outputRoot, removedFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // TODO: what about obsolete directories? we are not cleaning those up yet
 | 
					
						
							|  |  |  |       fs.unlinkSync(destFilePath); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-04-13 09:52:02 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default wrapDiffingPlugin(DestCopy); |