Skip to content

Commit

Permalink
Improve error messaging when unable to find @Package
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
matthewp committed Jun 4, 2019
1 parent f824863 commit 67c7641
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; Unix-style newlines
[*]
end_of_line = LF
indent_style = tab
indent_size = 4

[{*.json,*.yml,*.md}]
indent_style = space
indent_size = 2
35 changes: 24 additions & 11 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,53 @@ 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 pkgPath = path.join(path.dirname(this.src.path), line.replace("@package", "").trim());
var pkg = fs.readFileSync(pkgPath).toString();
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
Expand Down

0 comments on commit 67c7641

Please sign in to comment.