-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
153 lines (143 loc) · 3.69 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
/*
* 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", "helper-moment", "<%= site.helpers %>/*.js"],
partials: ["<%= site.partials %>/*.{html,md}", templateDir + "/partials/*.{html,md}"],
template: "<%= site.template %>",
templateDir: templateDir,
marked: {
breaks: false,
gfm: true,
highlight: function (code, lang) {
if (!lang) {
lang = "js";
}
return require("highlight.js").highlight(lang, code).value;
},
smartypants: true,
silent: false
},
// Metadata
pkg: "<%= pkg %>",
site: "<%= site %>"
},
htmls: {
files: {
"<%= site.dest %>/": [templateDir + "/*.html"],
"<%= site.dest %>/docs/": [templateDir + "/docs/*"]
}
}
},
// 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-watch");
grunt.loadNpmTasks("grunt-contrib-connect");
// Default tasks to be run.
grunt.registerTask("default", ["test", "copy:content", "assemble", "copy:misc"]);
// Linting and tests.
grunt.registerTask("test", ["clean"]);
grunt.registerTask("cb", ["clean", "default"]); // clean & build
grunt.registerTask("server", ["default", "connect:livereload", "watch"]); // watch & live reload
};