-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGruntfile.js
170 lines (133 loc) · 4.08 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
168
169
170
/*jshint node:true*/
module.exports = function (grunt) {
"use strict";
var getBytesWithUnit = function (bytes) {
if (isNaN(bytes)) {
return;
}
var units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var amountOf2s = Math.floor(Math.log(+bytes) / Math.log(2));
if (amountOf2s < 1) {
amountOf2s = 0;
}
var i = Math.floor(amountOf2s / 10);
bytes = +bytes / Math.pow(2, 10 * i);
// Rounds to 3 decimals places.
if (bytes.toString().length > bytes.toFixed(3).toString().length) {
bytes = bytes.toFixed(3);
}
return bytes + units[i];
};
// Watcher
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
build: {
"dist/reflexie.js": [
"src/intro",
// Via https://github.com/adobe-webplatform/css-regions-polyfill
/*!
Copyright 2012 Adobe Systems Inc.;
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"lib/css-regions-polyfill/src/shims",
"lib/css-regions-polyfill/src/StyleLoader",
"lib/css-regions-polyfill/src/cssparser",
/* https://github.com/jeromeetienne/microevent.js */
/* License MIT */
"lib/microevent/microevent",
/* https://github.com/keeganstreet/specificity */
/* License TBD */
"lib/specificity/specificity",
"src/core",
"src/utils",
"src/parser",
"src/polyfill/items/order",
"src/polyfill/items/alignSelf",
"src/polyfill/items/flexGrow",
"src/polyfill/container/flexDirection",
"src/polyfill/container/flexWrap",
"src/polyfill/container/justifyContent",
"src/polyfill/container/alignItems",
"src/polyfill/container/alignContent",
"src/polyfill/container/autoSize",
"src/polyfill",
"src/support",
"src/event",
"src/init",
"src/exports",
"src/outro"
]
},
watch: {
files: ["src/**/*.js"],
tasks: "build"
}
});
// Special concat/build task to handle various jQuery build requirements
//
grunt.registerMultiTask("build", "Concatenate source", function () {
var done = this.async();
// Concat specified files.
var compiled = "",
version = grunt.config("pkg.version"),
source;
// conditionally concatenate source
this.data.forEach(function (filepath) {
filepath += ".js";
source = grunt.file.read(filepath);
if (!(/(in|ou)tro\.js$/).test(filepath)) {
source = ("\n" + source).replace(/\n/gm, "\n\t").replace(/\n\t\n/gm, "\n\n");
}
// Formatting
// spaces -> tabs
source = source.replace(/ /g, "\t");
// trim whitespace
source = source.replace(/\s+\n/g, "\n\n");
compiled += source;
grunt.log.ok(filepath);
});
// Embed Version
// Embed Date
compiled = compiled.replace(/@VERSION/g, version)
.replace("@DATE", function () {
var date = new Date();
// YYYY-MM-DD
return [
date.getMonth() + 1,
date.getDate(),
date.getFullYear()
].join("-");
});
// Write concatenated source to file
grunt.file.write(this.target, compiled);
grunt.log.subhead("Saved output to " + this.target);
var uglify = require("uglify-js");
var result = uglify.minify(this.target, {
outSourceMap: this.target + ".map",
warnings: true,
mangle: true,
unused: true,
compress: {
unsafe: true
}
});
var minifiedPath = this.target.replace(".js", ".min.js");
// Save minified file
grunt.file.write(minifiedPath, result.code);
// Save source map
grunt.file.write(this.target + ".map", result.map);
var gzip = require("gzip");
grunt.log.ok(getBytesWithUnit(compiled.length) + " uncompressed");
grunt.log.ok(getBytesWithUnit(result.code.length) + " minified");
done();
});
};