Allow running external tasks in the watch loop
This would be really nice and shouldn't be hard to do with grunt.
At the point where people have other tasks people should perhaps learn and use grunt watch
At first I was thinking that we could just let grunt-contrib-watch do the work by splitting up the code-gen and compilation into separate tasks, but after looking into the code, I can see why you want to perform the watching from grunt-ts. You can optimize some long running tasks better.
So I think the other direction of enlisting a watch program from within grunt-ts might be the best solution. It's pretty easy to call another task from within a task, so I was thinking we could hold a sequence of task names in memory and call all of them during the main watch loop. We would have 3 queues that you can register tasks,
- beforeCodeGen
- beforeCompile
- onComplete
I don't think we will need to get more granular than that. What do you think?
I don't think we will need to get more granular than that
agreed :+1:
Has the enhancement been implemented that jeffmay suggested. I have need for such functionality. I would like to uglify after the compiling of all TypeScript files have completed. I attempted to do so using various combinations, but each failed, as uglify task never executes:
gruntfile.js
module.exports = function (grunt) { // load the task grunt.loadNpmTasks("grunt-ts");
// Configure grunt here
grunt.initConfig({
ts: {
// A specific target
dev: {
// The source TypeScript files, http://gruntjs.com/configuring-tasks#files
src: ["app/**/*.ts"],
// The source html files, https://github.com/grunt-ts/grunt-ts#html-2-typescript-support
//html: ["test/work/**/*.tpl.html"],
// If specified, generate this file that to can use for reference management
reference: "app/reference.ts",
// If specified, generate an out.js file which is the merged js file
out: 'app/app.cmb.js',
// If specified, the generate JavaScript files are placed here. Only works if out is not specified
//outDir: 'test/outputdirectory',
// If specified, watches this directory for changes, and re-runs the current target
watch:'app',
// Use to override the default options, http://gruntjs.com/configuring-tasks#options
options: {
// 'es3' (default) | 'es5'
//target: 'es3',
// 'amd' (default) | 'commonjs'
//module: 'commonjs',
// true (default) | false
sourceMap: true,
// true | false (default)
declaration: false,
// true (default) | false
removeComments: true
}
},
uglify: {
options: {
mangle: true,
compress: true,
banner: '/*! Copyright 2014 - Me ' +
'<%= grunt.template.today() %> */'
},
build: {
src: ['app/app.cmb.js'],
dest: 'app/app.cmb.min.js'
}
}
},
watch: {
files: "app/**/*.ts",
tasks:['ts:dev']
},
watchUglify: {
files: "app/**/*.ts",
tasks:['ts:uglify']
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Rename watch to watchUglify and load it again to attempt to run multiple tasks using watches
grunt.renameTask('watch', 'watchUglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
grunt.registerTask('dev', ['watchUglify']);
}
<< gruntfile.js
Please advise and/or provide an example solution towards this issue.
The problem I had was actually with grunt-ts-watch. It has a bug where you can run grunt watch to watch all tasks simultaniously or grunt watch:ts but you can't define a task that is grunt.registerTask('watch-ts', ['watch:ts', 'watch-html']). Watch is all or one or nothing. I needed to watch 2 things but not all.
In your case, I think you just need to run watch: { tasks: ['ts:dev', 'ts:uglify'] }
--- In your case, I think you just need to run watch: { tasks: ['ts:dev', 'ts:uglify'] }
tried that::

ts:dev runs fine, however, you will notice in the screenshot above, ts:uglify never executes.
That's strange. What happens if you do grunt.registerTask('buildUgly', ['ts:dev', 'ts:uglify'])?
Are you sure it isn't a problem with grunt-contrib-watch running multiple tasks?