diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..03f326c --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore index 3c3629e..7a7b33a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +package-lock.json node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6c8eb04 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: node +before_install: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" diff --git a/README.md b/README.md index 854e4a2..edae1fd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # bit-docs `@package` -Adds a `@package` tag for use in `bit-docs` +Adds a `@package` tag for use in `bit-docs`. `@package` will add the package's `package.json` info to the `docObject`. -Use: `@pacakge ../../package.json` +Use: `@package ../../package.json` diff --git a/bit-docs.js b/bit-docs.js index fce25f8..fd3d02b 100644 --- a/bit-docs.js +++ b/bit-docs.js @@ -1,16 +1,16 @@ var pkg = require("./package"); /** - * @module {function} bit-docs-tag-package * @parent plugins + * @module {function} bit-docs-tag-package + * @group bit-docs-tag-package/tags tags * * @description Adds a `@package` tag for use in `bit-docs`. * * @body * - * `@package` will add the package's `package.json` info to the `docObject`. - * - * Use: `@pacakge ../../package.json` + * This plugin registers onto the `tags` hook to add the + * [bit-docs-tag-package/tags/package] tag. */ module.exports = function(bitDocs) { bitDocs.register("tags",{ diff --git a/package.js b/package.js index 724221b..24a96ad 100644 --- a/package.js +++ b/package.js @@ -1,10 +1,56 @@ 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 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 diff --git a/package.json b/package.json index 6077c78..bf8f0c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bit-docs-tag-package", - "version": "0.0.6", + "version": "1.0.0", "description": "Reference package's package.json", "main": "package.js", "scripts": {