forked from koseduhemak/touchpadswipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
120 lines (105 loc) · 3.56 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
/**
* Created by mfuesslin on 28.11.2016.
*/
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: [
{
expand: true,
cwd: 'src',
src: ['options/*.html'],
dest: 'dist/'
}
]
}
},
uglify: {
build: {
files: [
{
src: ['src/*.js'],
dest: 'dist/<%= pkg.name %>.min.js'
},
{
src: ['src/options/*.js'],
dest: 'dist/options/options.js'
}
]
}
},
sass: {
dist: {
options: {
sourcemap: 'none'
},
files: [{
expand: true,
cwd: 'src/sass',
src: ['**/*.scss'],
dest: 'src/css',
ext: '.css'
}]
}
},
cssmin: { // Begin CSS Minify Plugin
target: {
files: [{
expand: true,
cwd: 'src/css',
src: ['*.css', '!*.min.css'],
dest: 'dist',
ext: '.min.css'
}]
}
},
compress: {
main: {
options: {
archive: '<%= pkg.name %>.<%= pkg.version %>.zip'
},
files: [
{expand: true, cwd: "dist/", src: ['**'], dest: '/'}
]
}
},
watch: { // Compile everything into one task with Watch Plugin
css: {
files: 'src/sass/*.scss',
tasks: ['sass', 'cssmin']
},
js: {
files: 'src/*.js',
tasks: ['uglify']
}
}
});
// Load the plugin that provides the "uglify" task.
/*grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-update_json');
grunt.loadNpmTasks('grunt-contrib-watch');*/
// Default task(s).
grunt.registerTask('default', ['watch']);
grunt.registerTask('updatejson', function (key, value) {
var pkg = grunt.file.readJSON('package.json');
var projectFile = "src/manifest.json";
if (!grunt.file.exists(projectFile)) {
grunt.log.error("file " + projectFile + " not found");
return true;//return false to abort the execution
}
var manifest = grunt.file.readJSON(projectFile);//get file as json object
manifest.version = pkg.version;
manifest.description = pkg.description;
manifest.name = pkg.name;
manifest["content_scripts"][0]["css"] = ["anim.min.css"];
manifest["content_scripts"][0]["js"] = [pkg.name + ".min.js"];
grunt.file.write("dist/manifest.json", JSON.stringify(manifest, null, 2));//serialize it back to file
});
grunt.registerTask('dist', ['copy', 'sass', 'cssmin', 'uglify', 'updatejson', 'compress']);
};