Add explicit plural for number of bytes
[mediawiki.git] / Gruntfile.js
blob573db69afb15a591d42bff5cd4e354562b8eb3df
1 /*jshint node:true */
2 module.exports = function ( grunt ) {
3         grunt.loadNpmTasks( 'grunt-contrib-copy' );
4         grunt.loadNpmTasks( 'grunt-contrib-jshint' );
5         grunt.loadNpmTasks( 'grunt-contrib-watch' );
6         grunt.loadNpmTasks( 'grunt-banana-checker' );
7         grunt.loadNpmTasks( 'grunt-jscs' );
8         grunt.loadNpmTasks( 'grunt-jsonlint' );
9         grunt.loadNpmTasks( 'grunt-karma' );
11         var wgServer = process.env.MW_SERVER,
12                 wgScriptPath = process.env.MW_SCRIPT_PATH,
13                 karmaProxy = {};
15         karmaProxy[wgScriptPath] = wgServer + wgScriptPath;
17         grunt.initConfig( {
18                 pkg: grunt.file.readJSON( 'package.json' ),
19                 jshint: {
20                         options: {
21                                 jshintrc: true
22                         },
23                         all: [
24                                 '*.js',
25                                 '{includes,languages,resources,tests}/**/*.js'
26                         ]
27                 },
28                 jscs: {
29                         all: [
30                                 '<%= jshint.all %>',
31                                 // Auto-generated file with JSON (double quotes)
32                                 '!tests/qunit/data/mediawiki.jqueryMsg.data.js',
33                                 // Skip functions are stored as script files but wrapped in a function when
34                                 // executed. node-jscs trips on the would-be "Illegal return statement".
35                                 '!resources/src/*-skip.js'
37                         // Exclude all files ignored by jshint
38                         ].concat( grunt.file.read( '.jshintignore' ).split( '\n' ).reduce( function ( patterns, pattern ) {
39                                 // Filter out empty lines
40                                 if ( pattern.length && pattern[0] !== '#' ) {
41                                         patterns.push( '!' + pattern );
42                                 }
43                                 return patterns;
44                         }, [] ) )
45                 },
46                 jsonlint: {
47                         all: [
48                                 '.jscsrc',
49                                 '{languages,maintenance,resources}/**/*.json',
50                                 'package.json'
51                         ]
52                 },
53                 banana: {
54                         core: 'languages/i18n/',
55                         api: 'includes/api/i18n/',
56                         installer: 'includes/installer/i18n/'
57                 },
58                 watch: {
59                         files: [
60                                 '<%= jscs.all %>',
61                                 '<%= jsonlint.all %>',
62                                 '.jshintignore',
63                                 '.jshintrc'
64                         ],
65                         tasks: 'test'
66                 },
67                 karma: {
68                         options: {
69                                 proxies: karmaProxy,
70                                 files: [ {
71                                         pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
72                                         watched: false,
73                                         included: true,
74                                         served: false
75                                 } ],
76                                 frameworks: [ 'qunit' ],
77                                 reporters: [ 'dots' ],
78                                 singleRun: true,
79                                 autoWatch: false,
80                                 // Some tests in extensions don't yield for more than the default 10s (T89075)
81                                 browserNoActivityTimeout: 60 * 1000
82                         },
83                         main: {
84                                 browsers: [ 'Chrome' ]
85                         },
86                         more: {
87                                 browsers: [ 'Chrome', 'Firefox' ]
88                         }
89                 },
90                 copy: {
91                         jsduck: {
92                                 src: 'resources/**/*',
93                                 dest: 'docs/js/modules',
94                                 expand: true,
95                                 rename: function ( dest, src ) {
96                                         return require( 'path' ).join( dest, src.replace( 'resources/', '' ) );
97                                 }
98                         }
99                 }
100         } );
102         grunt.registerTask( 'assert-mw-env', function () {
103                 if ( !process.env.MW_SERVER ) {
104                         grunt.log.error( 'Environment variable MW_SERVER must be set.\n' +
105                                 'Set this like $wgServer, e.g. "http://localhost"'
106                         );
107                 }
108                 if ( !process.env.MW_SCRIPT_PATH ) {
109                         grunt.log.error( 'Environment variable MW_SCRIPT_PATH must be set.\n' +
110                                 'Set this like $wgScriptPath, e.g. "/w"');
111                 }
112                 return !!( process.env.MW_SERVER && process.env.MW_SCRIPT_PATH );
113         } );
115         grunt.registerTask( 'lint', ['jshint', 'jscs', 'jsonlint', 'banana'] );
116         grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:main' ] );
118         grunt.registerTask( 'test', ['lint'] );
119         grunt.registerTask( 'default', 'test' );