Doc.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var fs = require('fs');
  2. var Buffer = require('buffer').Buffer;
  3. function Doc() {
  4. }
  5. Doc.prototype.getClassName = function(filePath) {
  6. fs.open(filePath, 'r', function(err, fd) {
  7. var contents = "";
  8. var raw = new Buffer(1024);
  9. fs.read(fd, raw, 0, raw.length, null, function(err, bytesRead, buffer) {
  10. var buf = buffer.slice(0, bytesRead);
  11. contents += buf.toString().split('module.exports = ')[1].split(';')[0];
  12. fs.close(fd, function() {
  13. console.log(contents);
  14. })
  15. })
  16. })
  17. }
  18. Doc.prototype.getClassInfos = function(path) {
  19. var fileNames = fs.readdirSync(path);
  20. var classInfos = {};
  21. var that = this;
  22. for(var i in fileNames) {
  23. var className = fileNames[i].split('Controller.js')[0];
  24. classInfos[className] = {
  25. author : "",
  26. desc : "",
  27. funcs : that.getFunc(className)
  28. }
  29. }
  30. return classInfos;
  31. }
  32. Doc.prototype.getFunc = function(className) {
  33. var controllerName = className.charAt(0).toUpperCase() + className.slice(1);
  34. var Controller;
  35. try{
  36. Controller = require('../controllers/' + controllerName + 'Controller.js');
  37. var funcList = {};
  38. for(var i in Controller.prototype) {
  39. if(i.match('action')){
  40. funcList[i] = {
  41. author : "",
  42. desc : "",
  43. param : []
  44. }
  45. }
  46. }
  47. return funcList;
  48. } catch(e) {
  49. console.error(e);
  50. return null;
  51. }
  52. }
  53. module.exports = Doc;