I am trying to include TS compilation to my project. This is my tsconfig.json:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "system",
"moduleResolution": "node",
"noImplicitAny": false,
"outDir": "build/develop/assets/scripts",
"removeComments": false,
"rootDir": "assets/management/",
"sourceMap": false,
"target": "ES5"
},
"exclude": [
"node_modules"
]
}
And this is my tasks/config/ts.js file:
/**
* Compile TS files to JS.
*
* #see https://github.com/TypeStrong/grunt-ts
*/
module.exports = function (grunt) {
grunt.config.set('ts', {
angular_app_dev: {
default: {
// src: [
// "assets/management/**/*.ts",
// "!node_modules/**/*.ts" // Avoid compiling TypeScript files in node_modules
// ],
// outDir: "assets/vili2",
tsconfig: {
tsconfig: true,
ignoreFiles: false,
ignoreSettings: false,
overwriteFilesGlob: false,
updateFiles: true,
passThrough: false
}
// options: {
// module: 'commonjs',
// // To compile TypeScript using external modules like NodeJS
// fast: 'never'
// // You'll need to recompile all the files each time for NodeJS
// }
}
}
});
grunt.loadNpmTasks('grunt-ts');
};
I am trying to make it so that it compiles the TS files ( later I want to add a watch so that it compiles them every time I change them, but one thing at a time )
When I run "tsc" from the command line it works perfectly, however if I run
grunt ts:angular_app_dev -verbose
it produces this:
$ grunt ts:angular_app_dev -verbose
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Registering "grunt-contrib-clean" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-clean\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-clean\package.json...OK
Loading "clean.js" tasks...OK
+ clean
Registering "grunt-contrib-coffee" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-coffee\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-coffee\package.json...OK
Loading "coffee.js" tasks...OK
+ coffee
Registering "grunt-contrib-concat" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-concat\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-concat\package.json...OK
Loading "concat.js" tasks...OK
+ concat
Registering "grunt-contrib-copy" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-copy\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-copy\package.json...OK
Loading "copy.js" tasks...OK
+ copy
Registering "grunt-contrib-cssmin" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-cssmin\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-cssmin\package.json...OK
Loading "cssmin.js" tasks...OK
+ cssmin
Registering "grunt-contrib-jst" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-jst\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-jst\package.json...OK
Loading "jst.js" tasks...OK
+ jst
Registering "grunt-contrib-less" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-less\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-less\package.json...OK
Loading "less.js" tasks...OK
+ less
Registering "grunt-sails-linker" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-sails-linker\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-sails-linker\package.json...OK
Loading "scriptlinker.js" tasks...OK
+ sails-linker
Registering "grunt-sync" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-sync\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-sync\package.json...OK
Loading "sync.js" tasks...OK
+ sync
Registering "grunt-ts" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-ts\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-ts\package.json...OK
Loading "ts.js" tasks...OK
+ ts
Registering "grunt-contrib-uglify" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-uglify\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-uglify\package.json...OK
Loading "uglify.js" tasks...OK
+ uglify
Registering "grunt-contrib-watch" local Npm module tasks.
Reading D:\Work\...\...\node_modules\grunt-contrib-watch\package.json...OK
Parsing D:\Work\...\...\node_modules\grunt-contrib-watch\package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "Gruntfile.js" tasks...OK
+ build, buildProd, compileAssets, db:migrate, default, linkAssets, linkAssetsBuild, linkAssetsBuildProd, prod, prodTest, syncAssets
Running tasks: ts:angular_app_dev
Running "ts:angular_app_dev" (ts) task
Verifying property ts.angular_app_dev exists in config...OK
File: [no files]
Done, without errors.
What am I missing ???
You are not missing anything. As it says down in the bottom it is "Done, without errors". Remove your -verbose flag for less information about the grunt compilation :)
grunt ts:angular_app_dev should be good enought
Related
I'm trying to use grunt in my ASP project, but for whatever reasons have get a stupid warning-message from Visual Studio.
How you can see down, the bower-task has been executed, but haven't uglify- and less-tasks. Gruntfile.js and folder "wwwroot" are in the same folder. What's wrong ?
This is console output in Visual Studio 2015:
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" bower
Running "bower:install" (bower) task
>> Installed bower packages
>> Copied packages to c:\T\BW\src\BW\wwwroot\lib
Done, without errors.
Process terminated with code 0.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" uglify_default
Running "uglify:uglify_target" (uglify) task
Process terminated with code 0.
>> Destination wwwroot/lib/angular/angular.js not written because src files were empty.
>> No files created.
Done, without errors.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" less
Running "less:dev" (less) task
>> Destination wwwroot/css/site.css not written because no source files were found.
Done, without errors.
Process terminated with code 0.
This is my gruntfile.js:
grunt.initConfig({
bower: {
install: {
options: {
targetDir: "wwwroot/lib",
layout: "byComponent",
cleanTargetDir: false
}
}
},
uglify: {
uglify_target: {
files: {
"wwwroot/lib/angular/angular.js":["src/angular.min.js"]
}
}
},
less: {
dev: {
files: {
"wwwroot/css/site.css": ["less/site.less"]
},
options: {
sourceMap: true,
}
}
},
});
grunt.registerTask("default", ["bower:install"]);
grunt.loadNpmTasks("grunt-bower-task");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-less");
Are you sure "wwwroot/lib/angular/angular.js":["src/angular.min.js"] is correct in your uglify step? Uglify is for minifying files, so it would seem as if you have the destination and source parameters reversed. You are also getting the message Destination wwwroot/lib/angular/angular.js not written because src files were empty. which would seem to indicate that as well.
The less step seems correct, but it can't find the less file you are trying to compile. Are you sure that site.less exists in a less folder?
Here is the less portion of the grunt file I just wrote, and it seems to work well, although getting the sourcemap to actually generate is still an issue. This is pretty much an exact equivalent of VS 2013 with Web Essentials installed. Compiling all less files in the content folder using autoprefix for the browsers we support, and puts the .css back into the content folder. It doesn't compile any less file that starts with _, as those are just includes/variables.
less: {
development: {
options: {
paths: ["content"],
compress: true,
plugins: [
new (require('less-plugin-autoprefix'))({ browsers: ["IE >= 9, firefox > 10, last 2 Chrome versions, last 2 safari versions, last 2 ios versions"], map: { inline: false } })
]
},
files: [{
expand: true,
cwd: 'content',
src: ['*.less', '!_*.less'],
dest: 'content',
ext: '.css'
}]
}
},
When I execute the clean task (grunt clean), everything works as expected but when I run the watch task (grunt test), I get the following error:
util.js:35
var str = String(f).replace(formatRegExp, function(x) {
^
RangeError: Maximum call stack size exceeded
Here's my gruntfile
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
clean: ['tmpDir/']
watch:
options:
spawn: false
src:
tasks: ['clean']
files: [
src: 'client/assets/strings/en/str.coffee'
]
# plugins
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-watch')
# tasks
grunt.registerTask('test', ['watch'])
Here's my package.json file:
{
"author": "Your Name <Your Email>",
"name": "app-name",
"description": "Application description",
"version": "0.0.1",
"homepage": "",
"repository": {
"type": "git",
"url": ""
},
"engines": {
"node": "~0.10.28"
},
"scripts": {
"start": "muffin server"
},
"dependencies": {
"coffee-script": "~1.1.2",
"express": "~3.0.6",
"chai": "~1.4.2",
"underscore": "~1.4.3",
"wd": "0.0.27"
},
"devDependencies": {
"express": "~3.0.6",
"grunt": "^0.4.5",
"grunt-contrib-coffee": "^0.11.1",
"grunt-contrib-copy": "^0.6.0",
"grunt-contrib-less": "^0.11.4",
"grunt-contrib-watch": "^0.6.1",
"requirejs": "~2.0.1"
}
}
The output when I run with --verbose is the following:
Note: replaced base path with ***
Initializing
Command-line options: --verbose
Reading "gruntfile.coffee" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Registering "grunt-contrib-clean" local Npm module tasks.
Reading /***/node_modules/grunt-contrib-clean/package.json...OK
Parsing /***/node_modules/grunt-contrib-clean/package.json...OK
Loading "clean.js" tasks...OK
+ clean
Registering "grunt-contrib-watch" local Npm module tasks.
Reading /***/node_modules/grunt-contrib-watch/package.json...OK
Parsing /***/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "gruntfile.coffee" tasks...OK
+ test
Running tasks: test
Running "test" task
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'
... many of these
Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
... many of these
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
util.js:35
var str = String(f).replace(formatRegExp, function(x) {
^
RangeError: Maximum call stack size exceeded
I finally figured out a similar problem I was having with spell. I was using
grunt.registerTask('spell', [ 'spell']);
The trick was that Grunt doesn't seem to like the repetition in names. When I switch to
grunt.registerTask('spellCheck', [ 'spell']);
Everything worked as it should.
may this help you
The files property takes an Array of file pattern strings. You've supplied an object it doesn't know how to interpret.
Change this:
files: [
src: 'client/assets/strings/en/str.coffee'
]
To this:
files: [
'client/assets/strings/en/str.coffee'
]
I use grunt-contrib-concat, but it doesn't appear to work.
All file are in the folder.
I used --verbose to see the details, but everything seems to be working correctly.
concat: {
options: {
// define a string to put between each file in the concatenated output
separator: ';'
},
dist: {
// the files to concatenate
src: [
//'assets/javascript/components/*.js',
'assets/javascript/components/jquery-ui-1.10.3.custom.js',
'assets/javascript/components/spectrum.js',
'assets/javascript/components/prefixfree.min.js',
'assets/javascript/src/jquery.menu_css3.js'
],
// the location of the resulting JS file
dest: 'assets/javascript/jquery.<%= pkg.name %>.min.js'
}
},
Running the tasks with --verbose:
Running "concat" task
Running "concat:dist" (concat) task
Verifying property concat.dist exists in config...OK
Files: assets/javascript/src/jquery.menu_css3.js -> assets/javascript/jquery.menu_css3.min.js
Options: separator=";", banner="", footer="", stripBanners=false, process=false
Reading assets/javascript/src/jquery.menu_css3.js...OK
Writing assets/javascript/jquery.menu_css3.min.js...OK
File "assets/javascript/jquery.menu_css3.min.js" created.
Running "uglify" task
Running "uglify:dist" (uglify) task
Verifying property uglify.dist exists in config...OK
Files: assets/javascript/jquery.menu_css3.min.js -> assets/javascript/jquery.menu_css3.min.js
Options: banner="", footer="", compress={"warnings":false}, mangle={}, beautify=false, report=false
Minifying with UglifyJS...Reading assets/javascript/jquery.menu_css3.min.js...OK
OK
Writing assets/javascript/jquery.menu_css3.min.js...OK
File "assets/javascript/jquery.menu_css3.min.js" created.
I'm currently getting the same error for all tasks that I run via grunt.
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ build,default,nick,server,test
No tasks specified, running default tasks.
Running tasks: default
Running "default" task
Warning: Task "undefined" not found. Use --force to continue.
The last warning happens for any task I run.
Grunfile.js(important stuff):
...
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js',
'!<%= yeoman.app %>/scripts/libs/{,*/}*.js'
]
},
...
});
...
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('nick', [ ]);
grunt.registerTask('default', [
'jshint'
]);
running jshint by itself works fine..
grunt jshint
>Running "jshint:all" (jshint) task
>> 52 files lint free.
>>
>>Done, without errors.
Done, without errors.
Any help? Let me know if there is any other info you need to help.
Nick.
Another potential cause of this problem is having double commas in a Gruntfile.js's registerTask section. For instance:
grunt.registerTask('dist', ['clean',, 'uglify:dist']);
Note that this will also produce the same error:
grunt.registerTask('dist', ['clean', /*unnecessarytask */, 'uglify:dist']);
I had the same issue and all I needed to do was update grunt with:
npm --global update grunt-cli
In order to customize my grunt tasks, I need access to the grunt task name given on the command line when starting grunt.
The options is no problem, since its well documented (grunt.options).
It's also well documented how to find out the task name, when running a grunt task.
But I need access to the task name before.
Eg, the user writes
grunt build --target=client
When configuring the grunt job in my Gruntfile.js, I can use
grunt.option('target') to get 'client'.
But how do I get hold of parameter build before the task build starts?
Any guidance is much appreciated!
Your grunt file is basically just a function. Try adding this line to the top:
module.exports = function( grunt ) {
/*==> */ console.log(grunt.option('target'));
/*==> */ console.log(grunt.cli.tasks);
// Add your pre task code here...
Running with grunt build --target=client should give you the output:
client
[ 'build' ]
At that point, you can run any code you need to before your task is run including setting values with new dependencies.
A better way is to use grunt.task.current which has information about the currently running task, including a name property. Within a task, the context (i.e. this) is the same object. So . . .
grunt.registerTask('foo', 'Foobar all the things', function() {
console.log(grunt.task.current.name); // foo
console.log(this.name); // foo
console.log(this === grunt.task.current); // true
});
If build is an alias to other tasks and you just want to know what command was typed that led to the current task execution, I typically use process.argv[2]. If you examine process.argv, you'll see that argv[0] is node (because grunt is a node process), argv[1] is grunt, and argv[2] is the actual grunt task (followed by any params in the remainder of argv).
EDIT:
Example output from console.log(grunt.task.current) on grunt#0.4.5 from within a task (can't have a current task from not a current task).
{
nameArgs: 'server:dev',
name: 'server',
args: [],
flags: {},
async: [Function],
errorCount: [Getter],
requires: [Function],
requiresConfig: [Function],
options: [Function],
target: 'dev',
data: { options: { debugPort: 5858, cwd: 'server' } },
files: [],
filesSrc: [Getter]
}
You can use grunt.util.hooker.hook for this.
Example (part of Gruntfile.coffee):
grunt.util.hooker.hook grunt.task, (opt) ->
if grunt.task.current and grunt.task.current.nameArgs
console.log "Task to run: " + grunt.task.current.nameArgs
CMD:
C:\some_dir>grunt concat --cmp my_cmp
Task to run: concat
Running "concat:coffee" (concat) task
Task to run: concat:coffee
File "core.coffee" created.
Done, without errors.
There is also a hack that I've used to prevent certain task execution:
grunt.util.hooker.hook grunt.task, (opt) ->
if grunt.task.current and grunt.task.current.nameArgs
console.log "Task to run: " + grunt.task.current.nameArgs
if grunt.task.current.nameArgs is "<some task you don't want user to run>"
console.log "Ooooh, not <doing smth> today :("
exit() # Not valid. Don't know how to exit :), but will stop grunt anyway
CMD, when allowed:
C:\some_dir>grunt concat:coffee --cmp my_cmp
Running "concat:coffee" (concat) task
Task to run: concat:coffee
File "core.coffee" created.
Done, without errors.
CMD, when prevented:
C:\some_dir>grunt concat:coffee --cmp my_cmp
Running "concat:coffee" (concat) task
Task to run: concat:coffee
Ooooh, not concating today :(
Warning: exit is not defined Use --force to continue.
Aborted due to warnings.