Skip to content

Instantly share code, notes, and snippets.

@Serivy
Created October 4, 2017 07:39
Show Gist options
  • Save Serivy/c00c534fbc0cd853af0ec3a60ed4789b to your computer and use it in GitHub Desktop.
Save Serivy/c00c534fbc0cd853af0ec3a60ed4789b to your computer and use it in GitHub Desktop.
Quicker typescript watch.
// A experiment for quicker builds.
gulp.task('watch:typescript:quick', function () {
return gulp.watch(files.tsFiles).on("change", function(file) {
// Workaround to keep original folder structure
var currentDirectory = path.dirname(file.path);
var sourceDirectory = 'scripts';
var index = currentDirectory.indexOf(sourceDirectory);
var relativeDirectory = currentDirectory.slice(index + sourceDirectory.length + 1);
var outputDirectory = __dirname + "\\scripts\\output"
if (relativeDirectory) {
outputDirectory = outputDirectory + "\\" + relativeDirectory;
}
var cmd = '"' + __dirname + '\\node_modules\\.bin\\tsc.cmd" --target ES5 --module AMD --sourceMap true --noResolve --outDir "' + outputDirectory + '" "' + file.path + '"';
var startD = new Date();
console.log(startD.toTimeString().split(' ')[0] + ' - File change detected. Starting incremental compilation...');
exec(cmd, function (err, stdout, stderr) {
if (stderr) {
console.log("Command Failed: " + stderr);
} else {
var endD = new Date();
console.log(endD.toTimeString().split(' ')[0] + ' - Compilation complete. Watching for file changes.');
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment