Skip to content

Commit

Permalink
MAGETWO-55345: Grunt uses actual theme's list
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets committed Aug 23, 2016
1 parent 3ef1e28 commit 5c76ada
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

// For performance use one level down: 'name/{,*/}*.js'
// If you want to recursively match all subfolders, use: 'name/**/*.js'

module.exports = function (grunt) {
'use strict';

var _ = require('underscore'),
path = require('path'),
themes = require('./dev/tools/grunt/configs/themes'),
themes = require('./dev/tools/grunt/tools/files-router').getThemes(),
configDir = './dev/tools/grunt/configs',
tasks = grunt.file.expand('./dev/tools/grunt/tasks/*');

Expand Down
2 changes: 1 addition & 1 deletion dev/tools/grunt/configs/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

var themes = require('./themes'),
var themes = require('../tools/files-router').getThemes(),
_ = require('underscore');

var themeOptions = {};
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/grunt/configs/combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

var theme = require('./themes'),
var theme = require('../tools/files-router').getThemes(),
path = require('./path');

/**
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/grunt/configs/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

var combo = require('./combo'),
themes = require('./themes'),
themes = require('../tools/files-router').getThemes(),
_ = require('underscore');

var themeOptions = {};
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/grunt/configs/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

var combo = require('./combo'),
themes = require('./themes'),
themes = require('../tools/files-router').getThemes(),
_ = require('underscore');

var themeOptions = {};
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/grunt/configs/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

var combo = require('./combo'),
themes = require('./themes'),
themes = require('../tools/files-router').getThemes(),
_ = require('underscore');

var themeOptions = {};
Expand Down
60 changes: 60 additions & 0 deletions dev/tools/grunt/tools/files-router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

'use strict';

module.exports = {
defaultConfig: {
'themes': 'dev/tools/grunt/configs/themes'
},

/**
* Immediately invoked function.
* Loads user config file.
*/
userConfig: (function () {
try {
return require(process.cwd() + '/grunt-config');
} catch (error) {
return null;
}
})(),

/**
* Loads "themes" file.
* Load priority:
* From user config;
* From default config with ".loc" suffix ;
* From default config;
*
* @returns themes file or error
*/
getThemes: function () {
if (this.userConfig && this.userConfig.themes) {
return require(this.getFullPath(this.userConfig.themes));
} else {
try {
return require(this.getFullPath(this.defaultConfig.themes + '.loc'));
} catch (error) {
try {
return require(this.getFullPath(this.defaultConfig.themes));
} catch (error) {
throw error;
}
}
}
},

/**
* Generates full path to file.
*
* @param {String} path - relative path to file.
*
* @returns {String} Full path to file
*/
getFullPath: function (path) {
return process.cwd() + '/' + path;
}
};
3 changes: 3 additions & 0 deletions grunt-config.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"themes": "dev/tools/grunt/configs/local-themes"
}

0 comments on commit 5c76ada

Please sign in to comment.