forked from chiel/express-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
83 lines (66 loc) · 1.37 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
'use strict';
var fs = require('fs');
module.exports = function(grunt){
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
var config = {
mkdir: {
all: {
options: {
create: ['public/css']
}
}
},
concurrent: {
dev: {
tasks: ['nodemon', 'watch'],
options: {
logConcurrentOutput: true
}
}
},
sass: {},
nodemon: {
dev: {}
},
watch: {}
};
var readCssDir = function(dir, target){
if (!fs.existsSync(dir)) return;
var count = 0, hasSubdirs, filePath,
name, input, output, globs;
fs.readdirSync(dir)
.forEach(function(fileName){
if (/^_/.test(fileName)) return;
if (!config.sass[target]){
config.sass[target] = {files: {}};
}
filePath = dir + '/' + fileName;
if (fs.statSync(filePath).isDirectory()){
hasSubdirs = true;
return;
}
name = fileName.match(/(.*)\.scss/)[1];
input = dir + '/' + name + '.scss';
output = 'public/css/' + name + '.css';
config.sass[target].files[output] = input;
count ++;
});
if (count > 0){
globs = [dir + '/*.scss'];
if (hasSubdirs){
globs.push(dir + '/**/*.scss');
}
config.watch[target] = {
files: globs,
tasks: ['sass:' + target]
};
}
};
readCssDir(__dirname + '/src/css', 'base');
grunt.initConfig(config);
grunt.registerTask('default', [
'mkdir',
'sass',
'concurrent:dev'
]);
};