@@ -4,40 +4,53 @@ var fs = require("graceful-fs");
4
4
/**
5
5
* @parent bit-docs-tag-package/tags
6
6
* @module {bit-docs-process-tags/types/tag} bit-docs-tag-package/tags/package @package
7
- *
7
+ *
8
8
* @description Adds the package's `package.json` info to the
9
9
* [bit-docs/types/docObject].
10
- *
10
+ *
11
11
* @signature `@package PATH`
12
- *
12
+ *
13
13
* Once added to the [bit-docs/types/docObject], you can reference the
14
14
* `package.json` properties like `name`, `description`, `author`, etc in
15
15
* `.mustache` templates.
16
- *
16
+ *
17
17
* @param {String } PATH The path to a `package.json` file.
18
- *
18
+ *
19
19
* @body
20
- *
20
+ *
21
21
* An example `package.json` file might look like:
22
- *
22
+ *
23
23
* ```js
24
24
* {
25
25
* "name": "my-package",
26
26
* "version": "0.0.1",
27
27
* "description": "My cool package.",
28
28
* }
29
29
* ```
30
- *
30
+ *
31
31
* That gets used like:
32
- *
32
+ *
33
33
* ```js
34
34
* @@package ./demos/package.json
35
35
* ```
36
36
*/
37
37
module . exports = {
38
38
add : function ( line , curData , scope , objects , currentWrite ) {
39
- var pkgPath = path . join ( path . dirname ( this . src . path ) , line . replace ( "@package" , "" ) . trim ( ) ) ;
40
- var pkg = fs . readFileSync ( pkgPath ) . toString ( ) ;
39
+ var atPackagePath = line . replace ( "@package" , "" ) . trim ( ) ;
40
+ var pkgPath = path . join ( path . dirname ( this . src . path ) , atPackagePath ) ;
41
+ var pkg ;
42
+ try {
43
+ pkg = fs . readFileSync ( pkgPath ) . toString ( ) ;
44
+ } catch ( e ) {
45
+ if ( e . code === "ENOENT" ) {
46
+ var newError = new Error ( '@package: Unable to locate ' +
47
+ atPackagePath + " from " + this . src . path
48
+ ) ;
49
+ throw newError ;
50
+ }
51
+
52
+ throw e ;
53
+ }
41
54
var result = JSON . parse ( pkg ) ;
42
55
43
56
// delete things that would be too big
0 commit comments