customizr 2.0.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/testing.yml +29 -0
- package/LICENSE +21 -21
- package/README.md +258 -259
- package/bin/customizr +71 -71
- package/build/modernizr-custom.js +6 -6
- package/build/modernizr-exclude.js +438 -73
- package/build/modernizr-package.js +6 -6
- package/build/modernizr-prefixed.js +9 -10
- package/build/modernizr-select.js +11 -12
- package/cache/options.json +14 -1
- package/package.json +62 -60
- package/src/builder.js +118 -118
- package/src/crawler.js +298 -298
- package/src/index.js +64 -64
- package/src/metadata.js +33 -33
- package/src/settings.json +34 -34
- package/src/utils.js +226 -226
- package/test/css/should-ignore.scss +9 -9
- package/test/css/vanilla.css +174 -161
- package/test/js/amd.js +23 -3
- package/test/js/vanilla.js +23 -3
- package/test/pretest.js +133 -133
- package/test/runner.js +17 -17
- package/test/settings/cache-invalidate.json +9 -9
- package/test/settings/custom.json +8 -8
- package/test/settings/exclude.json +14 -14
- package/test/settings/prefixed.json +10 -10
- package/test/settings/select.json +15 -15
- package/test/tests.js +415 -415
package/src/utils.js
CHANGED
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
module.exports = function (modernizrPath) {
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
// Dependencies
|
|
5
|
-
var fs = require("fs"),
|
|
6
|
-
path = require("path"),
|
|
7
|
-
glob = require("glob"),
|
|
8
|
-
colors = require("colors"),
|
|
9
|
-
equal = require("fast-deep-equal"),
|
|
10
|
-
mkdirp = require("mkdirp"),
|
|
11
|
-
_ = require("lodash");
|
|
12
|
-
|
|
13
|
-
// Lovingly lifted verbatim from Grunt: https://github.com/gruntjs/grunt/blob/master/lib/grunt/file.js
|
|
14
|
-
//
|
|
15
|
-
// Process specified wildcard glob patterns or filenames against a
|
|
16
|
-
// callback, excluding and uniquing files in the result set.
|
|
17
|
-
var processPatterns = function (patterns, fn) {
|
|
18
|
-
// Filepaths to return.
|
|
19
|
-
var result = [];
|
|
20
|
-
|
|
21
|
-
// Iterate over flattened patterns array.
|
|
22
|
-
_.flatten(patterns).forEach(function (pattern) {
|
|
23
|
-
// If the first character is ! it should be omitted
|
|
24
|
-
var exclusion = pattern.indexOf('!') === 0;
|
|
25
|
-
|
|
26
|
-
// If the pattern is an exclusion, remove the !
|
|
27
|
-
if (exclusion) {
|
|
28
|
-
pattern = pattern.slice(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Find all matching files for this pattern.
|
|
32
|
-
var matches = fn(pattern);
|
|
33
|
-
|
|
34
|
-
if (exclusion) {
|
|
35
|
-
// If an exclusion, remove matching files.
|
|
36
|
-
result = _.difference(result, matches);
|
|
37
|
-
} else {
|
|
38
|
-
// Otherwise add matching files.
|
|
39
|
-
result = _.union(result, matches);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
_ : require("lodash"),
|
|
48
|
-
|
|
49
|
-
file : {
|
|
50
|
-
delete : function (filepath) {
|
|
51
|
-
return fs.unlinkSync(filepath);
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
exists : function (filepath) {
|
|
55
|
-
return fs.existsSync(filepath);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
// Return an array of all file paths that match the given wildcard patterns.
|
|
59
|
-
expand : function (options, patterns) {
|
|
60
|
-
// Return all matching filepaths.
|
|
61
|
-
var matches = processPatterns(patterns, function (pattern) {
|
|
62
|
-
// Find all matching files for this pattern.
|
|
63
|
-
return glob.sync(pattern, options);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Filter result set?
|
|
67
|
-
if (options.filter) {
|
|
68
|
-
matches = matches.filter(function (filepath) {
|
|
69
|
-
filepath = path.join(options.cwd || '', filepath);
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
if (typeof options.filter === 'function') {
|
|
73
|
-
return options.filter(filepath);
|
|
74
|
-
} else {
|
|
75
|
-
// If the file is of the right type and exists, this should work.
|
|
76
|
-
return fs.statSync(filepath)[options.filter]();
|
|
77
|
-
}
|
|
78
|
-
} catch (e) {
|
|
79
|
-
// Otherwise, it's probably not the right type.
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return matches;
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
mkdir : function (filepath) {
|
|
89
|
-
return mkdirp.sync(path.dirname(filepath));
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
read : function (filepath) {
|
|
93
|
-
return String(fs.readFileSync(filepath));
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
readJSON : function (filepath) {
|
|
97
|
-
return JSON.parse(fs.readFileSync(filepath));
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
write : function (filepath, string, options) {
|
|
101
|
-
mkdirp.sync(path.dirname(filepath));
|
|
102
|
-
|
|
103
|
-
if (fs.existsSync(filepath)) {
|
|
104
|
-
fs.unlinkSync(filepath);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return fs.writeFileSync(filepath, string, options);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
log : {
|
|
112
|
-
ok : function (string) {
|
|
113
|
-
if (string) {
|
|
114
|
-
return process.stdout.write(">> ".green + string + "\n");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return process.stdout.write("OK".green + "\n");
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
subhead : function (string) {
|
|
121
|
-
string = string || "";
|
|
122
|
-
return process.stdout.write("\n" + string.bold + "\n");
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
write : function (string) {
|
|
126
|
-
string = string || "";
|
|
127
|
-
return process.stdout.write(string);
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
warn : function (string) {
|
|
131
|
-
string = string || "";
|
|
132
|
-
return process.stdout.write(("Warning: " + string + " \n").yellow);
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
writeln : function (string) {
|
|
136
|
-
string = string || "";
|
|
137
|
-
return process.stdout.write(string + "\n");
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
checkCacheValidity : function (currentConfig, modernizrOptions) {
|
|
142
|
-
var jsonPath = path.join(__dirname, "..", "package.json");
|
|
143
|
-
var pkg = this.file.readJSON(jsonPath);
|
|
144
|
-
|
|
145
|
-
// Check if a previous config exists
|
|
146
|
-
var previous = this.getPreviousOptions();
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
currentConfig.cache === true &&
|
|
150
|
-
(currentConfig.dest && this.file.exists(currentConfig.dest)) &&
|
|
151
|
-
pkg &&
|
|
152
|
-
previous &&
|
|
153
|
-
previous.version === pkg.version &&
|
|
154
|
-
previous.modernizr === pkg.dependencies.modernizr &&
|
|
155
|
-
equal(previous.options, modernizrOptions)
|
|
156
|
-
) {
|
|
157
|
-
return this.file.read(currentConfig.dest);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return false;
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
getSettings : function () {
|
|
164
|
-
return this.settings || {};
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
storeSettings : function (settings) {
|
|
168
|
-
var _defaults = this._.clone(this.getDefaults().defaults);
|
|
169
|
-
|
|
170
|
-
settings = this._.extend(_defaults, settings);
|
|
171
|
-
this.settings = settings;
|
|
172
|
-
return settings;
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
getPreviousOptions : function () {
|
|
176
|
-
var cacheDir = path.join(__dirname, "..", "cache");
|
|
177
|
-
var optionsLocation = path.join(cacheDir, "options.json");
|
|
178
|
-
|
|
179
|
-
// Check if cache directory doesn't exist
|
|
180
|
-
if (!this.file.exists(optionsLocation)) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Otherwise, return the options.
|
|
185
|
-
return this.file.readJSON(optionsLocation);
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
saveOptions : function (options) {
|
|
189
|
-
// If no options parameter, assume no further action.
|
|
190
|
-
if (typeof options === "undefined") {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
var cacheDir = path.join(__dirname, "..", "cache");
|
|
195
|
-
var optionsLocation = path.join(cacheDir, "options.json");
|
|
196
|
-
|
|
197
|
-
// Check if cache directory doesn't exist
|
|
198
|
-
if (!this.file.exists(cacheDir)) {
|
|
199
|
-
this.file.mkdir(cacheDir);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Remove old options
|
|
203
|
-
if (this.file.exists(optionsLocation)) {
|
|
204
|
-
this.file.delete(optionsLocation);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
var jsonPath = path.join(__dirname, "..", "package.json");
|
|
208
|
-
var pkg = this.file.readJSON(jsonPath);
|
|
209
|
-
|
|
210
|
-
// Stash options along with metadata
|
|
211
|
-
var metadata = {
|
|
212
|
-
version: pkg.version,
|
|
213
|
-
modernizr: (pkg.dependencies || {}).modernizr,
|
|
214
|
-
options: options
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// Write new options
|
|
218
|
-
this.file.write(optionsLocation, JSON.stringify(metadata, null, 2));
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
getDefaults : function () {
|
|
222
|
-
this.defaults = this.defaults || this.file.readJSON(path.join(__dirname, "settings.json"));
|
|
223
|
-
return this.defaults;
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
};
|
|
1
|
+
module.exports = function (modernizrPath) {
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// Dependencies
|
|
5
|
+
var fs = require("fs"),
|
|
6
|
+
path = require("path"),
|
|
7
|
+
glob = require("glob"),
|
|
8
|
+
colors = require("colors"),
|
|
9
|
+
equal = require("fast-deep-equal"),
|
|
10
|
+
mkdirp = require("mkdirp"),
|
|
11
|
+
_ = require("lodash");
|
|
12
|
+
|
|
13
|
+
// Lovingly lifted verbatim from Grunt: https://github.com/gruntjs/grunt/blob/master/lib/grunt/file.js
|
|
14
|
+
//
|
|
15
|
+
// Process specified wildcard glob patterns or filenames against a
|
|
16
|
+
// callback, excluding and uniquing files in the result set.
|
|
17
|
+
var processPatterns = function (patterns, fn) {
|
|
18
|
+
// Filepaths to return.
|
|
19
|
+
var result = [];
|
|
20
|
+
|
|
21
|
+
// Iterate over flattened patterns array.
|
|
22
|
+
_.flatten(patterns).forEach(function (pattern) {
|
|
23
|
+
// If the first character is ! it should be omitted
|
|
24
|
+
var exclusion = pattern.indexOf('!') === 0;
|
|
25
|
+
|
|
26
|
+
// If the pattern is an exclusion, remove the !
|
|
27
|
+
if (exclusion) {
|
|
28
|
+
pattern = pattern.slice(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Find all matching files for this pattern.
|
|
32
|
+
var matches = fn(pattern);
|
|
33
|
+
|
|
34
|
+
if (exclusion) {
|
|
35
|
+
// If an exclusion, remove matching files.
|
|
36
|
+
result = _.difference(result, matches);
|
|
37
|
+
} else {
|
|
38
|
+
// Otherwise add matching files.
|
|
39
|
+
result = _.union(result, matches);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
_ : require("lodash"),
|
|
48
|
+
|
|
49
|
+
file : {
|
|
50
|
+
delete : function (filepath) {
|
|
51
|
+
return fs.unlinkSync(filepath);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
exists : function (filepath) {
|
|
55
|
+
return fs.existsSync(filepath);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// Return an array of all file paths that match the given wildcard patterns.
|
|
59
|
+
expand : function (options, patterns) {
|
|
60
|
+
// Return all matching filepaths.
|
|
61
|
+
var matches = processPatterns(patterns, function (pattern) {
|
|
62
|
+
// Find all matching files for this pattern.
|
|
63
|
+
return glob.sync(pattern, options);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Filter result set?
|
|
67
|
+
if (options.filter) {
|
|
68
|
+
matches = matches.filter(function (filepath) {
|
|
69
|
+
filepath = path.join(options.cwd || '', filepath);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
if (typeof options.filter === 'function') {
|
|
73
|
+
return options.filter(filepath);
|
|
74
|
+
} else {
|
|
75
|
+
// If the file is of the right type and exists, this should work.
|
|
76
|
+
return fs.statSync(filepath)[options.filter]();
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// Otherwise, it's probably not the right type.
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return matches;
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
mkdir : function (filepath) {
|
|
89
|
+
return mkdirp.sync(path.dirname(filepath));
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
read : function (filepath) {
|
|
93
|
+
return String(fs.readFileSync(filepath));
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
readJSON : function (filepath) {
|
|
97
|
+
return JSON.parse(fs.readFileSync(filepath));
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
write : function (filepath, string, options) {
|
|
101
|
+
mkdirp.sync(path.dirname(filepath));
|
|
102
|
+
|
|
103
|
+
if (fs.existsSync(filepath)) {
|
|
104
|
+
fs.unlinkSync(filepath);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return fs.writeFileSync(filepath, string, options);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
log : {
|
|
112
|
+
ok : function (string) {
|
|
113
|
+
if (string) {
|
|
114
|
+
return process.stdout.write(">> ".green + string + "\n");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return process.stdout.write("OK".green + "\n");
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
subhead : function (string) {
|
|
121
|
+
string = string || "";
|
|
122
|
+
return process.stdout.write("\n" + string.bold + "\n");
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
write : function (string) {
|
|
126
|
+
string = string || "";
|
|
127
|
+
return process.stdout.write(string);
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
warn : function (string) {
|
|
131
|
+
string = string || "";
|
|
132
|
+
return process.stdout.write(("Warning: " + string + " \n").yellow);
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
writeln : function (string) {
|
|
136
|
+
string = string || "";
|
|
137
|
+
return process.stdout.write(string + "\n");
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
checkCacheValidity : function (currentConfig, modernizrOptions) {
|
|
142
|
+
var jsonPath = path.join(__dirname, "..", "package.json");
|
|
143
|
+
var pkg = this.file.readJSON(jsonPath);
|
|
144
|
+
|
|
145
|
+
// Check if a previous config exists
|
|
146
|
+
var previous = this.getPreviousOptions();
|
|
147
|
+
|
|
148
|
+
if (
|
|
149
|
+
currentConfig.cache === true &&
|
|
150
|
+
(currentConfig.dest && this.file.exists(currentConfig.dest)) &&
|
|
151
|
+
pkg &&
|
|
152
|
+
previous &&
|
|
153
|
+
previous.version === pkg.version &&
|
|
154
|
+
previous.modernizr === pkg.dependencies.modernizr &&
|
|
155
|
+
equal(previous.options, modernizrOptions)
|
|
156
|
+
) {
|
|
157
|
+
return this.file.read(currentConfig.dest);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
getSettings : function () {
|
|
164
|
+
return this.settings || {};
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
storeSettings : function (settings) {
|
|
168
|
+
var _defaults = this._.clone(this.getDefaults().defaults);
|
|
169
|
+
|
|
170
|
+
settings = this._.extend(_defaults, settings);
|
|
171
|
+
this.settings = settings;
|
|
172
|
+
return settings;
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
getPreviousOptions : function () {
|
|
176
|
+
var cacheDir = path.join(__dirname, "..", "cache");
|
|
177
|
+
var optionsLocation = path.join(cacheDir, "options.json");
|
|
178
|
+
|
|
179
|
+
// Check if cache directory doesn't exist
|
|
180
|
+
if (!this.file.exists(optionsLocation)) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Otherwise, return the options.
|
|
185
|
+
return this.file.readJSON(optionsLocation);
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
saveOptions : function (options) {
|
|
189
|
+
// If no options parameter, assume no further action.
|
|
190
|
+
if (typeof options === "undefined") {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
var cacheDir = path.join(__dirname, "..", "cache");
|
|
195
|
+
var optionsLocation = path.join(cacheDir, "options.json");
|
|
196
|
+
|
|
197
|
+
// Check if cache directory doesn't exist
|
|
198
|
+
if (!this.file.exists(cacheDir)) {
|
|
199
|
+
this.file.mkdir(cacheDir);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Remove old options
|
|
203
|
+
if (this.file.exists(optionsLocation)) {
|
|
204
|
+
this.file.delete(optionsLocation);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
var jsonPath = path.join(__dirname, "..", "package.json");
|
|
208
|
+
var pkg = this.file.readJSON(jsonPath);
|
|
209
|
+
|
|
210
|
+
// Stash options along with metadata
|
|
211
|
+
var metadata = {
|
|
212
|
+
version: pkg.version,
|
|
213
|
+
modernizr: (pkg.dependencies || {}).modernizr,
|
|
214
|
+
options: options
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// Write new options
|
|
218
|
+
this.file.write(optionsLocation, JSON.stringify(metadata, null, 2));
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
getDefaults : function () {
|
|
222
|
+
this.defaults = this.defaults || this.file.readJSON(path.join(__dirname, "settings.json"));
|
|
223
|
+
return this.defaults;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
svg:not(:root) {
|
|
2
|
-
overflow: hidden;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
#foo {
|
|
6
|
-
&:before {
|
|
7
|
-
content: icon(audio);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
svg:not(:root) {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
#foo {
|
|
6
|
+
&:before {
|
|
7
|
+
content: icon(audio);
|
|
8
|
+
}
|
|
9
|
+
}
|