This commit is contained in:
Joao Moreno
2017-01-11 11:55:52 +01:00
parent 3437c46349
commit 1c38df7823
15 changed files with 121 additions and 115 deletions

View File

@@ -28,14 +28,17 @@ options.sourceMap = true;
options.rootDir = rootDir;
options.sourceRoot = util.toFileUri(rootDir);
function createCompile(build:boolean, emitError?:boolean): (token?:util.ICancellationToken) => NodeJS.ReadWriteStream {
const smSourceRootPath = path.resolve(path.dirname(rootDir));
const smSourceRoot = util.toFileUri(smSourceRootPath);
function createCompile(build: boolean, emitError?: boolean): (token?: util.ICancellationToken) => NodeJS.ReadWriteStream {
const opts = _.clone(options);
opts.inlineSources = !!build;
opts.noFilesystemLookup = true;
const ts = tsb.create(opts, null, null, err => reporter(err.toString()));
return function (token?:util.ICancellationToken) {
return function (token?: util.ICancellationToken) {
const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
const tsFilter = util.filter(data => /\.ts$/.test(data.path));
const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));
@@ -54,7 +57,7 @@ function createCompile(build:boolean, emitError?:boolean): (token?:util.ICancell
.pipe(sourcemaps.write('.', {
addComment: false,
includeContent: !!build,
sourceRoot: options.sourceRoot
sourceRoot: smSourceRoot
}))
.pipe(tsFilter.restore)
.pipe(reporter.end(emitError));
@@ -63,7 +66,7 @@ function createCompile(build:boolean, emitError?:boolean): (token?:util.ICancell
};
}
export function compileTask(out:string, build:boolean): () => NodeJS.ReadWriteStream {
export function compileTask(out: string, build: boolean): () => NodeJS.ReadWriteStream {
const compile = createCompile(build, true);
return function () {
@@ -79,7 +82,7 @@ export function compileTask(out:string, build:boolean): () => NodeJS.ReadWriteSt
};
}
export function watchTask(out:string, build:boolean): () => NodeJS.ReadWriteStream {
export function watchTask(out: string, build: boolean): () => NodeJS.ReadWriteStream {
const compile = createCompile(build);
return function () {
@@ -96,21 +99,21 @@ export function watchTask(out:string, build:boolean): () => NodeJS.ReadWriteStre
};
}
function monacodtsTask(out:string, isWatch:boolean): NodeJS.ReadWriteStream {
let timer:NodeJS.Timer = null;
function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream {
let timer: NodeJS.Timer = null;
const runSoon = function(howSoon:number) {
const runSoon = function (howSoon: number) {
if (timer !== null) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function() {
timer = setTimeout(function () {
timer = null;
runNow();
}, howSoon);
};
const runNow = function() {
const runNow = function () {
if (timer !== null) {
clearTimeout(timer);
timer = null;
@@ -133,16 +136,16 @@ function monacodtsTask(out:string, isWatch:boolean): NodeJS.ReadWriteStream {
if (isWatch) {
const filesToWatchMap: {[file:string]:boolean;} = {};
monacodts.getFilesToWatch(out).forEach(function(filePath) {
const filesToWatchMap: { [file: string]: boolean; } = {};
monacodts.getFilesToWatch(out).forEach(function (filePath) {
filesToWatchMap[path.normalize(filePath)] = true;
});
watch('build/monaco/*').pipe(es.through(function() {
watch('build/monaco/*').pipe(es.through(function () {
runSoon(5000);
}));
resultStream = es.through(function(data) {
resultStream = es.through(function (data) {
const filePath = path.normalize(data.path);
if (filesToWatchMap[filePath]) {
runSoon(5000);
@@ -152,7 +155,7 @@ function monacodtsTask(out:string, isWatch:boolean): NodeJS.ReadWriteStream {
} else {
resultStream = es.through(null, function() {
resultStream = es.through(null, function () {
runNow();
this.emit('end');
});