This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathGruntfile.js
138 lines (120 loc) · 4.34 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
builddir: '.',
meta: {
banner: '/**\n' +
' * <%= pkg.description %>\n' +
' * @version v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @license <%= pkg.license %>' + ' */'
},
convert_less: {
default_options: {
files: [{
expand: true,
src: ['**/*.less']
}],
extension: '.scss'
}
},
swatch: {
amelia:{}, cerulean:{}, cosmo:{}, cyborg:{}, flatly:{}, journal:{},
readable:{}, simplex:{}, slate:{}, spacelab:{}, united:{},
custom:{}
},
clean: {
build: {
src: ['*/build.scss', '!global/build.scss']
}
},
concat: {
dist: {
src: [],
dest: ''
}
},
sass: {
dist: {
options: {
style: 'nested'
},
files: {}
}
}
});
grunt.registerTask('none', function() {});
grunt.registerMultiTask('convert_less', 'naively convert less to scss (may require some debugging)', function() {
//grunt.log.writeln('---', this.files);
this.files.forEach(function(f) {
f.src.filter(function(filepath) {
if (filepath.indexOf('node_modules') !== -1) {
return false;
} else {
return true;
}
}).forEach(function(f) {
var srcContents = grunt.file.read(f);
var out = srcContents.replace(/@/g, '$')
.replace(/\.([\w\-]*)\s*\((.*)\)\s*\{/g, '@mixin $1\($2\) {\n')
.replace(/\.([\w\-]*\(.*\)\s*;)/g, '@include $1')
.replace(/~"(.*)"/g, '#{"$1"}')
.replace(/\$(media|font-face|import)/g, '@$1')
.replace(/bootstrap\/less\//g, 'sass-bootstrap/lib/')
.replace(/less/g, 'scss')
.replace(/spin\(/g, 'adjust-hue(')
.replace(/\#gradient\ \>\ \@include\ vertical/g, '@include gradient-vertical');
if (out.match(/&-/g)) {
grunt.log.warn("This file may contain illegal parent selector usage (.navbar { &-brand {}}) that will have to be manually refactored", f);
var howto = "";
grunt.log.warn(howto);
}
var dest = f.replace(/\.less$/, '.scss')
.replace(/(bootswatch|variables)/, '_$1');
grunt.file.write(dest, out);
grunt.log.writeln('Converted less file:', f);
});
});
});
grunt.registerTask('build', 'build a regular theme', function(theme, compress) {
var compress = compress == undefined ? true : compress;
var concatSrc;
var concatDest;
var sassDest;
var sassSrc;
var files = {};
var dist = {};
concatSrc = 'global/build.scss';
concatDest = theme + '/build.scss';
sassDest = '<%=builddir%>/' + theme + '/bootstrap.css';
sassSrc = [ theme + '/' + 'build.scss' ];
dist = {src: concatSrc, dest: concatDest};
grunt.config('concat.dist', dist);
files = {}; files[sassDest] = sassSrc;
grunt.config('sass.dist.files', files);
grunt.config('sass.dist.options.style', 'nested');
grunt.task.run(['concat', 'sass:dist', 'clean:build',
compress ? 'compress:'+sassDest+':'+'<%=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('sass.dist.files', files);
grunt.config('sass.dist.options.style', 'compressed');
grunt.task.run(['sass:dist']);
});
grunt.registerMultiTask('swatch', 'build a theme', function() {
var t = this.target;
grunt.log.writeln('target', t);
grunt.task.run('build:'+t);
});
grunt.registerTask('default', 'build a theme', function() {
grunt.task.run('swatch');
});
};