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.

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