Gruntfile.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var projs = [
  2. 'tmerc',
  3. 'utm',
  4. 'sterea',
  5. 'stere',
  6. 'somerc',
  7. 'omerc',
  8. 'lcc',
  9. 'krovak',
  10. 'cass',
  11. 'laea',
  12. 'aea',
  13. 'gnom',
  14. 'cea',
  15. 'eqc',
  16. 'poly',
  17. 'nzmg',
  18. 'mill',
  19. 'sinu',
  20. 'moll',
  21. 'eqdc',
  22. 'vandg',
  23. 'aeqd'
  24. ];
  25. module.exports = function(grunt) {
  26. grunt.initConfig({
  27. pkg: grunt.file.readJSON('package.json'),
  28. connect: {
  29. server: {
  30. options: {
  31. port: process.env.PORT || 8080,
  32. base: '.'
  33. }
  34. }
  35. },
  36. mocha_phantomjs: {
  37. all: {
  38. options: {
  39. reporter: "dot",
  40. urls: [ //my ide requries process.env.IP and PORT
  41. "http://" + (process.env.IP || "127.0.0.1") + ":" + (process.env.PORT || "8080") + "/test/amd.html",
  42. "http://" + (process.env.IP || "127.0.0.1") + ":" + (process.env.PORT || "8080") + "/test/opt.html"
  43. ]
  44. }
  45. }
  46. },
  47. jshint: {
  48. options: {
  49. jshintrc: "./.jshintrc"
  50. },
  51. all: ['./lib/*.js', './lib/*/*.js']
  52. },
  53. browserify: {
  54. all: {
  55. files: {
  56. 'dist/proj4-src.js': ['lib/index.js'],
  57. },
  58. options: {
  59. standalone: 'proj4',
  60. alias: [
  61. './projs:./includedProjections'
  62. ]
  63. }
  64. }
  65. },
  66. uglify: {
  67. options: {
  68. report: 'gzip',
  69. mangle:{
  70. except: ['proj4','Projection','Point']
  71. },
  72. },
  73. all: {
  74. src: 'dist/proj4-src.js',
  75. dest: 'dist/proj4.js'
  76. }
  77. }
  78. });
  79. grunt.loadNpmTasks('grunt-browserify');
  80. grunt.loadNpmTasks('grunt-contrib-uglify');
  81. grunt.loadNpmTasks('grunt-contrib-jshint');
  82. grunt.loadNpmTasks('grunt-contrib-connect');
  83. grunt.loadNpmTasks('grunt-mocha-phantomjs');
  84. grunt.registerTask('custom',function(){
  85. grunt.task.run('browserify', 'uglify');
  86. var projections = this.args;
  87. if(projections[0]==='default'){
  88. grunt.file.write('./projs.js','module.exports = function(){}');
  89. return;
  90. }
  91. if(projections[0]==='all'){
  92. projections = projs;
  93. }
  94. grunt.file.write('./projs.js',[
  95. "var projs = [",
  96. " require('./lib/projections/"+projections.join("'),\n\trequire('./lib/projections/")+"')",
  97. "];",
  98. "module.exports = function(proj4){",
  99. " projs.forEach(function(proj){",
  100. " proj4.Proj.projections.add(proj);",
  101. " });",
  102. "}"
  103. ].join("\n"));
  104. });
  105. grunt.registerTask('build',function(){
  106. var args = this.args.length?this.args[0].split(','):['default'];
  107. grunt.task.run('jshint', 'custom:'+args.join(':'));
  108. });
  109. grunt.registerTask('default', ['build:all', 'connect','mocha_phantomjs']);
  110. };