Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ module.exports = function ( grunt ) {
eslint: {
options: {
extensions: [ '.js', '.json' ],
cache: true
cache: true,
fix: grunt.option( 'fix' )
},
main: [
'**/*.{js,json}',
Expand Down
31 changes: 16 additions & 15 deletions build/moduleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* Code shared with the OOjs UI project
*/

var self = module.exports = {
'use strict';

const self = module.exports = {
/**
* Expand an array of file paths and variant-objects into
* a flattened list by variant.
Expand Down Expand Up @@ -40,16 +42,15 @@ var self = module.exports = {
// (which will compile the less code) and the concat task
// (which will prepend intro.css without it being stripped
// like recess would).
var targets = { default: [] };
const targets = { default: [] };
resources.forEach( function ( filepath ) {
var variant, buffer;
if ( typeof filepath !== 'object' ) {
filepath = { default: filepath };
}
// Fetch copy of buffer before filepath/variant loop, otherwise
// it can incorrectly include the default file in a non-default variant.
buffer = targets.default.slice();
for ( variant in filepath ) {
const buffer = targets.default.slice();
for ( const variant in filepath ) {
if ( !targets[ variant ] ) {
targets[ variant ] = buffer.slice();
}
Expand All @@ -69,16 +70,16 @@ var self = module.exports = {
*/
makeBuildList: function ( modules, targets ) {
/**
* Given a list of modules and targets, returns an object splitting the scripts
* and styles.
*
* @param {Array} modules List of modules
* @param {Array} buildlist List of targets to work through
* @param {Object|null} filelist Object to extend
* @return {Object} Object of two arrays listing the file paths
*/
* Given a list of modules and targets, returns an object splitting the scripts
* and styles.
*
* @param {Array} modules List of modules
* @param {Array} buildlist List of targets to work through
* @param {Object|null} filelist Object to extend
* @return {Object} Object of two arrays listing the file paths
*/
function expandBuildList( modules, buildlist, filelist ) {
var build, moduleName, script, style;
let build, moduleName, script, style;

filelist = filelist || {};
filelist.scripts = filelist.scripts || [];
Expand Down Expand Up @@ -115,7 +116,7 @@ var self = module.exports = {
* @return {Array} Flat list of file paths
*/
buildDependencyList: function ( modules, load, list ) {
var i, module;
let i, module;

list = list || [];

Expand Down
4 changes: 3 additions & 1 deletion build/prependPaths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

function prependPaths( prefix, val ) {
var ob, k, v;
let ob, k, v;
if ( Array.isArray( val ) ) {
return val.map( function ( item ) {
return prependPaths( prefix, item );
Expand Down
29 changes: 14 additions & 15 deletions build/tasks/buildloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* Build a static loader file from a template
*/

'use strict';

module.exports = function ( grunt ) {

grunt.registerMultiTask( 'buildloader', function () {
var configScript,
styles = [],
const styles = [],
scripts = [],
loadedModules = [],
targetFile = this.data.targetFile,
Expand All @@ -21,17 +22,17 @@ module.exports = function ( grunt ) {
placeholders = this.data.placeholders || {},
dir = this.data.dir,
langList = this.data.langList !== undefined ? this.data.langList : true,
text = grunt.file.read( this.data.template ),
done = this.async(),
moduleUtils = require( '../moduleUtils' ),
stringifyObject = require( 'stringify-object' );
let text = grunt.file.read( this.data.template );

function scriptTag( src ) {
return indent + '<script src="' + pathPrefix + src.file + '"></script>';
}

function styleTag( group, src ) {
var rtlFilepath = src.file.replace( /\.css$/, '.rtl.css' );
const rtlFilepath = src.file.replace( /\.css$/, '.rtl.css' );

if ( grunt.file.exists( rtlFilepath ) ) {
if ( !dir ) {
Expand Down Expand Up @@ -64,38 +65,36 @@ module.exports = function ( grunt ) {
}

function placeholder( input, id, replacement, callback ) {
var output,
rComment = new RegExp( '<!-- ' + id + ' -->', 'm' );
const rComment = new RegExp( '<!-- ' + id + ' -->', 'm' );
if ( typeof replacement === 'function' ) {
replacement( function ( response ) {
output = input.replace( rComment, response );
const output = input.replace( rComment, response );
callback( output );
} );
} else {
output = input.replace( rComment, replacement );
const output = input.replace( rComment, replacement );
callback( output );
}
}

function addModules( load ) {
var module, moduleStyles, moduleScripts, dependency,
dependencies = moduleUtils.buildDependencyList( modules, load );
for ( dependency in dependencies ) {
module = dependencies[ dependency ];
const dependencies = moduleUtils.buildDependencyList( modules, load );
for ( const dependency in dependencies ) {
const module = dependencies[ dependency ];
if ( loadedModules.indexOf( module ) > -1 ) {
continue;
}
loadedModules.push( module );
if ( modules[ module ].scripts ) {
moduleScripts = modules[ module ].scripts
const moduleScripts = modules[ module ].scripts
.map( expand ).filter( filter.bind( this, 'scripts' ) ).map( scriptTag )
.join( '\n' );
if ( moduleScripts ) {
scripts.push( indent + '<!-- ' + module + ' -->\n' + moduleScripts );
}
}
if ( modules[ module ].styles ) {
moduleStyles = modules[ module ].styles
const moduleStyles = modules[ module ].styles
.map( expand ).filter( filter.bind( this, 'styles' ) ).map( styleTag.bind( styleTag, modules[ module ].styleGroup ) )
.join( '\n' );
if ( moduleStyles ) {
Expand All @@ -108,7 +107,7 @@ module.exports = function ( grunt ) {
addModules( load );

if ( i18n.length || demoPages ) {
configScript = indent + '<script>\n';
let configScript = indent + '<script>\n';

if ( i18n.length ) {
configScript +=
Expand Down
4 changes: 3 additions & 1 deletion build/tasks/git-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Change the in-memory package version to contain the git HEAD
*/

'use strict';

module.exports = function ( grunt ) {

grunt.registerTask( 'git-build', function () {
var done = this.async();
const done = this.async();
require( 'child_process' ).exec( 'git rev-parse HEAD', function ( err, stout, stderr ) {
if ( !stout || err || stderr ) {
grunt.log.error( err || stderr );
Expand Down
Loading