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.

152 lines
3.7 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/component/css/panel.css',
  29. './src/component/css/item.css',
  30. './src/component/css/timeaxis.css'
  31. ],
  32. header: '/* vis.js stylesheet */',
  33. separator: '\n'
  34. });
  35. var cssText = JSON.stringify(result.code);
  36. // concatenate the script files
  37. concat({
  38. dest: VIS_TMP,
  39. src: [
  40. './src/module/imports.js',
  41. './src/util.js',
  42. './src/events.js',
  43. './src/timestep.js',
  44. './src/dataset.js',
  45. './src/stack.js',
  46. './src/range.js',
  47. './src/eventbus.js',
  48. './src/controller.js',
  49. './src/component/component.js',
  50. './src/component/panel.js',
  51. './src/component/rootpanel.js',
  52. './src/component/timeaxis.js',
  53. './src/component/itemset.js',
  54. './src/component/item/*.js',
  55. './src/visualization/timeline.js',
  56. './src/module/exports.js'
  57. ],
  58. separator: '\n',
  59. // Note: we insert the css as a string in the javascript code here
  60. // the css will be injected on load of the javascript library
  61. footer: '// inject css\n' +
  62. 'util.loadCss(' + cssText + ');\n'
  63. });
  64. // bundle the concatenated script and dependencies into one file
  65. var b = browserify();
  66. b.add(VIS_TMP);
  67. b.bundle({
  68. standalone: 'vis'
  69. }, function (err, code) {
  70. if(err) {
  71. throw err;
  72. }
  73. // add header and footer
  74. var lib = read('./src/header.js') + code;
  75. // write bundled file
  76. write(VIS, lib);
  77. console.log('created ' + VIS);
  78. // remove temporary file
  79. fs.unlinkSync(VIS_TMP);
  80. // update version number and stuff in the javascript files
  81. replacePlaceholders(VIS);
  82. complete();
  83. });
  84. });
  85. /**
  86. * minify the visualization library vis.js
  87. */
  88. desc('Minify the visualization library vis.js');
  89. task('minify', function () {
  90. // minify javascript
  91. minify({
  92. src: VIS,
  93. dest: VIS_MIN,
  94. header: read('./src/header.js')
  95. });
  96. // update version number and stuff in the javascript files
  97. replacePlaceholders(VIS_MIN);
  98. console.log('created ' + VIS_MIN);
  99. });
  100. /**
  101. * test task
  102. */
  103. desc('Test the library');
  104. task('test', ['build'], function () {
  105. // TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
  106. var filelist = new jake.FileList();
  107. filelist.include([
  108. './test/**/*.js'
  109. ]);
  110. var files = filelist.toArray();
  111. files.forEach(function (file) {
  112. require('./' + file);
  113. });
  114. console.log('Executed ' + files.length + ' test files successfully');
  115. });
  116. /**
  117. * replace version, date, and name placeholders in the provided file
  118. * @param {String} filename
  119. */
  120. var replacePlaceholders = function (filename) {
  121. replace({
  122. replacements: [
  123. {pattern: '@@date', replacement: today()},
  124. {pattern: '@@version', replacement: version()}
  125. ],
  126. src: filename
  127. });
  128. };