-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
87 lines (70 loc) · 1.67 KB
/
index.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
var path = require('path');
var Transform = require('stream').Transform;
var Vinyl = require('vinyl');
var vm = require('vm');
module.exports = function(filename) {
var files = {};
var deps = {};
var error;
var nameRe = /[\w.]+/g;
var extRe = /\bextend:[ '"]+([\w.]+)/;
var mixsRe = /\bmixins: *[[{]/;
var mix1Re = /(?:['"]([\w.]+)['"]|[}\]])/g;
var locRe = /(.*[\s]){2}/;
return new Transform({
objectMode: true,
transform,
flush,
});
function transform(file, enc, cb) {
var data = file.contents.toString();
var k, ext, mixs, mix1;
nameRe.lastIndex = 0;
if (
data &&
String(nameRe.exec(data)) === 'Ext.define' &&
(k = String(nameRe.exec(data)))
) {
try {
new vm.Script(data, path.relative(file.cwd, file.path));
}
catch (e) {
(error = e).message += '\n' + e.stack.match(locRe)[0];
}
files[k] = file;
deps[k] = [];
if ((ext = extRe.exec(data)) && ext[1]) {
deps[k].push(ext[1]);
}
if ((mixs = mixsRe.exec(data))) {
mix1Re.lastIndex = mixs.index + mixs[0].length;
while ((mix1 = mix1Re.exec(data)) && mix1[1]) {
deps[k].push(mix1[1]);
}
}
}
cb();
}
function flush(cb) {
var a = [];
for (var k in files) {
push(a, k);
}
if (a.length > 0) {
this.push(new Vinyl({
path: filename,
contents: Buffer.concat(a),
}));
}
cb(error);
}
function push(a, k) {
if (files[k]) {
deps[k].forEach(k => {
push(a, k);
});
a.push(files[k].contents);
delete files[k];
}
}
};