build.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var fs = require("fs");
  2. var path = require("path");
  3. var panino = require("panino");
  4. var srcPath = __dirname + "/../lib/ace";
  5. var buildType = process.argv.splice(2)[0];
  6. var options = {
  7. title : "Ace API",
  8. parseType : "jsd",
  9. linkFormat : function(linkHtml) {
  10. var href = linkHtml.href;
  11. var o = href.match(/(.+)\.html(#.+)/);
  12. var c = href.match(/#(.+)/);
  13. if ( o !== null ) {
  14. href = href.replace(href, '#nav=api&api=' + o[1]);// + '&section=' + o[2]);
  15. }
  16. linkHtml.href = href;
  17. return linkHtml;
  18. },
  19. output : "../api/",
  20. outputAssets : "../api/resources",
  21. skin : "./template/jade/layout.jade",
  22. assets : "./template/resources",
  23. additionalObjs : "./additionalObjs.json",
  24. exclude : ["**/*_test.js", "**/mode/**", "default_commands.js", "multi_select_commands.js", "**/test/**", "**/theme/**", "**/worker/**"],
  25. index : "./index.md"
  26. };
  27. files = [srcPath];
  28. panino.parse(files, options, function (err, ast) {
  29. if (err) {
  30. console.error(err);
  31. process.exit(1);
  32. }
  33. panino.render(buildType || 'html', ast, options, function (err) {
  34. if (err) {
  35. console.error(err);
  36. process.exit(1);
  37. }
  38. /*fs.readdir(options.output, function (err, files) {
  39. files.forEach(function(file) {
  40. if (file.match(/\.html$/)) {
  41. var outFile = options.output + "/" + file;
  42. fs.readFile(outFile, "utf8", function(err, data) {
  43. var otherPageRegExp = new RegExp('<a href="(.+?.html)(#.+?)?"', "g");
  44. var m;
  45. if ( (m = data.match(otherPageRegExp)) ) {
  46. console.log(m)
  47. data = data.replace(otherPageRegExp, '<a href="#nav=api&api=' + m[1] + '&section=' + m[2] + '"')
  48. }
  49. fs.writeFile(outFile, data, function (err) {
  50. if (err) throw err;
  51. });
  52. });
  53. }
  54. });
  55. });*/
  56. });
  57. });