forked from xibyte/jsketcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
64 lines (56 loc) · 1.5 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
'use strict'
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const del = require('del');
const exec = require('child_process').exec;
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
function dirFilter(dirsToFilter) {
return (path) => {
for (let dir of dirsToFilter) {
if (path.startsWith(dir + '/') || path == dir) {
return false;
}
}
return true;
}
}
grunt.initConfig({
copy: {
resources: {
expand: true,
cwd: 'web',
src: '**',
dest: 'dist/',
filter: dirFilter(['web/app', 'web/test'])
}
}
});
grunt.registerTask('clean', function() {
del.sync('dist');
});
grunt.registerTask('build', function() {
const done = this.async();
webpack(webpackConfig, function (error) {
if (error) {
console.log('webpack failed');
console.log(error);
}
done();
});
});
grunt.registerTask('show-revision', function() {
const done = this.async();
exec('git rev-parse --short HEAD', (err, stdout, stderr) => {
grunt.log.writeln(stdout);
done();
});
});
grunt.registerTask('mark-revision', function() {
const done = this.async();
exec('mkdir -p dist && git rev-parse HEAD > dist/.rev', function (err, stdout, stderr) {
done(err);
});
});
grunt.registerTask('default', ['clean', 'build', 'copy:resources', 'mark-revision', 'show-revision']);
};