forked from micmro/performance-bookmarklet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
167 lines (152 loc) · 4.28 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
module.exports = function( grunt ) {
"use strict";
require("load-grunt-tasks")(grunt);
var banner = "/* https://github.com/micmro/performance-bookmarklet by Michael Mrowetz @MicMro\n build:<%= grunt.template.today(\"dd/mm/yyyy\") %> */\n";
grunt.initConfig({
copy : {
distBookmarklet: {
files: [{
expand: true,
cwd: "src/",
src: ["**/*.js"],
dest: "dist/tempCollect",
filter: function(fileName){
return !fileName.match(/.+\.(?:chromeExtension|firefoxAddon).js$/);
},
ext: ".js"
}]
},
distFirefoxAddon: {
files: [{
expand: true,
cwd: "src/",
src: ["**/*.js"],
dest: "dist/tempCollect",
filter: function(fileName){
return !fileName.match(/.+\.(?:bookmarklet|chromeExtension).js$/);
},
ext: ".js"
}]
},
distChromeExtension: {
files: [{
expand: true,
cwd: "src/",
src: ["**/*.js"],
dest: "dist/tempCollect",
filter: function(fileName){
return !fileName.match(/.+\.(?:bookmarklet|firefoxAddon).js$/);
},
ext: ".js"
}]
}
},
babel: {
options: {
returnUsedHelpers: true
},
dist: {
files: [{
expand: true,
cwd: "dist/tempCollect",
src: ["**/*.js"],
dest: "dist/tempEs5",
ext: ".js"
}]
}
},
browserify: {
options: {
banner: banner
},
distBookmarklet: {
files: {
"dist/performanceBookmarklet.js": ["dist/tempEs5/**/*.js"],
}
},
distFirefoxAddon: {
files: {
"dist/performanceBookmarklet.ff.js": ["dist/tempEs5/**/*.js"],
}
},
distChromeExtension: {
files: {
"dist/performanceBookmarklet.chrome.js": ["dist/tempEs5/**/*.js"],
}
}
},
uglify : {
options: {
compress: {
global_defs: {
"DEBUG": false
},
dead_code: true
},
banner: banner
},
distBookmarklet: {
files: {
"dist/performanceBookmarklet.min.js": ["dist/performanceBookmarklet.js"]
}
},
distFirefoxAddon: {
files: {
"dist/performanceBookmarklet.ff.min.js": ["dist/performanceBookmarklet.ff.js"]
}
},
distChromeExtension: {
files: {
"dist/performanceBookmarklet.chrome.min.js": ["dist/performanceBookmarklet.chrome.js"]
}
}
},
watch: {
babelBookmarklet: {
files: ["src/**/*", "Gruntfile.js"],
tasks: ["distBookmarklet"],
options: {
spawn: false,
interrupt: true
},
},
babelFirefoxAddon: {
files: ["src/**/*", "Gruntfile.js"],
tasks: ["distFirefoxAddon"],
options: {
spawn: false,
interrupt: true
},
},
babelChromeExtension: {
files: ["src/**/*", "Gruntfile.js"],
tasks: ["distChromeExtension"],
options: {
spawn: false,
interrupt: true
},
},
}
});
//transform CSS file to JS variable
grunt.registerTask("inlineCssToJs", function() {
var cssFile = "src/style.css";
var cssFileDestination = "dist/tempCollect/helpers/style.js";
var varName = "style";
var cssContent = grunt.file.read(cssFile);
//clean CSS content
cssContent = cssContent.replace( /\/\*(?:(?!\*\/)[\s\S])*\*\//g, "").replace(/[\r\n\t]+/g, " ").replace(/[ ]{2,}/g, " ").replace(/\"/g,"\\\"");
//make JS Var and export as module
cssContent = "export const " + varName + " = \"" + cssContent.trim() + "\";";
grunt.log.writeln(cssFile + " transformed to " + cssFileDestination);
grunt.file.write(cssFileDestination, cssContent);
});
grunt.registerTask("distBookmarklet", ["inlineCssToJs", "copy:distBookmarklet", "babel", "browserify:distBookmarklet", "uglify:distBookmarklet"]);
grunt.registerTask("distFirefoxAddon", ["inlineCssToJs", "copy:distFirefoxAddon", "babel", "browserify:distFirefoxAddon", "uglify:distFirefoxAddon"]);
grunt.registerTask("distChromeExtension", ["inlineCssToJs", "copy:distChromeExtension", "babel", "browserify:distChromeExtension", "uglify:distChromeExtension"]);
grunt.registerTask("distAll", ["distBookmarklet", "distFirefoxAddon", "distChromeExtension"]);
grunt.registerTask("watchDistBookmarklet", ["distBookmarklet", "watch:babelBookmarklet"]);
grunt.registerTask("watchDistFirefoxAddon", ["distFirefoxAddon", "watch:babelFirefoxAddon"]);
grunt.registerTask("watchDistChromeExtension", ["distChromeExtension", "watch:babelChromeExtension"]);
grunt.registerTask("default", ["watchDistBookmarklet"]);
};