This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (43 loc) · 1.35 KB
/
index.js
File metadata and controls
54 lines (43 loc) · 1.35 KB
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
/**
* Module dependencies
*/
var path = require('path');
var fs = require('fs');
var fbp = require('fbp');
/**
* Expose plugin
*/
module.exports = function(options) {
options = options || {};
var property = options.property || "fbp";
function build(builder) {
builder.hook('before scripts', function(pkg){
var files = pkg.config[property];
if (!files) return;
var fbpFiles = [];
files.forEach(function(file){
var ext = path.extname(file);
if (ext != ".fbp") return;
fbpFiles.push(file);
var fbpData = fs.readFileSync(pkg.path(file), 'utf-8');
try {
var json = fbp.parse(fbpData);
} catch (e) {
// Rewrite message to include more information
e.message = "Error parsing " + file + " : " + e.message;
if (e.line && e.column) {
e.message = e.message + ' @ line=' + e.line + ',column=' + e.column;
}
throw e;
}
var js = "module.exports = JSON.parse('"+JSON.stringify(json).replace(/'/g, "\\'")+"');";
pkg.addFile('scripts', file, js);
});
fbpFiles.forEach(function(file) {
pkg.removeFile(property, file);
});
});
}
// If consumed directly though `component build --use component-fbp`
return 'function' === typeof options.hook ? build(options) : build;
};