Skip to content

Commit

Permalink
Merge pull request #295 from magento-frontend/MAGETWO-55345
Browse files Browse the repository at this point in the history
MAGETWO-55345 Grunt uses actual theme's list
  • Loading branch information
Yaroslav Onischenko authored Aug 29, 2016
2 parents 8744435 + ee2ce79 commit 0353379
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 7 deletions.
9 changes: 7 additions & 2 deletions Gruntfile.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

// 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'),
filesRouter = require('./dev/tools/grunt/tools/files-router'),
configDir = './dev/tools/grunt/configs',
tasks = grunt.file.expand('./dev/tools/grunt/tasks/*');
tasks = grunt.file.expand('./dev/tools/grunt/tasks/*'),
themes;

filesRouter.set('themes', 'dev/tools/grunt/configs/themes');
themes = filesRouter.get('themes');

tasks = _.map(tasks, function(task){ return task.replace('.js', '') });
tasks.push('time-grunt');
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').get('themes'),
_ = 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').get('themes'),
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').get('themes'),
_ = 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').get('themes'),
_ = 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').get('themes'),
_ = require('underscore');

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

'use strict';

var defaultConfig = {},

/**
* 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;
},

/**
* Returns file.
*
* @param {String} path - relative path to file.
*
* @returns {Object|Null} File or NULL
*/
getFile = function (path) {
try {
return require(getFullPath(path));
} catch (error) {
return null;
}
},

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

module.exports = {

/**
* Loads file.
* Load priority:
* From user config;
* From default config with ".loc" suffix ;
* From default config;
*
* @param {String} alias
*
* @returns {Object} themes file or error
*/
get: function (alias) {
var tmp;

if (userConfig && userConfig[alias]) {
return require(getFullPath(userConfig[alias]));
} else if (tmp = getFile(defaultConfig[alias] + '.loc') || getFile(defaultConfig[alias])) {
return tmp;
} else {
throw new Error('Cannot find file. Alias "' + alias + '" not set. ' +
'Use "filesRouter.set" method to set it.').stack;
}
},

/**
* Sets file alias.
*
* @param {String} alias
* @param {String} path
*/
set: function (alias, path) {
defaultConfig[alias] = 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 0353379

Please sign in to comment.