2015-04-13 12:52:02 -04:00
|
|
|
/// <reference path="../typings/node/node.d.ts" />
|
|
|
|
/// <reference path="../typings/fs-extra/fs-extra.d.ts" />
|
|
|
|
|
2015-04-24 14:00:15 -04:00
|
|
|
import fs = require('fs');
|
2015-04-13 12:52:02 -04:00
|
|
|
import fse = require('fs-extra');
|
|
|
|
import path = require('path');
|
2015-05-04 11:19:25 -04:00
|
|
|
import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin';
|
2015-04-13 12:52:02 -04: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 11:19:25 -04:00
|
|
|
class DestCopy implements DiffingBroccoliPlugin {
|
2016-01-22 13:51:16 -05:00
|
|
|
constructor(private inputPath: string, private cachePath: string, private outputRoot: string) {}
|
2015-04-13 12:52:02 -04:00
|
|
|
|
|
|
|
|
2015-05-04 11:19:25 -04:00
|
|
|
rebuild(treeDiff: DiffResult) {
|
2016-04-12 12:40:37 -04:00
|
|
|
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
|
|
|
.forEach((changedFilePath) => {
|
|
|
|
var destFilePath = path.join(this.outputRoot, changedFilePath);
|
|
|
|
|
|
|
|
var destDirPath = path.dirname(destFilePath);
|
|
|
|
fse.mkdirsSync(destDirPath);
|
|
|
|
fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath);
|
|
|
|
});
|
2015-04-24 14:00:15 -04:00
|
|
|
|
2015-05-04 11:19:25 -04:00
|
|
|
treeDiff.removedPaths.forEach((removedFilePath) => {
|
2015-04-24 14:00:15 -04: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 12:52:02 -04:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 11:19:25 -04:00
|
|
|
|
|
|
|
export default wrapDiffingPlugin(DestCopy);
|