module.exports = function (grunt) {
'use strict';
var config, getTheme, file;
try {
config = grunt.file.readJSON('build.json');
} catch (err) {
console.info('build.json not found - using defaults');
config = {
'theme' : 'Twilight',
'color' : '#008080',
'image' : 'url(https://raw.githubusercontent.com/StylishThemes/GitHub-Dark/master/images/backgrounds/bg-tile1.png)',
'tiled' : true,
'attach' : 'scroll',
'tab' : 4,
'chrome' : false
};
}
getTheme = function () {
return (config.theme || '').toLowerCase().replace(/\s+/g, '-');
};
config.sourceFile = 'github-dark.css';
file = getTheme();
config.themeFile = file === '' || file === 'default' ? '' : 'themes/' + file + '.min.css';
config.buildFile = 'github-dark-' + (file ? file : 'default') + '-' + config.color.replace(/[^\d\w]/g, '') + '.build.min.css';
config.bgOptions = config.tiled ?
'background-repeat: repeat !important; background-size: auto !important; background-position: left top !important;' :
'background-repeat: no-repeat !important; background-size: cover !important; background-position: center top !important;';
config.bgOptions2 = config.attach.toLowerCase() === 'scroll' ?
'background-attachment: scroll !important;' :
'background-attachment: fixed !important;';
config.newTheme = config.themeFile ? '<%= grunt.file.read("' + config.themeFile + '") %>' : '';
file = grunt.file.read("github-dark.css").match(/(@-moz-document regexp\((.*)+\) \{(\n|\r)+)/);
config.prefix = file && file.length ? file[1].replace(/^\s+|\s+$/g, '') : '';
config.replacements = [{
pattern: /@-moz-document regexp\((.*)\) \{(\n|\r)+/,
replacement: ''
},{
pattern: /\/\*\[\[bg-choice\]\]\*\/ url\(.*\)/,
replacement: config.image
},{
pattern: '/*[[bg-options]]*/',
replacement: config.bgOptions
},{
pattern: '/*[[bg-options2]]*/',
replacement: config.bgOptions2
},{
pattern: /\/\*\[\[base-color\]\]\*\/ #4183C4/g,
replacement: config.color
},{
pattern: /\/\*\[\[tab-size\]\]\*\/ 4/g,
replacement: config.tab
},{
pattern: /\s+\/\* grunt build - remove to end of file(.*(\n|\r))+}$/m,
replacement: ''
},{
pattern: '/*[[syntax-theme]]*/',
replacement: config.newTheme
}];