diff --git a/Gruntfile.js.sample b/Gruntfile.js.sample index 44c5e897dd3f..ec0cd43ec3c7 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 792981a632ce..d984620feb64 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 930b2fd68715..7dca3a268db2 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 a26a0d95a54c..ee06b3713478 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 4071b47fa2b7..6f3b0f7ae6d9 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 014b6b065a96..880b7f7e392d 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 000000000000..dad794004ec2 --- /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 000000000000..7ef28a856f92 --- /dev/null +++ b/grunt-config.json.sample @@ -0,0 +1,3 @@ +{ + "themes": "dev/tools/grunt/configs/local-themes" +}