forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
158 lines (145 loc) · 4.97 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
module.exports = function (grunt) {
require('create-grunt-tasks')(grunt, function (create) {
//
// --- Release task ---
create.task('release')
.sub('clean', [
'build/'
])
.sub('typescript', {
cwd: 'src',
src: 'src/**/*.ts',
dest: 'build/',
options: { target: 'es5' }
})
.sub('less', {
files: {
'build/popup/style/style.css': 'src/popup/style/style.less'
},
options: {
paths: ['src/']
}
})
.sub('copy', {
cwd: 'src/',
src: [
'**/*.html',
'config/*.*',
'img/*.*',
'lib/**/*.js',
'popup/font/*.*',
'popup/img/*.*',
'manifest.json',
],
dest: 'build/',
expand: true
})
.sub('zip', {
src: ['build/**/*.*'],
dest: 'build.zip',
compression: 'DEFLATE'
})
.sub('ext-reload');
//
// --- Debug tasks ---
create.task('debug')
.sub('debug-js')
.sub('debug-css')
.sub('ext-reload');
create.task('debug-js')
.sub('typescript', {
src: 'src/**/*.ts',
options: {
sourceMap: true,
declaration: false,
target: 'es5'
}
});
create.task('debug-css')
.sub('less', {
files: {
'src/popup/style/style.css': 'src/popup/style/style.less'
},
options: {
paths: ['src/']
}
});
// ---- Watch ----
create.task('debug-watch')
.sub('concurrent', {
tasks: ['debug-watch-js', 'debug-watch-css', 'debug-watch-other'],
options: {
logConcurrentOutput: true
},
});
create.task('debug-watch-js')
.sub('typescript', {
src: 'src/**/*.ts',
options: {
sourceMap: true,
declaration: false,
target: 'es5',
watch: {
path: 'src',
after: ['ext-reload']
}
}
});
create.task('debug-watch-css')
.sub('watch', {
files: ['src/**/*.less'],
tasks: ['debug-css', 'ext-reload']
});
create.task('debug-watch-other')
.sub('watch', {
files: ['src/**/*.{json,html,png,svg,ttf}'],
tasks: ['ext-reload']
});
// --- Reload chrome extensions ---
create.task('ext-reload')
.sub(function () {
// Create server to communicate with extension
var done = this.async();
var server = require('http').createServer(function (req, res) {
res.end('reload');
});
var connected = false;
var sockets = {};
var socketCount = 0;
var closeServer = function () {
server.close(function () {
grunt.log.writeln('Server closed gracefully.');
done();
});
for (var id in sockets) {
sockets[id].destroy();
}
setTimeout(function () {
grunt.log.writeln('Server was not closed gracefully.');
done();
}, 2000);
};
server.on('connection', function (socket) {
sockets[socketCount++] = socket;
if (!connected) {
grunt.log.writeln('Auto-reloader connected.');
socket.emit('reload', {});
connected = true;
setTimeout(function () {
closeServer();
}, 1000);
}
});
server.on('error', function (e) {
grunt.log.writeln('Server error: ' + e.description);
closeServer();
});
server.listen(8890);
// Close server if no listeners
setTimeout(function () {
grunt.log.writeln('Auto-reloader did not connect.');
closeServer();
}, 5000);
});
});
};