util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var program = require('commander')
  2. , debug = require('debug')('crowi:console:util')
  3. , colors = require('colors')
  4. , crowi = new (require('../lib/crowi'))(__dirname + '/../', process.env)
  5. ;
  6. crowi.init()
  7. .then(function(app) {
  8. program
  9. .version(crowi.version);
  10. program
  11. .command('count-page-length')
  12. .action(function (cmd, env) {
  13. var Page = crowi.model('Page');
  14. var stream = Page.getStreamOfFindAll();
  15. var pages = [];
  16. stream.on('data', function (doc) {
  17. if (!doc.creator || !doc.revision) {
  18. return ;
  19. }
  20. pages.push({
  21. path: doc.path,
  22. body: doc.revision.body,
  23. author: doc.creator.username,
  24. });
  25. }).on('error', function (err) {
  26. // TODO: handle err
  27. debug('Error stream:', err);
  28. }).on('close', function () {
  29. // all done
  30. pages.forEach(function(page, i) {
  31. console.log('%d\t%s', page.body.length, page.path);
  32. });
  33. process.exit(0);
  34. });
  35. });
  36. program.parse(process.argv);
  37. }).catch(crowi.exitOnError);