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.

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