diff --git a/Gruntfile.js.sample b/Gruntfile.js.sample index 44c5e897dd3fa9757263e4081559201e1f51cc20..ec0cd43ec3c7302b0b7874d1d29fbf3d948bd00e 100644 --- a/Gruntfile.js.sample +++ b/Gruntfile.js.sample @@ -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/*'); diff --git a/dev/tools/grunt/configs/clean.js b/dev/tools/grunt/configs/clean.js index 792981a632ce638624a4142327298cb27e48fed8..d984620feb64742c984a6ac60a6b66a31b3cdc1e 100644 --- a/dev/tools/grunt/configs/clean.js +++ b/dev/tools/grunt/configs/clean.js @@ -5,7 +5,7 @@ 'use strict'; -var themes = require('./themes'), +var themes = require('../tools/files-router').getThemes(), _ = require('underscore'); var themeOptions = {}; diff --git a/dev/tools/grunt/configs/combo.js b/dev/tools/grunt/configs/combo.js index 930b2fd68715c7efbfe12906c5e291a35ae49e99..7dca3a268db2762cd730d0e0b6974feb95e424d7 100644 --- a/dev/tools/grunt/configs/combo.js +++ b/dev/tools/grunt/configs/combo.js @@ -5,7 +5,7 @@ 'use strict'; -var theme = require('./themes'), +var theme = require('../tools/files-router').getThemes(), path = require('./path'); /** diff --git a/dev/tools/grunt/configs/exec.js b/dev/tools/grunt/configs/exec.js index a26a0d95a54c63814d0a3d4f73001354e3d09d8a..ee06b371347829e77083726ed3825b58c449e4ae 100644 --- a/dev/tools/grunt/configs/exec.js +++ b/dev/tools/grunt/configs/exec.js @@ -6,7 +6,7 @@ 'use strict'; var combo = require('./combo'), - themes = require('./themes'), + themes = require('../tools/files-router').getThemes(), _ = require('underscore'); var themeOptions = {}; diff --git a/dev/tools/grunt/configs/less.js b/dev/tools/grunt/configs/less.js index 4071b47fa2b7ca347287564d412eb1702b3a5041..6f3b0f7ae6d99f73140f08251a3d89cc077887cb 100644 --- a/dev/tools/grunt/configs/less.js +++ b/dev/tools/grunt/configs/less.js @@ -6,7 +6,7 @@ 'use strict'; var combo = require('./combo'), - themes = require('./themes'), + themes = require('../tools/files-router').getThemes(), _ = require('underscore'); var themeOptions = {}; diff --git a/dev/tools/grunt/configs/watch.js b/dev/tools/grunt/configs/watch.js index 014b6b065a96fe3bdfa2d51136f24080fd144884..880b7f7e392dd1fa3fc11cf9e1ee289fac29e89f 100644 --- a/dev/tools/grunt/configs/watch.js +++ b/dev/tools/grunt/configs/watch.js @@ -6,7 +6,7 @@ 'use strict'; var combo = require('./combo'), - themes = require('./themes'), + themes = require('../tools/files-router').getThemes(), _ = require('underscore'); var themeOptions = {}; diff --git a/dev/tools/grunt/tools/files-router.js b/dev/tools/grunt/tools/files-router.js new file mode 100644 index 0000000000000000000000000000000000000000..dad794004ec26dcbcd0b6a38c73a207fb9b71afd --- /dev/null +++ b/dev/tools/grunt/tools/files-router.js @@ -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; + } +}; diff --git a/grunt-config.json.sample b/grunt-config.json.sample new file mode 100644 index 0000000000000000000000000000000000000000..7ef28a856f92529f71daac39e511a26d853184e2 --- /dev/null +++ b/grunt-config.json.sample @@ -0,0 +1,3 @@ +{ + "themes": "dev/tools/grunt/configs/local-themes" +}