Merge "Add links to Special:EditWatchlist in Preferences' Watchlist tab"
[mediawiki.git] / Gruntfile.js
blob9cf89d08271ab41df77d4167247da34bd7493286
1 /*jshint node:true */
2 module.exports = function ( grunt ) {
3         grunt.loadNpmTasks( 'grunt-contrib-jshint' );
4         grunt.loadNpmTasks( 'grunt-contrib-watch' );
5         grunt.loadNpmTasks( 'grunt-banana-checker' );
6         grunt.loadNpmTasks( 'grunt-jscs' );
7         grunt.loadNpmTasks( 'grunt-jsonlint' );
8         grunt.loadNpmTasks( 'grunt-karma' );
10         var wgServer = process.env.MW_SERVER,
11                 wgScriptPath = process.env.MW_SCRIPT_PATH;
13         grunt.initConfig( {
14                 pkg: grunt.file.readJSON( 'package.json' ),
15                 jshint: {
16                         options: {
17                                 jshintrc: true
18                         },
19                         all: [
20                                 '*.js',
21                                 '{includes,languages,resources,skins,tests}/**/*.js'
22                         ]
23                 },
24                 jscs: {
25                         all: [
26                                 '<%= jshint.all %>',
27                                 // Auto-generated file with JSON (double quotes)
28                                 '!tests/qunit/data/mediawiki.jqueryMsg.data.js',
29                                 // Skip functions are stored as script files but wrapped in a function when
30                                 // executed. node-jscs trips on the would-be "Illegal return statement".
31                                 '!resources/src/*-skip.js'
33                         // Exclude all files ignored by jshint
34                         ].concat( grunt.file.read( '.jshintignore' ).split( '\n' ).reduce( function ( patterns, pattern ) {
35                                 // Filter out empty lines
36                                 if ( pattern.length && pattern[0] !== '#' ) {
37                                         patterns.push( '!' + pattern );
38                                 }
39                                 return patterns;
40                         }, [] ) )
41                 },
42                 jsonlint: {
43                         all: [
44                                 '.jscsrc',
45                                 '{languages,maintenance,resources}/**/*.json',
46                                 'package.json'
47                         ]
48                 },
49                 banana: {
50                         core: 'languages/i18n/',
51                         api: 'includes/api/i18n/',
52                         installer: 'includes/installer/i18n/'
53                 },
54                 watch: {
55                         files: [
56                                 '<%= jscs.all %>',
57                                 '<%= jsonlint.all %>',
58                                 '.jshintignore',
59                                 '.jshintrc'
60                         ],
61                         tasks: 'test'
62                 },
63                 karma: {
64                         options: {
65                                 proxies: ( function () {
66                                         var obj = {};
67                                         // Set up a proxy for requests to relative urls inside wgScriptPath. Uses a
68                                         // property accessor instead of plain obj[wgScriptPath] assignment as throw if
69                                         // unset. Running grunt normally (e.g. npm test), should not fail over this.
70                                         // This ensures 'npm test' works out of the box, statically, on a git clone
71                                         // without MediaWiki fully installed or some environment variables set.
72                                         Object.defineProperty( obj, wgScriptPath, {
73                                                 enumerable: true,
74                                                 get: function () {
75                                                         if ( !wgServer ) {
76                                                                 grunt.fail.fatal( 'MW_SERVER is not set' );
77                                                         }
78                                                         if ( !wgScriptPath ) {
79                                                                 grunt.fail.fatal( 'MW_SCRIPT_PATH is not set' );
80                                                         }
81                                                         return wgServer + wgScriptPath;
82                                                 }
83                                         } );
84                                         return obj;
85                                 }() ),
86                                 files: [ {
87                                         pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
88                                         watched: false,
89                                         included: true,
90                                         served: false
91                                 } ],
92                                 frameworks: [ 'qunit' ],
93                                 reporters: [ 'dots' ],
94                                 singleRun: true,
95                                 autoWatch: false
96                         },
97                         main: {
98                                 browsers: [ 'Chrome' ]
99                         },
100                         more: {
101                                 browsers: [ 'Chrome', 'Firefox' ]
102                         }
103                 }
104         } );
106         grunt.registerTask( 'lint', ['jshint', 'jscs', 'jsonlint', 'banana'] );
107         grunt.registerTask( 'qunit', 'karma:main' );
109         grunt.registerTask( 'test', ['lint'] );
110         grunt.registerTask( 'default', 'test' );