gruntfile.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. module.exports = function(grunt) {
  2. const path = require('path');
  3. grunt.initConfig({
  4. pkg: grunt.file.readJSON('package.json'),
  5. watch: {
  6. scripts: {
  7. files: ['src/**'],
  8. tasks: ['jshint', 'copy', 'concat', 'uglify', 'less:development', 'less:production']
  9. }
  10. },
  11. jshint: {
  12. files: ['src/js/main/*.js', 'src/js/head/*.js', '../__common__/js/*.js'],
  13. options: {
  14. reporterOutput: "",
  15. proto: true,
  16. // options here to override JSHint defaults
  17. globals: {
  18. browser: true,
  19. jQuery: false,
  20. devel: true
  21. }
  22. }
  23. },
  24. copy: {
  25. js: {
  26. expand: true,
  27. cwd: './node_modules',
  28. dest: './js/',
  29. flatten: true,
  30. filter: 'isFile',
  31. timestamp: true,
  32. src: [
  33. './leaflet/dist/leaflet.js',
  34. ]
  35. },
  36. css: {
  37. expand: true,
  38. cwd: './node_modules',
  39. dest: './css/',
  40. flatten: true,
  41. filter: 'isFile',
  42. timestamp: true,
  43. src: [
  44. './leaflet/dist/leaflet.css',
  45. ]
  46. },
  47. leaflet_images: {
  48. expand: true,
  49. cwd: './node_modules',
  50. dest: './css/images/',
  51. flatten: true,
  52. filter: 'isFile',
  53. timestamp: true,
  54. src: [
  55. './leaflet/dist/images/*.png',
  56. ]
  57. },
  58. },
  59. concat: {
  60. head_and_body: {
  61. options: {
  62. separator: ';'
  63. },
  64. files: {
  65. 'js/searx.head.js': ['src/js/head/*.js'],
  66. 'js/searx.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js']
  67. }
  68. }
  69. },
  70. uglify: {
  71. options: {
  72. banner: '/*! simple/searx.min.js | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n',
  73. output: {
  74. comments: 'some'
  75. },
  76. ie8: false,
  77. warnings: true,
  78. compress: false,
  79. mangle: true,
  80. sourceMap: true
  81. },
  82. dist: {
  83. files: {
  84. 'js/searx.head.min.js': ['js/searx.head.js'],
  85. 'js/searx.min.js': ['js/searx.js']
  86. }
  87. }
  88. },
  89. webfont: {
  90. icons: {
  91. // src: 'node_modules/ionicons-npm/src/*.svg',
  92. src: [
  93. 'node_modules/ionicons-npm/src/navicon-round.svg',
  94. 'node_modules/ionicons-npm/src/search.svg',
  95. 'node_modules/ionicons-npm/src/play.svg',
  96. 'node_modules/ionicons-npm/src/link.svg',
  97. 'node_modules/ionicons-npm/src/chevron-up.svg',
  98. 'node_modules/ionicons-npm/src/chevron-left.svg',
  99. 'node_modules/ionicons-npm/src/chevron-right.svg',
  100. 'node_modules/ionicons-npm/src/arrow-down-a.svg',
  101. 'node_modules/ionicons-npm/src/arrow-up-a.svg',
  102. 'node_modules/ionicons-npm/src/arrow-swap.svg',
  103. 'node_modules/ionicons-npm/src/telephone.svg',
  104. 'node_modules/ionicons-npm/src/android-arrow-dropdown.svg',
  105. 'node_modules/ionicons-npm/src/android-globe.svg',
  106. 'node_modules/ionicons-npm/src/android-time.svg',
  107. 'node_modules/ionicons-npm/src/location.svg',
  108. 'node_modules/ionicons-npm/src/alert-circled.svg',
  109. 'node_modules/ionicons-npm/src/android-alert.svg',
  110. 'node_modules/ionicons-npm/src/ios-film-outline.svg',
  111. 'node_modules/ionicons-npm/src/music-note.svg',
  112. 'node_modules/ionicons-npm/src/ion-close-round.svg',
  113. 'node_modules/ionicons-npm/src/android-more-vertical.svg',
  114. 'src/fonts/magnet.svg',
  115. 'node_modules/ionicons-npm/src/android-close.svg',
  116. ],
  117. dest: 'fonts',
  118. destLess: 'src/generated',
  119. options: {
  120. font: 'ion',
  121. hashes : true,
  122. syntax: 'bem',
  123. styles : 'font,icon',
  124. types : 'eot,woff2,woff,ttf,svg',
  125. order : 'eot,woff2,woff,ttf,svg',
  126. stylesheets : ['css', 'less'],
  127. relativeFontPath : '../fonts/',
  128. autoHint : false,
  129. normalize : false,
  130. // ligatures : true,
  131. optimize : true,
  132. // fontHeight : 400,
  133. rename : function(name) {
  134. basename = path.basename(name);
  135. if (basename === 'android-alert.svg') {
  136. return 'error.svg';
  137. }
  138. if (basename === 'alert-circled.svg') {
  139. return 'warning.svg';
  140. }
  141. if (basename === 'ion-close-round.svg') {
  142. return 'close.svg';
  143. }
  144. return basename.replace(/(ios|md|android)-/i, '');
  145. },
  146. templateOptions: {
  147. baseClass: 'ion-icon',
  148. classPrefix: 'ion-'
  149. }
  150. }
  151. }
  152. },
  153. less: {
  154. development: {
  155. options: {
  156. paths: ["less"],
  157. banner: '/*! searx | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n'
  158. },
  159. files: {
  160. "css/searx.css": "src/less/style.less",
  161. "css/searx-rtl.css": "src/less/style-rtl.less"
  162. }
  163. },
  164. production: {
  165. options: {
  166. paths: ["less"],
  167. plugins: [
  168. new (require('less-plugin-clean-css'))()
  169. ],
  170. sourceMap: true,
  171. sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';},
  172. outputSourceFiles: false,
  173. sourceMapRootpath: '../',
  174. banner: '/*! searx | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n'
  175. },
  176. files: {
  177. "css/searx.min.css": "src/less/style.less",
  178. "css/searx-rtl.min.css": "src/less/style-rtl.less"
  179. }
  180. },
  181. },
  182. });
  183. grunt.loadNpmTasks('grunt-contrib-watch');
  184. grunt.loadNpmTasks('grunt-contrib-copy');
  185. grunt.loadNpmTasks('grunt-contrib-uglify');
  186. grunt.loadNpmTasks('grunt-contrib-jshint');
  187. grunt.loadNpmTasks('grunt-contrib-concat');
  188. grunt.loadNpmTasks('grunt-contrib-less');
  189. grunt.loadNpmTasks('grunt-contrib-cssmin');
  190. grunt.loadNpmTasks('grunt-webfont');
  191. grunt.registerTask('test', ['jshint']);
  192. grunt.registerTask('default', ['jshint', 'copy', 'concat', 'uglify', 'less:development', 'less:production']);
  193. };