-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
185 lines (175 loc) · 4.61 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
182
183
184
185
/*
* bootUP
* https://github.com/albogdano/bootup
* Licensed under the MIT license.
*/
"use strict";
module.exports = function(grunt) {
var cssCopy = {
flatten: true,
expand: true,
cwd: "<%= site.templates %>/<%= site.template %>/css/",
src: ["*.*"],
dest: "<%= site.dest %>/css/"
};
var jsCopy = {
flatten: true,
expand: true,
cwd: "<%= site.templates %>/<%= site.template %>/js/",
src: ["*.*"],
dest: "<%= site.dest %>/js/"
};
var templateDir = "<%= site.templates %>/<%= site.template %>";
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
site: grunt.file.readJSON("assemble.json"),
// Build HTML from templates and data
assemble: {
options: {
flatten: true,
layouts: "<%= site.layouts %>",
layout: "<%= site.layout %>",
plugins: ["assemble-partial-data", "<%= site.plugins %>/*.js"],
helpers: ["handlebars-helper-mdpartial", "<%= site.helpers %>/*.js"],
partials: ["<%= site.partials %>/*.{html,md}", templateDir + "/partials/*.{html,md}"],
template: "<%= site.template %>",
templateDir: templateDir,
marked: {
breaks: true,
gfm: true,
highlight: function (code) {
return require("highlight.js").highlightAuto(code).value;
},
pedantic: true,
sanitize: false,
silent: false
},
// Metadata
pkg: "<%= pkg %>",
site: "<%= site %>"
},
htmls: {
files: {"<%= site.dest %>/": [templateDir + "/*.html"]}
},
phps: ("<%= assemble.options.template %>" === "modern-business") ? {
options: {ext: ".php"},
files: { "<%= site.dest %>/": [templateDir + "/contact.php"] }
} : {}
},
// Lint JavaScript
jshint: {
all: ["Gruntfile.js", "<%= site.helpers %>/{,*/}*.js", "<%= site.plugins %>/{,*/}*.js"],
options: {
jshintrc: ".jshintrc"
}
},
// Validate HTML
validation: {
options: {
reset: true,
stoponerror: false,
reportpath: false,
relaxerror: ["Bad value X-UA-Compatible for attribute http-equiv on element meta."] //ignores these errors
},
files: {
src: ["<%= site.dest %>/{,*/}*.html"]
}
},
// Prettify test HTML pages from Assemble task.
prettify: {
all: {
files: [
{expand: true, cwd: "<%= site.dest %>", src: ["*.html"], dest: "<%= site.dest %>/", ext: ".html"}
]
}
},
// concat and minify scripts
uglify: {
},
// copy files task
copy: {
content: {
files: [
cssCopy, jsCopy,
{flatten: true, expand: true, cwd: templateDir + "/img/", src: ["*.*"], dest: "<%= site.dest %>/img/"},
{flatten: true, expand: true, cwd: templateDir + "/", src: ["*.html", "*.php"], dest: "<%= site.dest %>/"}
]
},
misc: {
files: [
{expand: true, cwd: "<%= site.templates %>/misc", src: ["*.*"], dest: "<%= site.dest %>"},
]
},
onlycss: { files: [cssCopy] },
onlyjs: { files: [jsCopy] }
},
// Before generating new files remove files from previous build.
clean: {
options: {
force: true
},
dest: ["<%= site.dest %>/**"]
},
watch: {
assemble: {
files: [templateDir + "/{,*/}*.{md,yml,html}", "<%= site.layouts %>/*.html"],
tasks: ["assemble"]
},
css: {
files: templateDir + "/css/*.css",
tasks: ["copy:onlycss"],
options: {
livereload: true
}
},
js: {
files: templateDir + "/js/*.js",
tasks: ["copy:onlyjs"],
options: {
livereload: true
}
},
livereload: {
options: {
livereload: "<%= connect.options.livereload %>"
},
files: [
"<%= site.dest %>/{,*/}*.html",
"<%= site.dest %>/{,*/}*.{png,jpg,jpeg,gif,webp,svg}"
]
}
},
connect: {
options: {
port: 9000,
livereload: 35729,
// change this to "0.0.0.0" to access the server from outside
hostname: "localhost"
},
livereload: {
options: {
open: true,
base: [
"<%= site.dest %>"
]
}
}
}
});
// Load npm plugins to provide necessary tasks.
grunt.loadNpmTasks("grunt-assemble");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-prettify");
// Default tasks to be run.
grunt.registerTask("default", ["test", "copy:content", "assemble", "copy:misc", "prettify"]);
// Linting and tests.
grunt.registerTask("test", ["clean"]);
grunt.registerTask("validate", ["jshint"]); // html && js validation
grunt.registerTask("cb", ["clean", "default"]); // clean & build
grunt.registerTask("server", ["default", "connect:livereload", "watch"]); // watch & live reload
};