Skip to content

Commit 494cdbc

Browse files
committed
MAGETWO-55345: Grunt uses actual theme's list
1 parent c4a1a49 commit 494cdbc

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

Gruntfile.js.sample

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ module.exports = function (grunt) {
1111

1212
var _ = require('underscore'),
1313
path = require('path'),
14-
themes = require('./dev/tools/grunt/tools/files-router').get('themes'),
14+
filesRouter = require('./dev/tools/grunt/tools/files-router'),
1515
configDir = './dev/tools/grunt/configs',
16-
tasks = grunt.file.expand('./dev/tools/grunt/tasks/*');
16+
tasks = grunt.file.expand('./dev/tools/grunt/tasks/*'),
17+
themes;
18+
19+
filesRouter.set('themes', 'dev/tools/grunt/configs/themes')
20+
themes = filesRouter.get('themes')
1721

1822
tasks = _.map(tasks, function(task){ return task.replace('.js', '') });
1923
tasks.push('time-grunt');

dev/tools/grunt/tools/files-router.js

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,47 @@
55

66
'use strict';
77

8-
module.exports = {
9-
defaultConfig: {
10-
'themes': 'dev/tools/grunt/configs/themes'
8+
var defaultConfig = {},
9+
10+
/**
11+
* Generates full path to file.
12+
*
13+
* @param {String} path - relative path to file.
14+
*
15+
* @returns {String} Full path to file
16+
*/
17+
getFullPath = function (path) {
18+
return process.cwd() + '/' + path;
19+
},
20+
21+
/**
22+
* Returns file.
23+
*
24+
* @param {String} path - relative path to file.
25+
*
26+
* @returns {Object|Null} File or NULL
27+
*/
28+
getFile = function (path) {
29+
try {
30+
return require(getFullPath(path));
31+
} catch (error) {
32+
return null;
33+
}
1134
},
1235

1336
/**
1437
* Immediately invoked function.
1538
* Loads user config file.
1639
*/
17-
userConfig: (function () {
40+
userConfig = (function () {
1841
try {
1942
return require(process.cwd() + '/grunt-config');
2043
} catch (error) {
2144
return null;
2245
}
23-
})(),
46+
})();
47+
48+
module.exports = {
2449

2550
/**
2651
* Loads file.
@@ -29,32 +54,30 @@ module.exports = {
2954
* From default config with ".loc" suffix ;
3055
* From default config;
3156
*
32-
* @returns themes file or error
57+
* @param {String} alias
58+
*
59+
* @returns {Object} themes file or error
3360
*/
34-
get: function (file) {
35-
if (this.userConfig && this.userConfig[file]) {
36-
return require(this.getFullPath(this.userConfig[file]));
61+
get: function (alias) {
62+
var tmp;
63+
64+
if (userConfig && userConfig[alias]) {
65+
return require(getFullPath(userConfig[alias]));
66+
} else if (tmp = getFile(defaultConfig[alias] + '.loc') || getFile(defaultConfig[alias])) {
67+
return tmp;
3768
} else {
38-
try {
39-
return require(this.getFullPath(this.defaultConfig[file] + '.loc'));
40-
} catch (error) {
41-
try {
42-
return require(this.getFullPath(this.defaultConfig[file]));
43-
} catch (error) {
44-
throw error;
45-
}
46-
}
69+
throw new Error('Cannot find file. Alias "' + alias + '" not set. ' +
70+
'Use "filesRouter.set" method to set it.').stack;
4771
}
4872
},
4973

5074
/**
51-
* Generates full path to file.
75+
* Sets file alias.
5276
*
53-
* @param {String} path - relative path to file.
54-
*
55-
* @returns {String} Full path to file
77+
* @param {String} alias
78+
* @param {String} path
5679
*/
57-
getFullPath: function (path) {
58-
return process.cwd() + '/' + path;
80+
set: function (alias, path) {
81+
defaultConfig[alias] = path;
5982
}
6083
};

0 commit comments

Comments
 (0)