2015-12-08 10:56:02 -06:00
|
|
|
module.exports = function(config, grunt) {
|
2015-10-01 10:00:41 -05:00
|
|
|
'use strict';
|
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
var gaze = require('gaze');
|
|
|
|
var path = require('path');
|
|
|
|
var firstRun = true;
|
|
|
|
var done;
|
|
|
|
var lastTime;
|
2015-12-08 10:56:02 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
grunt.registerTask('watch', function() {
|
2015-12-08 10:56:02 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
done = this.async();
|
|
|
|
lastTime = new Date().getTime();
|
|
|
|
|
|
|
|
if (firstRun === false) {
|
|
|
|
grunt.log.writeln('Watch resuming');
|
|
|
|
return;
|
2015-12-08 10:56:02 -06:00
|
|
|
}
|
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
gaze(config.srcDir + '/**/*', function(err, watcher) {
|
2015-12-08 10:56:02 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
console.log('Gaze watchers setup');
|
2015-09-09 12:34:24 -05:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
watcher.on('all', function(evtName, filepath) {
|
|
|
|
filepath = path.relative(process.cwd(), filepath);
|
2015-12-08 10:56:02 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
// ignore multiple changes at once
|
|
|
|
var now = new Date().getTime();
|
|
|
|
if (now - lastTime < 100) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastTime = now;
|
2016-01-13 15:31:29 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
var newPath;
|
|
|
|
grunt.log.writeln('File Changed: ', filepath);
|
2016-11-02 15:45:46 -05:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
if (/(\.html)|(\.json)$/.test(filepath)) {
|
|
|
|
newPath = filepath.replace(/^public/, 'public_gen');
|
|
|
|
grunt.log.writeln('Copying to ' + newPath);
|
|
|
|
grunt.file.copy(filepath, newPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/(\.js)$/.test(filepath)) {
|
|
|
|
newPath = filepath.replace(/^public/, 'public_gen');
|
|
|
|
grunt.log.writeln('Copying to ' + newPath);
|
|
|
|
grunt.file.copy(filepath, newPath);
|
2015-12-08 10:56:02 -06:00
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
grunt.task.run('jshint');
|
|
|
|
grunt.task.run('jscs');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/(\.scss)$/.test(filepath)) {
|
|
|
|
grunt.task.run('clean:css');
|
|
|
|
grunt.task.run('css');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/(\.ts)$/.test(filepath)) {
|
|
|
|
newPath = filepath.replace(/^public/, 'public_gen');
|
|
|
|
grunt.log.writeln('Copying to ' + newPath);
|
|
|
|
grunt.file.copy(filepath, newPath);
|
|
|
|
|
|
|
|
// copy ts file also used by source maps
|
|
|
|
//changes changed file source to that of the changed file
|
|
|
|
grunt.config('typescript.build.src', filepath);
|
|
|
|
grunt.config('tslint.source.files.src', filepath);
|
|
|
|
|
2016-12-10 03:00:58 -06:00
|
|
|
grunt.task.run('exec:tscompile');
|
2016-12-09 15:53:00 -06:00
|
|
|
grunt.task.run('exec:tslint');
|
2016-11-04 05:43:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
firstRun = false;
|
|
|
|
grunt.task.run('watch');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-08-10 07:03:10 -05:00
|
|
|
};
|