Grunt and npm updates to support sass only mode

- again I didn't write any of this
- who do you think I am, a programmer?
parent ac2c61f0
Pipeline #968 failed with stage
in 33 seconds
{
"scripts": {
"postinstall": "cp -a ./bower_components/bootstrap/fonts ./"
}
}
......@@ -9,3 +9,24 @@ _config.yml
bower.json
Gruntfile.js
*/index.html
2/
3/
assets/
bower_components/
custom/
default/
global/
help/
tests/
_config.yml
.bowerrc
.gitignore
.travis.yml
bower.json
CNAME
composer.json
favicon.ico
Gemfile
Gruntfile.js
index.html
*/index.html
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
var configBridge = grunt.file.readJSON('./bower_components/bootstrap/grunt/configBridge.json', { encoding: 'utf8' });
grunt.loadNpmTasks('grunt-exec');
// Project configuration.
grunt.initConfig({
// Define some variables and options
pkg: grunt.file.readJSON('package.json'),
builddir: '.',
buildtheme: '',
banner: '/*!\n' +
' * <%= pkg.name %> v<%= pkg.version %>\n' +
' * Homepage: <%= pkg.homepage %>\n' +
' * Copyright 2012-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license %>\n' +
' * Based on Bootstrap\n' +
'*/\n',
swatch: {
masonstrap:{}
},
swatch: { masonstrap:{} },
clean: {
build: {
src: ['*/build.less', '*/build.scss', '!global/build.less', '!global/build.scss']
src: ['*/build.scss', '!assets/scss/build.scss']
}
},
concat: {
......@@ -39,25 +35,13 @@ module.exports = function (grunt) {
dest: ''
}
},
less: {
dist: {
options: {
compress: false,
strictMath: true
},
files: {}
}
},
autoprefixer: {
options: {
browsers: configBridge.config.autoprefixerBrowsers
},
dist: {
src: '*/masonstrap.css'
exec: {
postcss: {
command: 'npm run postcss'
}
},
watch: {
files: ['*/variables.less', '*/bootswatch.less', '*/index.html'],
files: ['*/_variables.scss', '*/_bootswatch.scss', '*/index.html'],
tasks: 'build',
options: {
livereload: true,
......@@ -83,43 +67,13 @@ module.exports = function (grunt) {
}
});
// Default task (does nothing)
grunt.registerTask('none', function() {});
grunt.registerTask('build', 'build a regular theme', function(theme, compress) {
var theme = theme == undefined ? grunt.config('buildtheme') : theme;
var compress = compress == undefined ? true : compress;
var isValidTheme = grunt.file.exists(theme, 'variables.less') && grunt.file.exists(theme, 'bootswatch.less');
// cancel the build (without failing) if this directory is not a valid theme
if (!isValidTheme) {
return;
}
var concatSrc;
var concatDest;
var lessDest;
var lessSrc;
var files = {};
var dist = {};
concatSrc = 'global/build.less';
concatDest = theme + '/build.less';
lessDest = '<%=builddir%>/' + theme + '/masonstrap.css';
lessSrc = [ theme + '/' + 'build.less' ];
dist = {src: concatSrc, dest: concatDest};
grunt.config('concat.dist', dist);
files = {}; files[lessDest] = lessSrc;
grunt.config('less.dist.files', files);
grunt.config('less.dist.options.compress', false);
grunt.task.run(['concat', 'less:dist', 'prefix:' + lessDest, 'clean:build',
compress ? 'compress:'+lessDest+':'+'<%=builddir%>/' + theme + '/masonstrap.min.css':'none']);
});
grunt.registerTask('build_scss', 'build a regular theme from scss', function(theme, compress) {
var theme = theme == undefined ? grunt.config('buildtheme') : theme;
var compress = compress == undefined ? true : compress;
//
grunt.registerTask('build', 'build a regular theme from scss', function(theme, compress) {
theme = theme === undefined ? grunt.config('buildtheme') : theme;
compress = compress === undefined ? true : compress;
var isValidTheme = grunt.file.exists(theme, '_variables.scss') && grunt.file.exists(theme, '_bootswatch.scss');
......@@ -133,9 +87,9 @@ grunt.registerTask('build_scss', 'build a regular theme from scss', function(the
var scssSrc;
var files = {};
var dist = {};
concatSrc = 'global/build.scss';
concatSrc = 'assets/scss/build.scss';
concatDest = theme + '/build.scss';
scssDest = '<%=builddir%>/' + theme + '/masonstrap.css';
scssDest = '<%=builddir%>/' + theme + '/bootstrap.css';
scssSrc = [theme + '/' + 'build.scss'];
dist = {src: concatSrc, dest: concatDest};
......@@ -144,28 +98,17 @@ grunt.registerTask('build_scss', 'build a regular theme from scss', function(the
files[scssDest] = scssSrc;
grunt.config('sass.dist.files', files);
grunt.config('sass.dist.options.style', 'expanded');
grunt.config('sass.dist.options.sourcemap', 'none');
grunt.config('sass.dist.options.precision', 8);
grunt.config('sass.dist.options.unix-newlines', true);
grunt.task.run(['concat', 'sass:dist', 'prefix:' + scssDest, 'clean:build',
compress ? 'compress_scss:' + scssDest + ':' + '<%=builddir%>/' + theme + 'masonstrap.min.css' : 'none']);
});
grunt.registerTask('prefix', 'autoprefix a generic css', function(fileSrc) {
grunt.config('autoprefixer.dist.src', fileSrc);
grunt.task.run('autoprefixer');
//
grunt.task.run(['concat', 'sass:dist', 'exec:postcss', 'clean:build',
compress ? 'compress:' + scssDest + ':' + '<%=builddir%>/' + theme + '/bootstrap.min.css' : 'none']);
});
grunt.registerTask('compress', 'compress a generic css', function(fileSrc, fileDst) {
var files = {}; files[fileDst] = fileSrc;
grunt.log.writeln('compressing file ' + fileSrc);
grunt.config('less.dist.files', files);
grunt.config('less.dist.options.compress', true);
grunt.task.run(['less:dist']);
});
grunt.registerTask('compress_scss', 'compress a generic css with sass', function(fileSrc, fileDst) {
//
grunt.registerTask('compress', 'compress a generic css with sass', function(fileSrc, fileDst) {
var files = {}; files[fileDst] = fileSrc;
grunt.log.writeln('compressing file ' + fileSrc);
......@@ -179,14 +122,14 @@ grunt.registerTask('build_scss', 'build a regular theme from scss', function(the
grunt.task.run('build:'+t);
});
grunt.registerTask('swatch_scss', 'build a theme from scss ', function (theme) {
grunt.registerTask('swatch', 'build a theme from scss ', function (theme) {
var t = theme;
if (!t) {
for (var t in grunt.config('swatch')) {
grunt.task.run('build_scss:' + t);
for (t in grunt.config('swatch')) {
grunt.task.run('build:' + t);
}
} else {
grunt.task.run('build_scss:' + t);
grunt.task.run('build:' + t);
}
});
......@@ -196,62 +139,9 @@ grunt.registerTask('build_scss', 'build a regular theme from scss', function(the
grunt.config('buildtheme', theme);
});
/**
* Regex borrowed form
* https://gist.github.com/rosskevin/ddfe895091de2ca5f931
* */
grunt.registerTask('convert_less', 'Convert less to scss using regular expression', function () {
var convertBaseDir = '';
grunt.file.expand(convertBaseDir + '*/*.less').forEach(function (lessFile) {
if (lessFile !=="global/build.less"){
var srcContents = grunt.file.read(lessFile);
var out = srcContents
// 1. replace @ with $
.replace(/@(?!import|media|keyframes|-)/g, '$')
// 2. replace mixins
.replace(/[\.#](?![0-9])([\w\-]*)\s*\((.*)\)\s*\{/g, '@mixin $1($2){')
// 3. In LESS, bootstrap namespaces mixins, in SASS they are just prefixed e.g #gradient > .vertical-three-colors becomes @include gradient-vertical-three-colors
.replace(/[\.#](?![0-9])([\w\-]*)\s>\s\.(.*;)/g, '@include $1-$2')
// 4. replace includes
.replace(/[\.#](?![0-9])([\w\-].*\(.*;)/g, '@include $1')
// 5. replace no param mixin includes with empty parens
.replace(/@include\s([\w\-]*\s*);/g, '@include $1();')
// 6. replace extends .class; @extend .class;
.replace(/(\.(?![0-9])([\w\-]+);)/g, '@extend $1')
// 7. replace string literals
.replace(/~"(.*)"/g, '#{"$1"}')
// 8. replace interpolation ${var} > #{$var}
.replace(/\$\{(.*)\}/g, '#{$$$1}')
// 9. replace spin to adjust-hue (function name diff)
.replace(/spin\(/g, 'adjust-hue(')
// 10. replace bower and imports in build.scss
.replace(/bootstrap\/less\//g, 'bootstrap-sass-official/assets/stylesheets/')
.replace(/\.less/g, '')
// 11. replace icon-font-path value with conditional for asset helpers
.replace(/(\$icon-font-path:).*;/g, '$1 if($bootstrap-sass-asset-helper, "bootstrap/", "../fonts/bootstrap/");')
// 12. set bootswatch's web-font-path value as !default
.replace(/(\$web-font-path:.*);/g, '$1 !default;')
// 13. Remove the web-font mixin which breaks in libsass
.replace(/[\s\S][\s\S]@mixin web-font.*([\s\S]*?).*;([\s\S]*?)}([\s\S]*?)/,"")
// 14. Replace usage of the web-font mixin with variable interpolation
.replace(/@include web-font/,'@import url');
if (/\/variables.less$/.test(lessFile)) {
// 15. set default value of $bootstrap-sass-asset-helper to false
out = "$bootstrap-sass-asset-helper: false;\n" + out;
// 16. only assign variables if they haven't been previously set e.g. $var: #f00; > $var: #f00 !default;
out = out.replace(/^(\$.*);/gm, '$1 !default;');
}
var baseDirRegex = new RegExp("^" + convertBaseDir, "g");
var sassFile = lessFile.replace(baseDirRegex, '').replace(/\.less$/, '.scss').replace(/(bootswatch|variables)/, '_$1');
grunt.file.write(sassFile, out);
grunt.log.writeln('Converted less file: ', lessFile, Array(27 - lessFile.length).join(' '),'> ', sassFile);
}
});
});
grunt.registerTask('postcss', 'exec:postcss');
grunt.registerTask('server', 'connect:keepalive');
grunt.registerTask('default', ['swatch', 'connect:base', 'watch']);
grunt.registerTask('default', ['connect:base', 'watch']);
};
exclude: ["src", "node_modules", "bower.json", "bower_components/font-awesome/src", "package.json", "README.md", "Gruntfile.js"]
exclude: ["src", "node_modules", "bower.json", "bower_components/font-awesome/src", "composer.json", "package.json", "README.md", "LICENSE", "Gruntfile.js", "Gemfile"]
include: ["_bootswatch.scss","_variables.scss"]
......@@ -21,12 +21,9 @@
"*/index.html"
],
"dependencies": {
"bootstrap": "~3.3.7"
"bootstrap": "~4.0.0"
},
"devDependencies": {
"bootstrap-sass-official": "~3.3.7",
"font-awesome": "~4.7.0",
"html5shiv": "~3.7.3",
"respond": "~1.4.2"
"font-awesome": "~4.7.0"
}
}
{
"name": "Masonstrap",
"description": "Easily provide any web project with Mason branding",
"version": "3.3.7",
"version": "4.0.0-alpha.6",
"author": "Mason SRCT",
"homepage": "srct.gmu.edu",
"license": "MIT",
......@@ -12,15 +12,21 @@
"engines": {
"node": ">= 6.10.0"
},
"scripts": {
"postcss": "postcss --config assets/js/postcss.js --replace */bootstrap*.css"
},
"devDependencies": {
"bower": "~1.8.0",
"grunt": "~1.0.1",
"grunt-autoprefixer": "~3.0.4",
"grunt-contrib-clean": "~1.0.0",
"grunt-contrib-concat": "~1.0.1",
"grunt-contrib-connect": "~1.0.2",
"grunt-contrib-less": "~1.4.0",
"grunt-contrib-sass": "~1.0.0",
"grunt-contrib-watch": "~1.0.0"
"autoprefixer": "^6.5.0",
"bower": "~1.2.8",
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-exec": "^1.0.1",
"postcss-cli": "^2.6.0",
"postcss-flexbugs-fixes": "^2.0.0"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment