Gruntfile.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. module.exports = function(grunt) {
  2. basicPath = 'static/js/threeJsHelper/';
  3. sshServers = {};
  4. sshServers['compute3'] = 'ipepdvcompute3.ipe.kit.edu';
  5. sshServers['anka'] = 'anka-visualize.anka.kit.edu';
  6. username = 'visualization';
  7. tarName = '<%= pkg.name %>.tar';
  8. deployCommand = function(env, server) {
  9. var command = 'ssh ' + username + '@' + sshServers[server]
  10. + ' "cd /usr/local/www/;'
  11. + 'rm -rf <%= pkg.name %>;'
  12. + 'tar -xf ' + tarName + ';'
  13. + 'cp -r <%= pkg.name %>/* visualization-' + env + '/;"'
  14. + 'cp visualization-' + env + '/visualization/settings_env.py.' + env + '.' + server + ' visualization-' + env + '/visualization/settings_env.py;';
  15. return command;
  16. }
  17. var env = grunt.option('env') || 'staging';
  18. var server = grunt.option('server') || 'compute3';
  19. grunt.initConfig({
  20. pkg: grunt.file.readJSON('package.json'),
  21. files : {
  22. dest: basicPath + 'dist/<%= pkg.jsname %>.js',
  23. destMin: basicPath + 'dist/<%= pkg.jsname %>.min.js'
  24. },
  25. concat: {
  26. options: {
  27. separator: ';'
  28. },
  29. dist: {
  30. src: [ basicPath + 'src/**/*.js' ],
  31. dest: '<%= files.dest %>'
  32. }
  33. },
  34. shell: {
  35. pkg: {
  36. command: 'tar -cf ' + tarName + ' ../<%= pkg.name %>/* --exclude=settings_env.py --exclude=node_modules --exclude=__pycache__ --exclude=Gruntfile.js --exclude=startDev.sh --exclude=manage.py'
  37. },
  38. rmPkg: {
  39. command: 'rm ' + tarName
  40. },
  41. scp: {
  42. command: 'scp ' + tarName + ' visualization@' + sshServers[server] + ':/usr/local/www/'
  43. },
  44. deploy: {
  45. command: deployCommand(env, server)
  46. },
  47. bumbVersion: {
  48. command: 'npm version patch'
  49. }
  50. },
  51. watch: {
  52. scripts: {
  53. files: [ basicPath + 'src/**/*.js' ],
  54. tasks: ['dev-watch'],
  55. options : {
  56. interrupt: true
  57. }
  58. }
  59. },
  60. uglify: {
  61. options: {
  62. // the banner is inserted at the top of the output
  63. banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
  64. },
  65. dist: {
  66. files: {
  67. '<%= files.destMin %>': ['<%= files.dest %>']
  68. }
  69. }
  70. }
  71. });
  72. grunt.loadNpmTasks('grunt-contrib-concat');
  73. grunt.loadNpmTasks('grunt-contrib-watch');
  74. grunt.loadNpmTasks('grunt-shell');
  75. grunt.loadNpmTasks('grunt-contrib-uglify');
  76. grunt.registerTask('default', ['concat', 'uglify']);
  77. grunt.registerTask('dev-watch', ['concat', 'uglify' ]);
  78. grunt.registerTask('update-version', ['shell:bumbVersion']);
  79. grunt.registerTask('deploy', ['concat', 'uglify', 'shell:pkg', 'shell:scp', 'shell:rmPkg', 'shell:deploy']);
  80. };