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.

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