-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.js
66 lines (63 loc) · 1.59 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
var path = require("path");
var fs = require("graceful-fs");
/**
* @parent bit-docs-tag-package/tags
* @module {bit-docs-process-tags/types/tag} bit-docs-tag-package/tags/package @package
*
* @description Adds the package's `package.json` info to the
* [bit-docs/types/docObject].
*
* @signature `@package PATH`
*
* Once added to the [bit-docs/types/docObject], you can reference the
* `package.json` properties like `name`, `description`, `author`, etc in
* `.mustache` templates.
*
* @param {String} PATH The path to a `package.json` file.
*
* @body
*
* An example `package.json` file might look like:
*
* ```js
* {
* "name": "my-package",
* "version": "0.0.1",
* "description": "My cool package.",
* }
* ```
*
* That gets used like:
*
* ```js
* @@package ./demos/package.json
* ```
*/
module.exports = {
add: function(line, curData, scope, objects, currentWrite) {
var atPackagePath = line.replace("@package", "").trim();
var pkgPath = path.join(path.dirname(this.src.path), atPackagePath);
var pkg;
try {
pkg = fs.readFileSync(pkgPath).toString();
} catch(e) {
if(e.code === "ENOENT") {
var newError = new Error('@package: Unable to locate ' +
atPackagePath + " from " + this.src.path
);
throw newError;
}
throw e;
}
var result = JSON.parse(pkg);
// delete things that would be too big
delete result.readme;
// or things that don't matter
for(var prop in result) {
if(prop[0] === "_") {
delete result[prop];
}
}
curData.package = result;
}
};