2013-05-31 02:33:12 +00:00
|
|
|
/*!
|
|
|
|
* Grunt file
|
|
|
|
*
|
|
|
|
* @package VisualEditor
|
|
|
|
*/
|
|
|
|
|
2016-05-16 14:38:57 +00:00
|
|
|
require( 'babel-polyfill' );
|
|
|
|
|
2017-02-03 15:19:44 +00:00
|
|
|
/* eslint-env node, es6 */
|
2013-05-31 02:33:12 +00:00
|
|
|
module.exports = function ( grunt ) {
|
2017-03-28 19:27:10 +00:00
|
|
|
var modules = grunt.file.readJSON( 'lib/ve/build/modules.json' ),
|
|
|
|
screenshotOptions = {
|
|
|
|
reporter: 'spec',
|
|
|
|
timeout: 40000,
|
|
|
|
require: [
|
|
|
|
function () {
|
2017-04-29 11:37:53 +00:00
|
|
|
// eslint-disable-next-line no-undef, no-implicit-globals
|
2017-03-28 19:27:10 +00:00
|
|
|
langs = [ 'en' ];
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
screenshotOptionsAll = {
|
|
|
|
reporter: 'spec',
|
|
|
|
timeout: 40000,
|
|
|
|
require: [
|
|
|
|
function () {
|
2017-04-29 11:37:53 +00:00
|
|
|
// eslint-disable-next-line no-undef, no-implicit-globals
|
2017-03-28 19:27:10 +00:00
|
|
|
langs = require( './build/tasks/screenshotLangs.json' ).langs;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2013-05-31 02:33:12 +00:00
|
|
|
|
2016-10-28 00:22:30 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
2015-04-03 09:33:22 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-contrib-copy' );
|
2013-05-31 02:33:12 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-contrib-watch' );
|
2016-10-28 00:22:30 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-eslint' );
|
2017-02-03 15:08:56 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-image' );
|
2015-06-13 08:14:38 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-jsonlint' );
|
2016-06-24 14:24:42 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-mocha-test' );
|
2016-05-17 14:05:59 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-stylelint' );
|
2015-12-09 00:44:55 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-tyops' );
|
2013-12-19 23:07:19 +00:00
|
|
|
grunt.loadTasks( 'lib/ve/build/tasks' );
|
2013-12-14 23:04:08 +00:00
|
|
|
grunt.loadTasks( 'build/tasks' );
|
2013-05-31 02:33:12 +00:00
|
|
|
|
|
|
|
grunt.initConfig( {
|
2013-12-19 23:07:19 +00:00
|
|
|
jsduckcatconfig: {
|
|
|
|
main: {
|
2015-03-05 22:51:53 +00:00
|
|
|
target: '.jsduck/categories.json',
|
2013-12-19 23:07:19 +00:00
|
|
|
from: [
|
2015-03-05 22:51:53 +00:00
|
|
|
'.jsduck/mw-categories.json',
|
2013-12-19 23:07:19 +00:00
|
|
|
{
|
2015-03-03 08:26:34 +00:00
|
|
|
file: 'lib/ve/.jsduck/categories.json',
|
2013-12-19 23:07:19 +00:00
|
|
|
aggregate: {
|
|
|
|
'VisualEditor (core)': [
|
|
|
|
'General',
|
|
|
|
'Initialization',
|
|
|
|
'DataModel',
|
|
|
|
'ContentEditable',
|
|
|
|
'User Interface',
|
|
|
|
'Tests'
|
|
|
|
]
|
|
|
|
},
|
2015-06-10 19:28:09 +00:00
|
|
|
include: [ 'UnicodeJS', 'OOjs UI', 'Upstream' ]
|
2013-12-19 01:07:54 +00:00
|
|
|
}
|
2013-12-19 23:07:19 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
buildloader: {
|
|
|
|
egiframe: {
|
2015-03-05 22:51:53 +00:00
|
|
|
targetFile: '.jsduck/eg-iframe.html',
|
|
|
|
template: '.jsduck/eg-iframe.html.template',
|
2013-12-14 23:04:08 +00:00
|
|
|
modules: modules,
|
2014-05-21 20:09:56 +00:00
|
|
|
load: [ 'visualEditor.desktop.standalone' ],
|
2016-11-19 00:00:14 +00:00
|
|
|
pathPrefix: 'lib/ve/',
|
2013-12-14 23:04:08 +00:00
|
|
|
indent: '\t\t'
|
|
|
|
}
|
|
|
|
},
|
2016-06-24 14:24:42 +00:00
|
|
|
mochaTest: {
|
2016-06-24 16:51:13 +00:00
|
|
|
'screenshots-en': {
|
2017-03-28 19:27:10 +00:00
|
|
|
options: screenshotOptions,
|
2017-03-28 17:15:25 +00:00
|
|
|
src: [ 'build/screenshots.userGuide.js' ]
|
2016-06-24 16:51:13 +00:00
|
|
|
},
|
|
|
|
'screenshots-all': {
|
2017-03-28 19:27:10 +00:00
|
|
|
options: screenshotOptionsAll,
|
2017-03-28 17:15:25 +00:00
|
|
|
src: [ 'build/screenshots.userGuide.js' ]
|
2017-03-28 19:27:10 +00:00
|
|
|
},
|
|
|
|
'diff-screenshots-en': {
|
|
|
|
options: screenshotOptions,
|
|
|
|
src: [ 'build/screenshots.diffs.js' ]
|
|
|
|
},
|
|
|
|
'diff-screenshots-all': {
|
|
|
|
options: screenshotOptionsAll,
|
|
|
|
src: [ 'build/screenshots.diffs.js' ]
|
2016-06-24 14:24:42 +00:00
|
|
|
}
|
|
|
|
},
|
2017-02-03 15:08:56 +00:00
|
|
|
image: {
|
|
|
|
options: {
|
|
|
|
zopflipng: true,
|
|
|
|
pngout: true,
|
|
|
|
optipng: true,
|
|
|
|
advpng: true,
|
|
|
|
pngcrush: true
|
|
|
|
},
|
|
|
|
'screenshots-en': {
|
|
|
|
expand: true,
|
|
|
|
src: 'screenshots/*-en.png'
|
|
|
|
},
|
|
|
|
'screenshots-all': {
|
|
|
|
expand: true,
|
|
|
|
src: 'screenshots/*.png'
|
|
|
|
}
|
|
|
|
},
|
2015-12-09 00:44:55 +00:00
|
|
|
tyops: {
|
|
|
|
options: {
|
|
|
|
typos: 'build/typos.json'
|
|
|
|
},
|
|
|
|
src: [
|
|
|
|
'**/*.{js,json,less,css,txt}',
|
|
|
|
'!build/typos.json',
|
|
|
|
'!lib/**',
|
|
|
|
'!{docs,node_modules,vendor}/**',
|
|
|
|
'!.git/**'
|
|
|
|
]
|
|
|
|
},
|
2016-10-28 00:22:30 +00:00
|
|
|
eslint: {
|
|
|
|
all: [
|
|
|
|
'*.js',
|
2017-04-20 15:56:45 +00:00
|
|
|
'{build,modules}/**/*.js'
|
2016-10-28 00:22:30 +00:00
|
|
|
]
|
2013-12-06 02:34:44 +00:00
|
|
|
},
|
2016-05-16 14:38:57 +00:00
|
|
|
stylelint: {
|
2016-05-20 12:55:41 +00:00
|
|
|
all: [
|
2016-05-16 14:38:57 +00:00
|
|
|
'**/*.css',
|
2017-06-29 19:17:54 +00:00
|
|
|
'**/*.less',
|
2016-05-16 14:38:57 +00:00
|
|
|
'!coverage/**',
|
|
|
|
'!dist/**',
|
|
|
|
'!docs/**',
|
|
|
|
'!lib/**',
|
2017-07-06 20:39:42 +00:00
|
|
|
'!node_modules/**',
|
|
|
|
'!vendor/**'
|
2016-05-16 14:38:57 +00:00
|
|
|
]
|
2013-05-31 02:33:12 +00:00
|
|
|
},
|
2014-04-04 22:22:57 +00:00
|
|
|
banana: {
|
2015-07-18 14:30:01 +00:00
|
|
|
all: [
|
2016-07-25 10:18:34 +00:00
|
|
|
'modules/ve-{mw,wmf}/i18n/'
|
2015-07-18 14:30:01 +00:00
|
|
|
]
|
2014-04-04 22:22:57 +00:00
|
|
|
},
|
2015-06-13 08:14:38 +00:00
|
|
|
jsonlint: {
|
|
|
|
all: [
|
2016-03-29 16:53:56 +00:00
|
|
|
'*.json',
|
2017-08-19 08:43:53 +00:00
|
|
|
'.{stylelintrc,eslintrc}.json',
|
2015-06-13 08:14:38 +00:00
|
|
|
'**/*.json',
|
2015-10-29 17:26:47 +00:00
|
|
|
'!**/node_modules/**',
|
2017-08-19 08:43:53 +00:00
|
|
|
'!lib/**',
|
|
|
|
'!vendor/**'
|
2015-06-13 08:14:38 +00:00
|
|
|
]
|
|
|
|
},
|
2015-04-03 09:33:22 +00:00
|
|
|
copy: {
|
|
|
|
jsduck: {
|
|
|
|
src: 'lib/ve/**/*',
|
|
|
|
dest: 'docs/',
|
|
|
|
expand: true
|
|
|
|
}
|
|
|
|
},
|
2013-05-31 02:33:12 +00:00
|
|
|
watch: {
|
2013-12-18 04:33:22 +00:00
|
|
|
files: [
|
2017-08-19 08:43:53 +00:00
|
|
|
'.{stylelintrc,eslintrc}.json',
|
2016-10-28 00:22:30 +00:00
|
|
|
'<%= eslint.all %>',
|
2016-05-16 14:38:57 +00:00
|
|
|
'<%= stylelint.all %>'
|
2013-12-18 04:33:22 +00:00
|
|
|
],
|
2014-05-15 16:12:43 +00:00
|
|
|
tasks: 'test'
|
2013-05-31 02:33:12 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-06-26 11:24:06 +00:00
|
|
|
grunt.registerTask( 'git-status', function () {
|
|
|
|
var done = this.async();
|
|
|
|
// Are there unstaged changes?
|
|
|
|
require( 'child_process' ).exec( 'git ls-files --modified', function ( err, stdout, stderr ) {
|
|
|
|
var ret = err || stderr || stdout;
|
|
|
|
if ( ret ) {
|
2015-06-01 15:15:06 +00:00
|
|
|
grunt.log.error( 'Unstaged changes in these files:' );
|
|
|
|
grunt.log.error( ret );
|
|
|
|
// Show a condensed diff
|
|
|
|
require( 'child_process' ).exec( 'git diff -U1 | tail -n +3', function ( err, stdout, stderr ) {
|
|
|
|
grunt.log.write( err || stderr || stdout );
|
|
|
|
done( false );
|
|
|
|
} );
|
2014-06-26 11:24:06 +00:00
|
|
|
} else {
|
|
|
|
grunt.log.ok( 'No unstaged changes.' );
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2014-05-15 16:12:43 +00:00
|
|
|
grunt.registerTask( 'build', [ 'jsduckcatconfig', 'buildloader' ] );
|
2017-04-28 16:04:47 +00:00
|
|
|
grunt.registerTask( 'lint', [ 'tyops', 'eslint', 'stylelint', 'jsonlint', 'banana' ] );
|
2014-05-15 16:12:43 +00:00
|
|
|
grunt.registerTask( 'test', [ 'build', 'lint' ] );
|
2014-06-26 11:24:06 +00:00
|
|
|
grunt.registerTask( 'test-ci', [ 'git-status' ] );
|
2017-02-03 15:08:56 +00:00
|
|
|
grunt.registerTask( 'screenshots', [ 'mochaTest:screenshots-en', 'image:screenshots-en' ] );
|
|
|
|
grunt.registerTask( 'screenshots-all', [ 'mochaTest:screenshots-all', 'image:screenshots-all' ] );
|
2014-05-15 16:12:43 +00:00
|
|
|
grunt.registerTask( 'default', 'test' );
|
2014-06-26 11:24:06 +00:00
|
|
|
|
|
|
|
if ( process.env.JENKINS_HOME ) {
|
|
|
|
grunt.renameTask( 'test', 'test-internal' );
|
|
|
|
grunt.registerTask( 'test', [ 'test-internal', 'test-ci' ] );
|
|
|
|
} else {
|
|
|
|
grunt.registerTask( 'ci', [ 'test', 'test-ci' ] );
|
|
|
|
}
|
2013-05-31 02:33:12 +00:00
|
|
|
};
|