-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gruntfile.js
118 lines (106 loc) · 3.04 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
var fs = require("fs");
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
// Package.json.
pkg: grunt.file.readJSON('package.json'),
// Copy everything to dist directory.
copy: {
main: {
files: [
{
expand: true,
cwd: 'src/',
src: '**',
dest: 'dist/'
}
]
}
},
// Compile scripts & styles together.
useref: {
html: "dist/app.html",
temp: "dist"
},
// Remove unnecessary files.
clean: {
release: [
// Remoeve everything.
'dist/**/*',
// Except..
'!dist/app.html',
'!dist/manifest.json',
'!dist/manifest.mobile.json',
'!dist/background.js',
'!dist/app.min.js',
'!dist/_locales', '!dist/_locales/**/*',
'!dist/angular', '!dist/angular/**/*',
'!dist/partial', '!dist/partial/**/*',
'!dist/style', '!dist/style/app.min.css',
'!dist/style/font', '!dist/style/img',
'!dist/style/font/*', '!dist/style/img/*'
]
},
// For dev ease. e.g. grunt watch
watch: {
scripts: {
files: ['src/**/*'], // No need to be too specific.
tasks: ['default']
}
},
// Make the zipfile for release.
compress: {
release: {
options: {
archive: "release.zip"
},
expand: true,
cwd: 'dist/',
src: ['**/*'],
dest: './'
}
}
});
// Packages
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-useref');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compress');
// Custom task to set version from package.json to manifest.
grunt.registerTask('versionmanifest', 'Set manifest version from package.json', function() {
var done = this.async();
fs.readFile('./dist/manifest.json', function (err, data) {
if (err) {
throw err;
}
var json = JSON.parse(data);
json.version = grunt.config.get('pkg').version;
fs.writeFile('./dist/manifest.json', JSON.stringify(json), function (err) {
if (err) {
throw err;
}
done();
});
});
});
// Custom task to remove the key from the manifest file for releases.
grunt.registerTask('manifestrelease', 'Remove the key from the manifest for release.', function() {
var done = this.async();
fs.readFile('./dist/manifest.json', function (err, data) {
if (err) {
throw err;
}
var json = JSON.parse(data);
delete json.key;
fs.writeFile('./dist/manifest.json', JSON.stringify(json), function (err) {
if (err) {
throw err;
}
done();
});
});
});
grunt.registerTask('release', ['copy', 'versionmanifest', 'useref', 'concat', 'uglify', 'cssmin', 'clean', 'manifestrelease', 'compress', 'default']);
grunt.registerTask('default', ['copy', 'versionmanifest', 'useref', 'concat', 'cssmin', 'clean']);
};