-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
executable file
·200 lines (179 loc) · 3.85 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
'use strict';
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
var tasks = {
pkg: grunt.file.readJSON('package.json'),
vendor: grunt.file.readJSON('.bowerrc'),
name_asset: '<%= pkg.name.replace(/_/g, \'-\') %>',
// Clean
clean: {
assets: ['static/css', 'static/js'],
dev: ['build/dev'],
dist: ['build/dist'],
},
// Compiles LESS files to CSS
less: {
dev: {
paths: ['less/'],
src: ['less/main.less'],
dest: 'static/css/<%= name_asset %>.<%= pkg.version %>.css'
},
dist: {
paths: ['less/'],
src: ['less/main.less'],
dest: 'static/css/<%= name_asset %>.<%= pkg.version %>.min.css',
options: {
plugins: [
new (require('less-plugin-autoprefix'))({
browsers: ['> 0.1%']
}), new (require('less-plugin-clean-css'))({})
]
}
}
},
// Concatenate the JS
concat: {
options: {
stripBanners: true,
banner: '/* <%= pkg.name %> v<%= pkg.version %> | ' +
'<%= pkg.author.name %> */\n',
},
js: {
src: ['js/**/*.js'],
dest: 'static/js/<%= name_asset %>.<%= pkg.version %>.js',
}
},
// Uglyfy the JS
uglify: {
options: {
sourceMap: true
},
dist: {
src: 'static/js/<%= name_asset %>.<%= pkg.version %>.js',
dest: 'static/js/<%= name_asset %>.<%= pkg.version %>.min.js'
}
},
// Copy
copy: {
vendor: {
files: [
{
cwd: '<%= vendor.directory %>',
src: [ '**' ],
dest: 'static/lib/',
expand: true
}
]
}
},
// Wire the lib
wiredep: {
vendor: {
directory: 'static/lib/',
src: [ 'layouts/**/*.html' ],
onMainNotFound: function(pkg) {
var str = "The package `" + pkg + "` doesn't have a `main` field.";
grunt.log.errorlns(str['red']);
grunt.log.errorlns("More info: https://www.npmjs.com/package/wiredep#what-can-go-wrong");
},
}
},
// Bump
semver: {
release: {
files: [{
src: 'package.json',
dest: 'package.json'
}]
},
},
// Watch
watch: {
options: {
atBegin: true,
livereload: true
},
less: {
files: ['less/**/*.less'],
tasks: ['less:dev']
},
concat: {
files: ['js/**/*.js'],
tasks: ['concat:js']
},
hugo: {
files: ['static/**', 'layouts/**', 'config.toml'],
tasks: 'hugo:dev'
},
},
// Create live site
connect: {
website: {
options: {
hostname: 'localhost',
port: 9000,
protocol: 'http',
base: 'build/dev',
livereload: true
}
}
},
// Unit tests
nodeunit: {
tests: ['tests/*_test.js']
}
};
grunt.initConfig( tasks );
// Create the hugo task
grunt.registerTask('hugo', function(target) {
// Make it asynchronous
var done = this.async();
var args = [ '--destination=build/' + target ],
opts = { stdio: 'inherit' };
if (target === 'dev') {
args.push('--baseUrl=http://localhost:9000/');
args.push('--buildDrafts=true');
args.push('--buildFuture=true');
}
// Spawn the process
var p = require('child_process').spawn('hugo', args, opts),
events = { close: 'process closed', error: 'process error', exited: 'process exited' },
res = [];
for (var e in events) {
var text = events[e];
res.push(p.on(e, function(code) { console.log(text+' (code '+code+')'); return done(true); }));
}
return res;
});
// Register tasks
grunt.registerTask('test', [
'clean',
'dev',
'dist',
'nodeunit'
]);
grunt.registerTask('dev', [
'clean:assets',
'clean:dev',
'less:dev',
'concat:js',
'copy:vendor',
'hugo:dev'
]);
grunt.registerTask('dist', [
'clean:assets',
'clean:dist',
'less:dist',
'concat:js',
'uglify',
'copy:vendor',
'hugo:dist'
]);
grunt.registerTask('bump', 'Bump the package', function(param) {
param = param || 'patch';
grunt.task.run('semver:release:bump:' + param);
});
grunt.registerTask('default', [
'connect', 'watch'
]);
};