You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.2 KiB

  1. var fs = require('fs');
  2. var jade = require('jade');
  3. var package = require('./package');
  4. var hl = require('./docs/helpers/highlight');
  5. var linktype = require('./docs/helpers/linktype');
  6. var href = require('./docs/helpers/href');
  7. var klass = require('./docs/helpers/klass');
  8. // add custom jade filters
  9. require('./docs/helpers/filters')(jade);
  10. function getVersion() {
  11. var hist = fs.readFileSync('./History.md', 'utf8').replace(/\r/g, '\n').split('\n');
  12. for (var i = 0; i < hist.length; ++i) {
  13. var line = (hist[i] || '').trim();
  14. if (!line) {
  15. continue;
  16. }
  17. var match = /^\s*([^\s]+)\s/.exec(line);
  18. if (match && match[1]) {
  19. return match[1];
  20. }
  21. }
  22. throw new Error('no match found');
  23. }
  24. function getUnstable(ver) {
  25. ver = ver.replace('-pre');
  26. var spl = ver.split('.');
  27. spl = spl.map(function(i) {
  28. return parseInt(i, 10);
  29. });
  30. spl[1]++;
  31. spl[2] = 'x';
  32. return spl.join('.');
  33. }
  34. // use last release
  35. package.version = getVersion();
  36. package.unstable = getUnstable(package.version);
  37. var filemap = require('./docs/source');
  38. var files = Object.keys(filemap);
  39. function jadeify(filename, options, newfile) {
  40. options = options || {};
  41. options.package = package;
  42. options.hl = hl;
  43. options.linktype = linktype;
  44. options.href = href;
  45. options.klass = klass;
  46. jade.renderFile(filename, options, function(err, str) {
  47. if (err) {
  48. console.error(err.stack);
  49. return;
  50. }
  51. newfile = newfile || filename.replace('.jade', '.html');
  52. fs.writeFile(newfile, str, function(err) {
  53. if (err) {
  54. console.error('could not write', err.stack);
  55. } else {
  56. console.log('%s : rendered ', new Date, newfile);
  57. }
  58. });
  59. });
  60. }
  61. files.forEach(function(file) {
  62. var filename = __dirname + '/' + file;
  63. jadeify(filename, filemap[file]);
  64. if (process.argv[2] === '--watch') {
  65. fs.watchFile(filename, {interval: 1000}, function(cur, prev) {
  66. if (cur.mtime > prev.mtime) {
  67. jadeify(filename, filemap[file]);
  68. }
  69. });
  70. }
  71. });
  72. var acquit = require('./docs/source/acquit');
  73. var acquitFiles = Object.keys(acquit);
  74. acquitFiles.forEach(function(file) {
  75. var filename = __dirname + '/docs/acquit.jade';
  76. jadeify(filename, acquit[file], __dirname + '/docs/' + file);
  77. });