2013-05-31 02:33:12 +00:00
|
|
|
/*!
|
|
|
|
* Grunt file
|
|
|
|
*
|
|
|
|
* @package VisualEditor
|
|
|
|
*/
|
|
|
|
|
2022-03-17 23:39:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-05-31 02:33:12 +00:00
|
|
|
module.exports = function ( grunt ) {
|
2024-04-29 11:52:40 +00:00
|
|
|
const conf = grunt.file.readJSON( 'extension.json' ),
|
2017-03-28 19:27:10 +00:00
|
|
|
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 () {
|
2023-07-03 12:57:57 +00:00
|
|
|
global.langs = [ grunt.option( 'lang' ) || 'en' ];
|
2017-03-28 19:27:10 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
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 () {
|
2023-07-03 12:57:57 +00:00
|
|
|
global.langs = require( './build/tasks/screenshotLangs.json' ).langs;
|
2017-03-28 19:27:10 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2013-05-31 02:33:12 +00:00
|
|
|
|
2016-10-28 00:22:30 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
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' );
|
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( {
|
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: [
|
2024-03-27 12:37:43 +00:00
|
|
|
'**/*.{js,json,less,css,txt,php,md,sh}',
|
2017-10-26 22:53:25 +00:00
|
|
|
'!package-lock.json',
|
2015-12-09 00:44:55 +00:00
|
|
|
'!build/typos.json',
|
2024-03-27 12:37:43 +00:00
|
|
|
'!**/i18n/**/*.json',
|
|
|
|
'**/i18n/**/en.json',
|
|
|
|
'**/i18n/**/qqq.json',
|
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: {
|
2020-06-02 20:30:00 +00:00
|
|
|
cache: true,
|
|
|
|
fix: grunt.option( 'fix' )
|
2018-12-14 14:13:03 +00:00
|
|
|
},
|
2022-04-13 14:44:49 +00:00
|
|
|
all: [ '.' ]
|
2013-12-06 02:34:44 +00:00
|
|
|
},
|
2016-05-16 14:38:57 +00:00
|
|
|
stylelint: {
|
2020-11-19 22:32:54 +00:00
|
|
|
options: {
|
|
|
|
reportNeedlessDisables: true
|
|
|
|
},
|
2016-05-20 12:55:41 +00:00
|
|
|
all: [
|
2019-09-18 18:11:45 +00:00
|
|
|
'**/*.{css,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
|
|
|
},
|
2023-09-12 16:59:33 +00:00
|
|
|
banana: conf.MessagesDirs,
|
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 () {
|
2022-03-17 23:39:53 +00:00
|
|
|
const done = this.async();
|
2014-06-26 11:24:06 +00:00
|
|
|
// Are there unstaged changes?
|
2024-06-04 03:39:48 +00:00
|
|
|
require( 'child_process' ).exec( 'git ls-files --modified', ( err, stdout, stderr ) => {
|
2022-03-17 23:39:53 +00:00
|
|
|
const ret = err || stderr || stdout;
|
2014-06-26 11:24:06 +00:00
|
|
|
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
|
2024-06-04 03:39:48 +00:00
|
|
|
require( 'child_process' ).exec( 'git diff -U1 | tail -n +3', ( err2, stdout2, stderr2 ) => {
|
2020-08-18 12:16:49 +00:00
|
|
|
grunt.log.write( err2 || stderr2 || stdout2 );
|
2015-06-01 15:15:06 +00:00
|
|
|
done( false );
|
|
|
|
} );
|
2014-06-26 11:24:06 +00:00
|
|
|
} else {
|
|
|
|
grunt.log.ok( 'No unstaged changes.' );
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-04-29 11:52:40 +00:00
|
|
|
grunt.registerTask( 'test', [ 'tyops', 'eslint', 'stylelint', 'banana' ] );
|
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
|
|
|
};
|