2013-05-31 02:33:12 +00:00
|
|
|
/*!
|
|
|
|
* Grunt file
|
|
|
|
*
|
|
|
|
* @package VisualEditor
|
|
|
|
*/
|
|
|
|
|
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',
|
2018-01-11 17:24:25 +00:00
|
|
|
// TODO: Work out how to catch this timeout and continue.
|
|
|
|
// For now just make it very long.
|
|
|
|
timeout: 5 * 60 * 1000,
|
2017-03-28 19:27:10 +00:00
|
|
|
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',
|
2018-01-11 17:24:25 +00:00
|
|
|
// TODO: Work out how to catch this timeout and continue.
|
|
|
|
// For now just make it very long.
|
|
|
|
timeout: 5 * 60 * 1000,
|
2017-03-28 19:27:10 +00:00
|
|
|
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: {
|
2018-02-01 00:44:08 +00:00
|
|
|
pngs: {
|
|
|
|
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'
|
|
|
|
}
|
2017-02-03 15:08:56 +00:00
|
|
|
},
|
2018-02-01 00:44:08 +00:00
|
|
|
svgs: {
|
|
|
|
options: {
|
|
|
|
svgo: [
|
|
|
|
'--pretty',
|
|
|
|
'--enable=removeRasterImages',
|
|
|
|
'--enable=sortAttrs',
|
|
|
|
'--disable=cleanupIDs',
|
|
|
|
'--disable=removeDesc',
|
|
|
|
'--disable=removeTitle',
|
|
|
|
'--disable=removeViewBox',
|
|
|
|
'--disable=removeXMLProcInst'
|
|
|
|
]
|
|
|
|
},
|
2017-02-03 15:08:56 +00:00
|
|
|
expand: true,
|
2018-02-01 00:44:08 +00:00
|
|
|
src: 'images/*.svg'
|
2017-02-03 15:08:56 +00:00
|
|
|
}
|
|
|
|
},
|
2015-12-09 00:44:55 +00:00
|
|
|
tyops: {
|
|
|
|
options: {
|
|
|
|
typos: 'build/typos.json'
|
|
|
|
},
|
|
|
|
src: [
|
|
|
|
'**/*.{js,json,less,css,txt}',
|
2017-10-26 22:53:25 +00:00
|
|
|
'!package-lock.json',
|
2015-12-09 00:44:55 +00:00
|
|
|
'!build/typos.json',
|
2019-01-31 01:20:07 +00:00
|
|
|
'!i18n/**',
|
2015-12-09 00:44:55 +00:00
|
|
|
'!lib/**',
|
|
|
|
'!{docs,node_modules,vendor}/**',
|
|
|
|
'!.git/**'
|
|
|
|
]
|
|
|
|
},
|
2016-10-28 00:22:30 +00:00
|
|
|
eslint: {
|
2018-12-14 14:13:03 +00:00
|
|
|
options: {
|
2019-02-19 18:53:11 +00:00
|
|
|
reportUnusedDisableDirectives: true,
|
|
|
|
cache: true
|
2018-12-14 14:13:03 +00:00
|
|
|
},
|
2016-10-28 00:22:30 +00:00
|
|
|
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: [
|
2018-09-25 22:38:39 +00:00
|
|
|
'i18n/{ve-mw,ve-mw/api,ve-wmf}'
|
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' ] );
|
2018-02-01 00:44:08 +00:00
|
|
|
grunt.registerTask( 'screenshots', [ 'mochaTest:screenshots-en', 'image:pngs' ] );
|
|
|
|
grunt.registerTask( 'screenshots-all', [ 'mochaTest:screenshots-all', 'image:pngs' ] );
|
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 {
|
2018-02-01 00:44:08 +00:00
|
|
|
grunt.registerTask( 'ci', [ 'test', 'image:svgs', 'test-ci' ] );
|
2014-06-26 11:24:06 +00:00
|
|
|
}
|
2013-05-31 02:33:12 +00:00
|
|
|
};
|