-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
178 lines (154 loc) · 3.99 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
module.exports = function(grunt) {
//cfg of stock tasks
grunt.initConfig({
copy: {
build: {
cwd: 'src',
src: ['**', '!markup/**', '!styles/**'],
dest: 'dist',
expand:true,
dot:true
}
},
frontmatter: {
build: {
options: {
minify: false,
width:60
},
files: {
'src/markup/yaml.json': ['src/markup/pages/*.pug']
}
}
},
pug: {
build: {
options: {
pretty:true,
debug:false,
basedir: 'src/markup',
data: function(dest,src) {
//read json made by frontmatter task - concats all yaml into one file
var fs = require('fs');
var yaml = JSON.parse(fs.readFileSync('src/markup/yaml.json','utf8'));
//get filename of current pug page currently being compiled
var filename = src[0].replace('src/markup/pages/', '').replace('.pug', '').split('/').pop();
//loop through json of all page YAMLs to find the one page YAML that matches the pug page currently being compiled
var pageYAML = null;
for(object in yaml) {
if(yaml[object]['section'] === filename) {
pageYAML = yaml[object];
}
}
//return the pageYAML found above
return {
from: src,
to: dest,
page: pageYAML
};
}
},
files: [{
cwd: 'src/markup/pages',
dest: 'dist/',
src: ['**/*.pug'],
expand:true,
filter: 'isFile',
ext: '.html'
}]
}
},
sass: {
build: {
options: {
style: 'expanded',
sourceMap: true
},
// files: [{
// expand: true,
// src: ['**/*.scss', '!**/_*.scss'],
// cwd: 'src/styles',
// dest: 'dist/css',
// ext: '.css'
// }]
files: {
'dist/css/styles.css' : 'src/styles/styles.scss'
}
}
},
clean: {
build: {
src: ['dist']
}
},
autoprefixer: {
build: {
expand:true,
cwd: 'dist',
src: ['**/*.css'],
dest: 'dist'
}
},
watch: {
options: {
dot: true,
interrupt: false,
livereload: true,
livereloadOnError: false,
spawn: false
},
markup: {
files: ['src/markup/**/*.pug', '!src/markup/pages/**/*.pug'],
tasks: ['markup:build']
},
markup_pages: {
files: ['src/markup/pages/**/*.pug'],
tasks: ['markup:watch']
},
styles: {
files: ['src/styles/**/*.scss'],
tasks: ['styles:build']
},
data: {
files: ['src/data/**'],
tasks: ['data:watch']
},
js: {
files: ['src/js/**'],
tasks: ['newer:copy']
}
},
connect: {
build: {
options: {
hostname: '*',
// hostname: '<%= grunt.config.get("ip") %>',
port: 3000,
base: 'dist/',
target: 'http://localhost:3000',
appName: 'open',
open: true,
livereload: true
}
}
}
});
//loading of stock tasks
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-pug');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-frontmatter');
grunt.loadNpmTasks('grunt-newer');
//defining of custom tasks for CLI use
grunt.registerTask('markup:build', ['frontmatter', 'pug']);
grunt.registerTask('markup:watch', ['frontmatter', 'newer:pug']);
grunt.registerTask('styles:build', ['sass', 'autoprefixer']);
grunt.registerTask('styles:watch', ['newer:sass', 'newer:autoprefixer']);
grunt.registerTask('data:watch', ['newer:copy']);
grunt.registerTask('default','Creates build and serves it for dev purposes', ['clean','copy', 'markup:build', 'styles:build', 'connect', 'watch']);
grunt.registerTask('prod','Creates prod build in dist directory', ['clean','copy', 'markup:build', 'styles:build']);
};