builder/docgen.js
// Run document/unit test generator
Run document/unit test generator
Run document / unit test generator
function run () {
  var fcns = {};
  var mainpath = './../';
  var folders = fs.readdirSync(mainpath + 'lib','utf8');
  for (var i = 0;i < folders.length; i++) {
    if (folders[i].lastIndexOf('.js') === -1) {
      var files = fs.readdirSync(mainpath + 'lib/' + folders[i],'utf8');
      var outpath = mainpath + 'doc/' + folders[i];
      mkdirp(outpath, function(err) {
        if (err) console.log(err) 
      });
      for (var j = 0;j < files.length; j++) {
        var fundoc = gendoc(files[j],folders[i]);
        var funmd = genmd(fundoc);
        gentest(fundoc);
        name = fundoc.name;
        fcns[name] = {
          name: name,
          category: fundoc.category,
          link: '/' + folders[i] + '/' + name + '.md',
          summary: fundoc.summary,
          md: funmd
        }
        try {
          fs.writeFileSync(outpath + '/' + name + '.md',funmd);
        } catch (err) {
          console.log(err)
        }
      }
    }
  }
  var catgs = {};
  for (var k in fcns) {
    var fn = fcns[k];
    var categ = catgs[fn.category];
    if (!categ) {
      catgs[fn.category] = {};
    }
    catgs[fn.category][k] = fcns[k];
  }
  function categmd(catgs) {
    var categorical = "## Contents\n\n";
    categorical += Object.keys(catgs).sort().map(function(a) {
      var fn = catgs[a];
      return '### ' + a + '\n\n' +
      Object.keys(fn).sort().map(function(b) {
        return '- [' + fn[b].name + '](/doc' + fn[b].link + ')' + ' - ' + fn[b].summary;
      }).join('\n') + '\n';
    }).join('\n');
    fs.writeFileSync(mainpath + 'doc/contents.md',categorical);
  }
  function categhtml(catgs) {
    var categorical = "# Contents\n\n";
    categorical += Object.keys(catgs).sort().map(function(a) {
      var fn = catgs[a];
      return '## ' + a + '\n\n' +
      Object.keys(fn).sort().map(function(b) {
        var labcat = fn[b].category.toLowerCase().replace(/ /g,'-');
        return '- [' + fn[b].name + '](/doc/apidoc.html#-' + labcat + '-' + fn[b].name + ')' + ' - ' + fn[b].summary;
      }).join('\n') + '\n';
    }).join('\n');
    fs.writeFileSync('../../maxto.github.io/doc/contentshtml.md',categorical);
  }
  function apidoc(catgs) {
   var categorical = '';
   categorical += Object.keys(catgs).sort().map(function(a) {
    var fn = catgs[a];
    return '## ' + a + '\n\n' +
    Object.keys(fn).sort().map(function(b) {
      return fn[b].md;
    }).join('\n') + '\n';
  }).join('\n');
   fs.writeFileSync('../../maxto.github.io/doc/apidochtml.md',categorical);
 }
 categmd(catgs);
 categhtml(catgs);
 apidoc(catgs);
}
function run ( ) { var fcns = { } ; var mainpath = './../' ; var folders = fs . readdirSync ( mainpath + 'lib' , 'utf8' ) ; for ( var i = 0 ; i < folders . length ; i ++ ) { if ( folders [ i ] . lastIndexOf ( '.js' ) === - 1 ) { var files = fs . readdirSync ( mainpath + 'lib/' + folders [ i ] , 'utf8' ) ; var outpath = mainpath + 'doc/' + folders [ i ] ; mkdirp ( outpath , function ( err ) { if ( err ) console . log ( err ) } ) ; for ( var j = 0 ; j < files . length ; j ++ ) { var fundoc = gendoc ( files [ j ] , folders [ i ] ) ; var funmd = genmd ( fundoc ) ; gentest ( fundoc ) ; name = fundoc . name ; fcns [ name ] = { name : name , category : fundoc . category , link : '/' + folders [ i ] + '/' + name + '.md' , summary : fundoc . summary , md : funmd } try { fs . writeFileSync ( outpath + '/' + name + '.md' , funmd ) ; } catch ( err ) { console . log ( err ) } } } } var catgs = { } ; for ( var k in fcns ) { var fn = fcns [ k ] ; var categ = catgs [ fn . category ] ; if ( ! categ ) { catgs [ fn . category ] = { } ; } catgs [ fn . category ] [ k ] = fcns [ k ] ; } function categmd ( catgs ) { var categorical = "## Contents\n\n" ; categorical += Object . keys ( catgs ) . sort ( ) . map ( function ( a ) { var fn = catgs [ a ] ; return '### ' + a + '\n\n' + Object . keys ( fn ) . sort ( ) . map ( function ( b ) { return '- [' + fn [ b ] . name + '](/doc' + fn [ b ] . link + ')' + ' - ' + fn [ b ] . summary ; } ) . join ( '\n' ) + '\n' ; } ) . join ( '\n' ) ; fs . writeFileSync ( mainpath + 'doc/contents.md' , categorical ) ; } function categhtml ( catgs ) { var categorical = "# Contents\n\n" ; categorical += Object . keys ( catgs ) . sort ( ) . map ( function ( a ) { var fn = catgs [ a ] ; return '## ' + a + '\n\n' + Object . keys ( fn ) . sort ( ) . map ( function ( b ) { var labcat = fn [ b ] . category . toLowerCase ( ) . replace ( / / g , '-' ) ; return '- [' + fn [ b ] . name + '](/doc/apidoc.html#-' + labcat + '-' + fn [ b ] . name + ')' + ' - ' + fn [ b ] . summary ; } ) . join ( '\n' ) + '\n' ; } ) . join ( '\n' ) ; fs . writeFileSync ( '../../maxto.github.io/doc/contentshtml.md' , categorical ) ; } function apidoc ( catgs ) { var categorical = '' ; categorical += Object . keys ( catgs ) . sort ( ) . map ( function ( a ) { var fn = catgs [ a ] ; return '## ' + a + '\n\n' + Object . keys ( fn ) . sort ( ) . map ( function ( b ) { return fn [ b ] . md ; } ) . join ( '\n' ) + '\n' ; } ) . join ( '\n' ) ; fs . writeFileSync ( '../../maxto.github.io/doc/apidochtml.md' , categorical ) ; } categmd ( catgs ) ; categhtml ( catgs ) ; apidoc ( catgs ) ; }
Run document/unit test generator
Run document / unit test generator
// get category folders and functions // generate doc // generaye markdown // generate test // set categories // create CONTENTS.md for Markdown docs // create CONTENTS.md for HTML docs // ex. - [isarray](/doc/apiref.html#-test-isarray) // create APIDOC.md // build