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