| module.exports = function(path, obj) { | ||
| path.description = obj.join(' '); | ||
| }; |
| module.exports = function(obj, arr) { | ||
| obj.params = obj.params || {}; | ||
| var name = arr.shift(), | ||
| type = arr.shift(), | ||
| rest = arr.join(' '); | ||
| obj.params[name] = { | ||
| type: type, | ||
| info: rest | ||
| }; | ||
| }; |
| module.exports = function(path, obj) { | ||
| path.method = obj.shift(); | ||
| path.path = obj.shift(); | ||
| }; |
| var bees = require('../'); | ||
| describe('bees', function() { | ||
| describe('#load()', function() { | ||
| it('should load a file', function() { | ||
| bees.load(__dirname + '/file').should.be.a('string'); | ||
| }); | ||
| }); | ||
| describe('#parse()', function() { | ||
| it('should parse a file correctly', function() { | ||
| var res = bees.parse(bees.load(__dirname + '/file')); | ||
| var parsed = | ||
| [ | ||
| { method: 'GET', path: '/lol/:id', description: 'hi' }, | ||
| { | ||
| method: 'GET', | ||
| path: '/lol/:id', | ||
| description: 'hai', | ||
| params: { id: { type: 'string', info: 'id of the user' } } | ||
| } | ||
| ]; | ||
| JSON.stringify(res).should.equal(JSON.stringify(parsed)); | ||
| }); | ||
| }); | ||
| }); |
Sorry, the diff of this file is not supported yet
+1
-1
@@ -1,1 +0,1 @@ | ||
| module.exports = require('./lib/bees'); | ||
| module.exports = require('./lib/bees.js'); |
+44
-38
@@ -0,49 +1,55 @@ | ||
| var fs = require('fs'), | ||
| bees = exports; | ||
| var plugins = { | ||
| "return": require('./plugins/return'), | ||
| "param" : require('./plugins/param') | ||
| '@param': require('./plugin/param'), | ||
| '@path' : require('./plugin/path'), | ||
| '@descr': require('./plugin/descr') | ||
| }; | ||
| exports.parse = function bees(file) { | ||
| var matches = file.match(/\/\*{1,2}(.|\n)+?\*\//g), | ||
| json = []; | ||
| matches.map(function(m) { | ||
| bees.load = function(file) { | ||
| return fs.readFileSync(file, 'utf-8'); | ||
| }; | ||
| bees.parse = function(file) { | ||
| var blocks = file.match(/\/\* @api[\w\W*]+?\*\//g) || [], | ||
| config = []; | ||
| blocks.forEach(function(api) { | ||
| var path = {}; | ||
| api = api.split('\n'); | ||
| api.shift(); | ||
| api.pop(); | ||
| api = api.map(function(x) { | ||
| var match = x.match(/@([\w\W]+?;)/) || []; | ||
| return match.shift() || ""; | ||
| }); | ||
| var sub = {}; | ||
| m = m.split('\n'); | ||
| m.pop(); | ||
| m.shift(); | ||
| m.map(function(i) { | ||
| (function every(list) { | ||
| var item = list.shift(); | ||
| if(!item) return; | ||
| i = i.replace(/\*/g, '') | ||
| .trim(); | ||
| if(!i.length) return; | ||
| if(~i.indexOf('@')) { | ||
| var cmd = i.match(/@(\w+)\s([\W\w]+)?/); | ||
| cmd.shift(); | ||
| if(plugins[cmd[0]]) { | ||
| plugins[cmd[0]](cmd, sub); | ||
| } | ||
| item = item.replace(/[.*\n]/g, '').split(' '); | ||
| var cmd = item.shift(); | ||
| if(plugins[cmd]) { | ||
| plugins[cmd](path, item); | ||
| } | ||
| else { | ||
| i = i.split(' '); | ||
| sub.method = i[0]; | ||
| sub.path = i[1]; | ||
| } | ||
| }); | ||
| every(list); | ||
| })(api.join('\n').split(';')); | ||
| json.push(sub); | ||
| config.push(path); | ||
| }); | ||
| return json; | ||
| return config; | ||
| }; | ||
| exports.use = function(name, fn) { | ||
| bees.use = function(name, fn) { | ||
| plugins[name] = fn; | ||
| }; | ||
| } |
+7
-5
| { | ||
| "name": "bees", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "author": "yawnt <yawn.localhost@gmail.com>", | ||
| "description": "HTTP API Generator", | ||
| "description": "Api documentation generator", | ||
| "devDependencies": { | ||
| "vows": ">= 0.0.0" | ||
| "mocha": ">= 0.0.0", | ||
| "should": ">= 0.0.0", | ||
| "assert": ">= 0.0.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "vows --spec --isolate test/test-*.js" | ||
| "test": "mocha -R spec -r should test/*-test.js" | ||
| }, | ||
@@ -19,2 +21,2 @@ "bin": { | ||
| } | ||
| } | ||
| } |
+33
-1
@@ -77,3 +77,2 @@ bees (in Italian ```API``` means ```bees```) | ||
| ); | ||
| ``` | ||
@@ -95,6 +94,39 @@ | ||
| $ node plugin.js | ||
| [ | ||
| { | ||
| method: 'GET', | ||
| path: '/:id', | ||
| params: { id: 'id of the user' }, | ||
| return: 'user infos', | ||
| plugin: 'hai lol' | ||
| } | ||
| ] | ||
| ``` | ||
| ## Reporters: | ||
| Reporters are a way to return formatted objects. | ||
| If we got this in eyes-reporter.js: | ||
| ```javascript | ||
| var inspector = require('eyes').inspector({stream: null}); | ||
| module.exports = function(doc) { | ||
| return inspector(doc); | ||
| }; | ||
| ``` | ||
| And we call bees just like this: | ||
| ``` | ||
| bees -R eyes-reporter <file> | ||
| ``` | ||
| We will get: | ||
|  | ||
| Cool eh? | ||
| ## To Do: | ||
@@ -101,0 +133,0 @@ |
| module.exports = function(cmd, sub) { | ||
| var datas = cmd[1].match(/(\w+)\s([\W\w]+)?/) | ||
| datas.shift(); | ||
| sub.params = sub.params || {}; | ||
| sub.params[datas[0]] = datas[1]; | ||
| }; |
| module.exports = function(cmd, sub) { | ||
| sub.return = cmd[1]; | ||
| }; |
-24
| var app = require('express').createServer(); | ||
| /** | ||
| * GET / | ||
| * | ||
| * @return Main page | ||
| */ | ||
| app.get('/', function(req, res){ | ||
| res.send('Hello World'); | ||
| }); | ||
| /** | ||
| * GET /:id | ||
| * | ||
| * @param id id of the user | ||
| * @return user infos | ||
| */ | ||
| app.get('/:id', function(req, res){ | ||
| res.send('Hello World'); | ||
| }); | ||
| app.listen(3000); |
| var vows = require('vows'), | ||
| assert = require('assert'), | ||
| bees = require('../'); | ||
| var example = require('fs').readFileSync('./test/app.js', 'utf-8'); | ||
| vows | ||
| .describe('bees.js') | ||
| .addBatch( | ||
| { | ||
| 'example.js': { | ||
| topic: bees.parse(example), | ||
| 'should return correct json': function(json) { | ||
| assert.deepEqual( | ||
| json, | ||
| [ | ||
| { | ||
| "method": "GET", | ||
| "path": "/", | ||
| "return": "Main page" | ||
| }, | ||
| { | ||
| "method": "GET", | ||
| "path": "/:id", | ||
| "params": { | ||
| "id": "id of the user" | ||
| }, | ||
| "return": "user infos" | ||
| } | ||
| ] | ||
| ); | ||
| } | ||
| } | ||
| }) | ||
| .export(module); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5995
39.06%11
10%145
28.32%3
200%81
-11.96%1
Infinity%