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.

171 lines
4.2 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. 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. './src/timeline/component/css/currenttime.css',
  35. './src/timeline/component/css/customtime.css'
  36. ],
  37. header: '/* vis.js stylesheet */',
  38. separator: '\n'
  39. });
  40. var cssText = JSON.stringify(result.code);
  41. // concatenate the script files
  42. concat({
  43. dest: VIS_TMP,
  44. src: [
  45. './src/module/imports.js',
  46. './src/shim.js',
  47. './src/util.js',
  48. './src/events.js',
  49. './src/EventBus.js',
  50. './src/DataSet.js',
  51. './src/DataView.js',
  52. './src/timeline/TimeStep.js',
  53. './src/timeline/Stack.js',
  54. './src/timeline/Range.js',
  55. './src/timeline/Controller.js',
  56. './src/timeline/component/Component.js',
  57. './src/timeline/component/Panel.js',
  58. './src/timeline/component/RootPanel.js',
  59. './src/timeline/component/TimeAxis.js',
  60. './src/timeline/component/CurrentTime.js',
  61. './src/timeline/component/CustomTime.js',
  62. './src/timeline/component/ItemSet.js',
  63. './src/timeline/component/item/*.js',
  64. './src/timeline/component/Group.js',
  65. './src/timeline/component/GroupSet.js',
  66. './src/timeline/Timeline.js',
  67. './src/graph/dotparser.js',
  68. './src/graph/shapes.js',
  69. './src/graph/Node.js',
  70. './src/graph/Edge.js',
  71. './src/graph/Popup.js',
  72. './src/graph/Groups.js',
  73. './src/graph/Images.js',
  74. './src/graph/Graph.js',
  75. './src/module/exports.js'
  76. ],
  77. separator: '\n',
  78. // Note: we insert the css as a string in the javascript code here
  79. // the css will be injected on load of the javascript library
  80. footer: '// inject css\n' +
  81. 'util.loadCss(' + cssText + ');\n'
  82. });
  83. // bundle the concatenated script and dependencies into one file
  84. var b = browserify();
  85. b.add(VIS_TMP);
  86. b.bundle({
  87. standalone: 'vis'
  88. }, function (err, code) {
  89. if(err) {
  90. throw err;
  91. }
  92. // add header and footer
  93. var lib = read('./src/module/header.js') + code;
  94. // write bundled file
  95. write(VIS, lib);
  96. console.log('created ' + VIS);
  97. // remove temporary file
  98. fs.unlinkSync(VIS_TMP);
  99. // update version number and stuff in the javascript files
  100. replacePlaceholders(VIS);
  101. complete();
  102. });
  103. });
  104. /**
  105. * minify the visualization library vis.js
  106. */
  107. desc('Minify the visualization library vis.js');
  108. task('minify', function () {
  109. // minify javascript
  110. minify({
  111. src: VIS,
  112. dest: VIS_MIN,
  113. header: read('./src/module/header.js')
  114. });
  115. // update version number and stuff in the javascript files
  116. replacePlaceholders(VIS_MIN);
  117. console.log('created ' + VIS_MIN);
  118. });
  119. /**
  120. * test task
  121. */
  122. desc('Test the library');
  123. task('test', ['build'], function () {
  124. // TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
  125. var filelist = new jake.FileList();
  126. filelist.include([
  127. './test/**/*.js'
  128. ]);
  129. var files = filelist.toArray();
  130. files.forEach(function (file) {
  131. require('./' + file);
  132. });
  133. console.log('Executed ' + files.length + ' test files successfully');
  134. });
  135. /**
  136. * replace version, date, and name placeholders in the provided file
  137. * @param {String} filename
  138. */
  139. var replacePlaceholders = function (filename) {
  140. replace({
  141. replacements: [
  142. {pattern: '@@date', replacement: today()},
  143. {pattern: '@@version', replacement: version()}
  144. ],
  145. src: filename
  146. });
  147. };