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.

167 lines
4.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /**
  2. * Jake build script
  3. */
  4. var jake = require('jake'),
  5. browserify = require('browserify'),
  6. path = require('path'),
  7. fs = require('fs');
  8. require('jake-utils');
  9. // constants
  10. var VIS = './vis.js';
  11. var VIS_TMP = './vis.js.tmp';
  12. var VIS_MIN = './vis.min.js';
  13. /**
  14. * default task
  15. */
  16. desc('Execute all tasks: build all libraries');
  17. task('default', ['build', 'minify', 'test'], function () {
  18. console.log('done');
  19. });
  20. /**
  21. * build the visualization library vis.js
  22. */
  23. desc('Build the visualization library vis.js');
  24. task('build', {async: true}, function () {
  25. // concatenate and stringify the css files
  26. var result = concat({
  27. src: [
  28. './src/timeline/component/css/timeline.css',
  29. './src/timeline/component/css/panel.css',
  30. './src/timeline/component/css/groupset.css',
  31. './src/timeline/component/css/itemset.css',
  32. './src/timeline/component/css/item.css',
  33. './src/timeline/component/css/timeaxis.css'
  34. ],
  35. header: '/* vis.js stylesheet */',
  36. separator: '\n'
  37. });
  38. var cssText = JSON.stringify(result.code);
  39. // concatenate the script files
  40. concat({
  41. dest: VIS_TMP,
  42. src: [
  43. './src/module/imports.js',
  44. './src/shim.js',
  45. './src/util.js',
  46. './src/events.js',
  47. './src/EventBus.js',
  48. './src/DataSet.js',
  49. './src/DataView.js',
  50. './src/timeline/TimeStep.js',
  51. './src/timeline/Stack.js',
  52. './src/timeline/Range.js',
  53. './src/timeline/Controller.js',
  54. './src/timeline/component/Component.js',
  55. './src/timeline/component/Panel.js',
  56. './src/timeline/component/RootPanel.js',
  57. './src/timeline/component/TimeAxis.js',
  58. './src/timeline/component/ItemSet.js',
  59. './src/timeline/component/item/*.js',
  60. './src/timeline/component/Group.js',
  61. './src/timeline/component/GroupSet.js',
  62. './src/timeline/Timeline.js',
  63. './src/graph/dotparser.js',
  64. './src/graph/shapes.js',
  65. './src/graph/Node.js',
  66. './src/graph/Edge.js',
  67. './src/graph/Popup.js',
  68. './src/graph/Groups.js',
  69. './src/graph/Images.js',
  70. './src/graph/Graph.js',
  71. './src/module/exports.js'
  72. ],
  73. separator: '\n',
  74. // Note: we insert the css as a string in the javascript code here
  75. // the css will be injected on load of the javascript library
  76. footer: '// inject css\n' +
  77. 'util.loadCss(' + cssText + ');\n'
  78. });
  79. // bundle the concatenated script and dependencies into one file
  80. var b = browserify();
  81. b.add(VIS_TMP);
  82. b.bundle({
  83. standalone: 'vis'
  84. }, function (err, code) {
  85. if(err) {
  86. throw err;
  87. }
  88. // add header and footer
  89. var lib = read('./src/module/header.js') + code;
  90. // write bundled file
  91. write(VIS, lib);
  92. console.log('created ' + VIS);
  93. // remove temporary file
  94. fs.unlinkSync(VIS_TMP);
  95. // update version number and stuff in the javascript files
  96. replacePlaceholders(VIS);
  97. complete();
  98. });
  99. });
  100. /**
  101. * minify the visualization library vis.js
  102. */
  103. desc('Minify the visualization library vis.js');
  104. task('minify', function () {
  105. // minify javascript
  106. minify({
  107. src: VIS,
  108. dest: VIS_MIN,
  109. header: read('./src/module/header.js')
  110. });
  111. // update version number and stuff in the javascript files
  112. replacePlaceholders(VIS_MIN);
  113. console.log('created ' + VIS_MIN);
  114. });
  115. /**
  116. * test task
  117. */
  118. desc('Test the library');
  119. task('test', ['build'], function () {
  120. // TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
  121. var filelist = new jake.FileList();
  122. filelist.include([
  123. './test/**/*.js'
  124. ]);
  125. var files = filelist.toArray();
  126. files.forEach(function (file) {
  127. require('./' + file);
  128. });
  129. console.log('Executed ' + files.length + ' test files successfully');
  130. });
  131. /**
  132. * replace version, date, and name placeholders in the provided file
  133. * @param {String} filename
  134. */
  135. var replacePlaceholders = function (filename) {
  136. replace({
  137. replacements: [
  138. {pattern: '@@date', replacement: today()},
  139. {pattern: '@@version', replacement: version()}
  140. ],
  141. src: filename
  142. });
  143. };