Skip to content

Commit 714863c

Browse files
committed
Add @Package tag and tests
0 parents  commit 714863c

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

bit-docs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var pkg = require("./package");
2+
3+
module.exports = function(bitDocs) {
4+
bitDocs.register("tags",{
5+
package: pkg
6+
});
7+
};

package.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var path = require("path");
2+
var fs = require("fs");
3+
4+
var typeConverters = {
5+
stache: 'html',
6+
mustache: 'html',
7+
component: 'html'
8+
};
9+
10+
var convertType = function(type) {
11+
return typeConverters[type] || type;
12+
};
13+
14+
module.exports = {
15+
add: function(line, curData, scope, objects, currentWrite) {
16+
var sourcePath = path.join(path.dirname(this.src.path));
17+
var pkgPath = line.split(' ')[1];
18+
var pkg = require(path.join(sourcePath, pkgPath));
19+
curData.package = pkg;
20+
}
21+
};

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "bit-docs-tag-package",
3+
"version": "0.0.1",
4+
"description": "Reference package's package.json",
5+
"main": "package.js",
6+
"scripts": {
7+
"test": "mocha test/test.js --reporter spec",
8+
"postversion": "git push --tags && git push",
9+
"preversion": "npm test",
10+
"release:pre": "npm version prerelease && npm publish",
11+
"release:patch": "npm version patch && npm publish",
12+
"release:minor": "npm version minor && npm publish",
13+
"release:major": "npm version major && npm publish"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/bit-docs/bit-docs-tag-package.git"
18+
},
19+
"keywords": [
20+
"bit-docs",
21+
"donejs"
22+
],
23+
"author": "Bitovi",
24+
"license": "MIT",
25+
"bugs": {
26+
"url": "https://github.com/bit-docs/bit-docs-tag-package/issues"
27+
},
28+
"homepage": "https://github.com/bit-docs/bit-docs-tag-package#readme",
29+
"devDependencies": {
30+
"bit-docs-process-tags": "0.0.5",
31+
"mocha": ">= 1.18.0"
32+
}
33+
}

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# bit-docs `@package`
2+
3+
Adds a `@package` tag for use in `bit-docs`
4+
5+
`@package` will add the package's `package.json` info to the `docObject`.
6+
7+
Use: `@pacakge ../../package.json`

test/code/js/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "package-test",
3+
"version": "0.0.1",
4+
"description": "A test for bit-docs @package tag",
5+
"main": "foo.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC"
11+
}

test/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var processTags = require("bit-docs-process-tags");
2+
var pkg = require("../package");
3+
var path = require("path");
4+
var assert = require("assert");
5+
6+
describe("sourceref", function() {
7+
it("adds the package.json info", function() {
8+
var docMap = {};
9+
10+
processTags({
11+
comment: "@constructor\n@package ./js/package.json",
12+
scope: {},
13+
docMap: docMap,
14+
docObject: {
15+
src: {
16+
path: path.join(__dirname, "code","test.js")
17+
}
18+
},
19+
tags: {
20+
package: pkg,
21+
constructor: {
22+
add : function() {
23+
this.name = "constructed";
24+
this.type = "constructor";
25+
return ["scope", this];
26+
}
27+
}
28+
}
29+
}, function(newDoc, newScope) {
30+
assert.ok(newDoc.package.version === '0.0.1');
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)