vis.js is a dynamic, browser-based visualization library
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.

102 lines
2.8 KiB

  1. // Update the version numbers and library sizes in index.md
  2. var fs = require('fs'),
  3. zlib = require('zlib');
  4. var VIS = 'vis.js',
  5. VIS_MIN = 'vis.min.js',
  6. INDEX = 'index.html';
  7. // get development size
  8. function developmentSize(callback) {
  9. fs.readFile(VIS, function (err, data) {
  10. if (!err) {
  11. var size = Math.round(data.length / 1024) + ' kB';
  12. callback(null, size);
  13. }
  14. else {
  15. callback(err);
  16. }
  17. });
  18. }
  19. // get (gzipped) production size
  20. function productionSize(callback) {
  21. fs.readFile(VIS_MIN, function (err, data) {
  22. if (!err) {
  23. zlib.gzip(data, function (err, data) {
  24. if (!err) {
  25. var size = Math.round(data.length / 1024) + ' kB';
  26. callback(null, size)
  27. }
  28. else {
  29. callback(err);
  30. }
  31. });
  32. }
  33. else {
  34. callback(err);
  35. }
  36. });
  37. }
  38. // get version
  39. function version(callback) {
  40. fs.readFile(VIS_MIN, function (err, data) {
  41. if (!err) {
  42. var match = /@version\s*([\w\.-]*)/i.exec(data);
  43. var version = undefined;
  44. if (match) {
  45. version = match[1];
  46. }
  47. callback(null, version);
  48. }
  49. else {
  50. callback(err);
  51. }
  52. });
  53. }
  54. // update version and library sizes in index.md
  55. function updateVersion(developmentSize, productionSize, version, callback) {
  56. fs.readFile(INDEX, function (err, data) {
  57. if (!err) {
  58. data = String(data);
  59. data = data.replace(/<span id="development-size">([\w\s]*)<\/span>/g,
  60. '<span id="development-size">' + developmentSize + '</span>');
  61. data = data.replace(/<span id="production-size">([\w\s]*)<\/span>/g,
  62. '<span id="production-size">' + productionSize + '</span>');
  63. data = data.replace(/<span class="version">([\w\.-]*)<\/span>/g,
  64. '<span class="version">' + version + '</span>');
  65. fs.writeFile(INDEX, data, callback);
  66. }
  67. else {
  68. callback(err);
  69. }
  70. });
  71. }
  72. developmentSize(function (err, devSize) {
  73. console.log('development size: ' + devSize);
  74. productionSize(function (err, prodSize) {
  75. console.log('production size: ' + prodSize);
  76. version(function (err, version) {
  77. console.log('version: ' + version);
  78. if (devSize && prodSize && version) {
  79. updateVersion(devSize, prodSize, version, function (err, res) {
  80. if (err) {
  81. console.log(err);
  82. }
  83. else {
  84. console.log('done');
  85. }
  86. });
  87. }
  88. else {
  89. }
  90. });
  91. });
  92. });