gruntfile.js 6.0 KB

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