forked from thomaspark/bootswatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
181 lines (165 loc) · 4.97 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-sass');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
builddir: 'dist',
buildtheme: '',
banner: '/*!\n' +
' * Bootswatch v<%= pkg.version %>\n' +
' * Homepage: <%= pkg.homepage %>\n' +
' * Copyright 2012-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license %>\n' +
' * Based on Bootstrap\n' +
'*/\n',
swatch: {
cerulean:{},
cosmo:{},
cyborg:{},
darkly:{},
flatly:{},
journal:{},
litera:{},
lumen:{},
lux:{},
materia:{},
minty:{},
pulse:{},
sandstone:{},
simplex:{},
sketchy:{},
slate:{},
solar:{},
spacelab:{},
superhero:{},
united:{},
yeti:{}
},
clean: {
build: {
src: ['dist/*/build.scss']
}
},
concat: {
options: {
banner: '<%= banner %>',
stripBanners: false
},
dist: {
src: [],
dest: ''
}
},
copy: {
vendor: {
files: [
{expand: true, cwd: 'node_modules/font-awesome', src: ['css/**', 'fonts/**'], dest: 'docs/_vendor/font-awesome/'},
{expand: true, cwd: 'node_modules/jquery', src: ['dist/**'], dest: 'docs/_vendor/jquery/'},
{expand: true, cwd: 'node_modules/bootstrap', src: ['dist/**'], dest: 'docs/_vendor/bootstrap/'},
{expand: true, cwd: 'node_modules/popper.js', src: ['dist/**'], dest: 'docs/_vendor/popper.js/'}
]
},
css: {
files: [
{expand: true, cwd: 'dist', src: ['**/*.css', '**/*.scss'], dest: 'docs/4/'},
]
}
},
exec: {
postcss: {
command: 'npm run postcss'
}
},
watch: {
files: ['dist/*/_variables.scss', 'dist/*/_bootswatch.scss'],
tasks: 'build',
options: {
livereload: true,
nospawn: true
}
},
connect: {
base: {
options: {
base: 'docs',
port: 3000,
livereload: true,
open: true
}
},
keepalive: {
options: {
port: 3000,
livereload: true,
keepalive: true,
open: true
}
}
}
});
grunt.registerTask('none', function() {});
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('dist/' + theme, '_variables.scss') && grunt.file.exists('dist/' + theme, '_bootswatch.scss');
// cancel the build (without failing) if this directory is not a valid theme
if (!isValidTheme) {
return;
}
var concatSrc;
var concatDest;
var scssDest;
var scssSrc;
var files = {};
var dist = {};
concatSrc = 'build/scss/build.scss';
concatDest = 'dist/' + theme + '/build.scss';
scssSrc = 'dist/' + theme + '/build.scss';
scssDest = '<%=builddir%>/' + theme + '/bootstrap.css';
dist = {src: concatSrc, dest: concatDest};
grunt.config('concat.dist', dist);
files = {};
files[scssDest] = scssSrc;
grunt.config('sass.dist.files', files);
grunt.config('sass.dist.options.outputStyle', 'expanded');
grunt.task.run(['concat', 'sass:dist', 'postcss', 'clean:build',
compress ? 'compress:' + scssDest + ':' + '<%=builddir%>/' + theme + '/bootstrap.min.css' : 'none',
'copy:css']);
});
grunt.registerTask('compress', 'compress a generic css with sass', 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.outputStyle', 'compressed');
grunt.task.run(['sass:dist']);
});
grunt.registerMultiTask('swatch', 'build a theme', function() {
var t = this.target;
grunt.task.run('build:'+t);
});
grunt.registerTask('swatch', 'build a theme from scss ', function (theme) {
var t = theme;
if (!t) {
for (t in grunt.config('swatch')) {
grunt.task.run('build:' + t);
}
} else {
grunt.task.run('build:' + t);
}
});
grunt.event.on('watch', function(action, filepath) {
var path = require('path');
var theme = path.basename(path.dirname(filepath));
console.log(theme);
grunt.config('buildtheme', theme);
});
grunt.registerTask('vendor', 'copy:vendor');
grunt.registerTask('postcss', 'exec:postcss');
grunt.registerTask('server', 'connect:keepalive');
grunt.registerTask('default', ['connect:base', 'watch']);
};