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.

188 lines
4.8 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
  1. /**
  2. * Jake build script
  3. */
  4. var jake = require('jake'),
  5. browserify = require('browserify'),
  6. wrench = require('wrench'),
  7. fs = require('fs');
  8. require('jake-utils');
  9. // constants
  10. var DIST = './dist';
  11. var VIS = DIST + '/vis.js';
  12. var VIS_CSS = DIST + '/vis.css';
  13. var VIS_TMP = DIST + '/vis.js.tmp';
  14. var VIS_MIN = DIST + '/vis.min.js';
  15. /**
  16. * default task
  17. */
  18. desc('Default task: build all libraries');
  19. task('default', ['build', 'minify'], function () {
  20. console.log('done');
  21. });
  22. /**
  23. * build the visualization library vis.js
  24. */
  25. desc('Build the visualization library vis.js');
  26. task('build', {async: true}, function () {
  27. jake.mkdirP(DIST);
  28. // concatenate and stringify the css files
  29. concat({
  30. src: [
  31. './src/timeline/component/css/timeline.css',
  32. './src/timeline/component/css/panel.css',
  33. './src/timeline/component/css/groupset.css',
  34. './src/timeline/component/css/itemset.css',
  35. './src/timeline/component/css/item.css',
  36. './src/timeline/component/css/timeaxis.css',
  37. './src/timeline/component/css/currenttime.css',
  38. './src/timeline/component/css/customtime.css'
  39. ],
  40. dest: VIS_CSS,
  41. separator: '\n'
  42. });
  43. console.log('created ' + VIS_CSS);
  44. // concatenate the script files
  45. concat({
  46. dest: VIS_TMP,
  47. src: [
  48. './src/module/imports.js',
  49. './src/shim.js',
  50. './src/util.js',
  51. './src/events.js',
  52. './src/EventBus.js',
  53. './src/DataSet.js',
  54. './src/DataView.js',
  55. './src/timeline/TimeStep.js',
  56. './src/timeline/Stack.js',
  57. './src/timeline/Range.js',
  58. './src/timeline/Controller.js',
  59. './src/timeline/component/Component.js',
  60. './src/timeline/component/Panel.js',
  61. './src/timeline/component/RootPanel.js',
  62. './src/timeline/component/TimeAxis.js',
  63. './src/timeline/component/CurrentTime.js',
  64. './src/timeline/component/CustomTime.js',
  65. './src/timeline/component/ItemSet.js',
  66. './src/timeline/component/item/*.js',
  67. './src/timeline/component/Group.js',
  68. './src/timeline/component/GroupSet.js',
  69. './src/timeline/Timeline.js',
  70. './src/graph/dotparser.js',
  71. './src/graph/shapes.js',
  72. './src/graph/Node.js',
  73. './src/graph/Edge.js',
  74. './src/graph/Popup.js',
  75. './src/graph/Groups.js',
  76. './src/graph/Images.js',
  77. './src/graph/graphMixins/physics/PhysicsMixin.js',
  78. './src/graph/graphMixins/physics/BarnesHut.js',
  79. './src/graph/graphMixins/physics/Repulsion.js',
  80. './src/graph/graphMixins/ManipulationMixin.js',
  81. './src/graph/graphMixins/SectorsMixin.js',
  82. './src/graph/graphMixins/ClusterMixin.js',
  83. './src/graph/graphMixins/SelectionMixin.js',
  84. './src/graph/graphMixins/NavigationMixin.js',
  85. './src/graph/graphMixins/MixinLoader.js',
  86. './src/graph/Graph.js',
  87. './src/module/exports.js'
  88. ],
  89. separator: '\n'
  90. });
  91. // copy images
  92. wrench.copyDirSyncRecursive('./src/graph/img', DIST+ '/img', {
  93. forceDelete: true
  94. });
  95. // copy css
  96. wrench.copyDirSyncRecursive('./src/graph/css', DIST+ '/css', {
  97. forceDelete: true
  98. });
  99. var timeStart = Date.now();
  100. // bundle the concatenated script and dependencies into one file
  101. var b = browserify();
  102. b.add(VIS_TMP);
  103. b.bundle({
  104. standalone: 'vis'
  105. }, function (err, code) {
  106. if(err) {
  107. throw err;
  108. }
  109. console.log("browserify",Date.now() - timeStart); timeStart = Date.now();
  110. // add header and footer
  111. var lib = read('./src/module/header.js') + code;
  112. // write bundled file
  113. write(VIS, lib);
  114. console.log('created js' + VIS);
  115. // remove temporary file
  116. fs.unlinkSync(VIS_TMP);
  117. // update version number and stuff in the javascript files
  118. replacePlaceholders(VIS);
  119. complete();
  120. });
  121. });
  122. /**
  123. * minify the visualization library vis.js
  124. */
  125. desc('Minify the visualization library vis.js');
  126. task('minify', function () {
  127. // minify javascript
  128. minify({
  129. src: VIS,
  130. dest: VIS_MIN,
  131. header: read('./src/module/header.js')
  132. });
  133. // update version number and stuff in the javascript files
  134. replacePlaceholders(VIS_MIN);
  135. console.log('created minified ' + VIS_MIN);
  136. });
  137. /**
  138. * test task
  139. */
  140. desc('Test the library');
  141. task('test', function () {
  142. // TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
  143. var filelist = new jake.FileList();
  144. filelist.include([
  145. './test/**/*.js'
  146. ]);
  147. var files = filelist.toArray();
  148. files.forEach(function (file) {
  149. require('./' + file);
  150. });
  151. console.log('Executed ' + files.length + ' test files successfully');
  152. });
  153. /**
  154. * replace version, date, and name placeholders in the provided file
  155. * @param {String} filename
  156. */
  157. var replacePlaceholders = function (filename) {
  158. replace({
  159. replacements: [
  160. {pattern: '@@date', replacement: today()},
  161. {pattern: '@@version', replacement: version()}
  162. ],
  163. src: filename
  164. });
  165. };