Gruntfile.js 2.9 KB

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