mediawiki-extensions-Popups/Gruntfile.js
Volker E f47e333ff1 build: Bring SVGO optimization to build step
Enabling SVGO automation with 'grunt-svgmin' and conservative
plugin settings to build step, among those:
- enable removeRasterImages and sortAttrs,
- disable cleanupIDs, removeDesc, removeTitle, & removeViewBox as
  described in
  https://www.mediawiki.org/wiki/Manual:Coding_conventions/SVG#Exemplified_safe_configuration
- disable removeXMLProcInst; if the SVG doesn't start with an XML
  declaration, then it's MIME type will be detected as "text/plain"
  rather than "image/svg+xml" by libmagic and, consequently, MediaWiki's
  CSSMin CSS minifier. libmagic's default database currently requires
  that SVGs contain an XML declaration:
  <https://github.com/threatstack/libmagic/blob/master/magic/Magdir/sgml#L5>.
- make use of pretty and multipass options.

Settings are stored in a JSON file to be independent of the Grunt build
process. Also updating SVG accordingly.

Bug: T185596
Change-Id: I715ad4cf2e900665e4c32c78b4c2d9d9cebf0222
2018-08-01 10:51:43 -05:00

101 lines
1.9 KiB
JavaScript

/* eslint-evn node */
module.exports = function ( grunt ) {
const conf = grunt.file.readJSON( 'extension.json' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-svgmin' );
grunt.initConfig( {
banana: conf.MessagesDirs,
eslint: {
options: {
maxWarnings: 0,
reportUnusedDisableDirectives: true
},
// Lint the built artifacts with ES5 so that no ES6 slips to production
build: {
options: {
configFile: '.eslintrc.es5.json'
},
src: [
'resources/dist/*.js'
]
},
sources: {
src: [
'*.js',
'src/**/*.js',
'tests/**/*.js'
]
},
sourcesfix: {
options: {
fix: true
},
src: [
'*.js',
'src/**/*.js',
'tests/**/*.js'
]
}
},
jsonlint: {
all: [
'*.json',
'**/*.json',
'!docs/**',
'!node_modules/**',
'!vendor/**'
]
},
stylelint: {
options: {
syntax: 'less'
},
all: [
'src/**/*.less'
]
},
// SVG Optimization
svgmin: {
options: grunt.file.readJSON( '.svgo.json' ),
all: {
files: [ {
expand: true,
cwd: 'resources/ext.popups.images',
src: [
'**/*.svg'
],
dest: 'resources/ext.popups.images/',
ext: '.svg'
} ]
}
},
watch: {
options: {
interrupt: true,
debounceDelay: 1000
},
lint: {
files: [ 'resources/ext.popups.main/**/*.less', 'resources/**/*.js' ],
tasks: [ 'lint' ]
},
configFiles: {
files: [ 'Gruntfile.js' ],
options: {
reload: true
}
}
}
} );
grunt.registerTask( 'fix', [ 'eslint:sourcesfix' ] );
grunt.registerTask( 'lint', [ 'eslint', 'stylelint', 'jsonlint', 'banana', 'eslint:build', 'svgmin' ] );
grunt.registerTask( 'default', [ 'lint' ] );
};