build/lib/compilation.ts/compileTask
export function compileTask(src: string, out: string, build: boolean): () => NodeJS.ReadWriteStream {

	return function () {

		if (os.totalmem() < 4_000_000_000) {
			throw new Error('compilation requires 4GB of RAM');
		}

		const compile = createCompile(src, build, true, false);
		const srcPipe = gulp.src(`${src}/**`, { base: `${src}` });
		const generator = new MonacoGenerator(false);
		if (src === 'src') {
			generator.execute();
		}

		// mangle: TypeScript to TypeScript
		let mangleStream = es.through();
		if (build) {
			let ts2tsMangler = new Mangler(compile.projectPath);
			const newContentsByFileName = ts2tsMangler.computeNewFileContents();
			mangleStream = es.through(function write(data: File) {
				const newContents = newContentsByFileName.get(data.path);
				if (newContents !== undefined) {
					data.contents = Buffer.from(newContents);
				}
				this.push(data);
			}, function end() {
				this.push(null);
				// free resources
				newContentsByFileName.clear();
				(<any>ts2tsMangler) = undefined;
			});
		}

		return srcPipe
			.pipe(mangleStream)
			.pipe(generator.stream)
			.pipe(compile())
			.pipe(gulp.dest(out));
	};
}