-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpackage.js
69 lines (57 loc) · 2.18 KB
/
package.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
Package.describe({
summary: "UX/UI framework from Twitter with less " + '\n add @import "bootstrap.less"; to your less file'
});
Package.on_use(function (api) {
api.add_files('build/less/bootstrap.less', 'server');
api.add_files('build/js/bootstrap.js', 'client');
api.add_files('build/img/glyphicons-halflings.png', 'client');
api.add_files('build/img/glyphicons-halflings-white.png', 'client');
});
var less = require('less');
var fs = require('fs');
var path = require('path');
var bootstrap = "";
Package.register_extension(
"less", function (bundle, source_path, serve_path, where) {
serve_path = serve_path + '.css';
if(source_path.indexOf("bootstrap.less")>-1){
bootstrap = String(fs.readFileSync(source_path));
return;
}
var contents = String(fs.readFileSync(source_path));
contents = contents.replace('@import "bootstrap.less";',bootstrap)
try {
var myRegexp = /@import "([\w'-/.]*)";/g;
var match = myRegexp.exec(contents);
while (match != null) {
var pat = path.join(path.dirname(source_path),match[1]);
contents = contents.replace(match[0], '@amport "' + pat +'";');
match = myRegexp.exec(contents);
//temp.push(pat);
}
contents = contents.replace(/@amport/g,'@import');
less.render(contents.toString('utf8'), function (err, css) {
// XXX why is this a callback? it's not async.
if (err) {
bundle.error(source_path + ": Less compiler error: " + err.message);
return;
}
bundle.add_resource({
type: "css",
path: serve_path,
data: new Buffer(css),
where: where
});
});
} catch (e) {
// less.render() is supposed to report any errors via its
// callback. But sometimes, it throws them instead. This is
// probably a bug in less. Be prepared for either behavior.
bundle.error(source_path + ": Less compiler error: " + e.message);
}
}
);
Package.on_test(function (api) {
api.add_files('less/bootstrap.less', 'server');
api.add_files(['tests/bootstrap_less_tests.less', 'tests/bootstrap_less_tests.js'], 'client');
});