gruntfile.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. stylelint: {
  25. options: {
  26. formatter: 'unix',
  27. },
  28. src: [
  29. 'src/less/**/*.less',
  30. ]
  31. },
  32. copy: {
  33. js: {
  34. expand: true,
  35. cwd: './node_modules',
  36. dest: './js/',
  37. flatten: true,
  38. filter: 'isFile',
  39. timestamp: true,
  40. src: [
  41. './leaflet/dist/leaflet.js',
  42. ]
  43. },
  44. css: {
  45. expand: true,
  46. cwd: './node_modules',
  47. dest: './css/',
  48. flatten: true,
  49. filter: 'isFile',
  50. timestamp: true,
  51. src: [
  52. './leaflet/dist/leaflet.css',
  53. ]
  54. },
  55. leaflet_images: {
  56. expand: true,
  57. cwd: './node_modules',
  58. dest: './css/images/',
  59. flatten: true,
  60. filter: 'isFile',
  61. timestamp: true,
  62. src: [
  63. './leaflet/dist/images/*.png',
  64. ]
  65. },
  66. },
  67. concat: {
  68. head_and_body: {
  69. options: {
  70. separator: ';'
  71. },
  72. files: {
  73. 'js/searx.head.js': ['src/js/head/*.js'],
  74. 'js/searx.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js']
  75. }
  76. }
  77. },
  78. uglify: {
  79. options: {
  80. banner: '/*! simple/searx.min.js | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n',
  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. banner: '/*! searx | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n'
  166. },
  167. files: {
  168. "css/searx.css": "src/less/style.less",
  169. "css/searx-rtl.css": "src/less/style-rtl.less"
  170. }
  171. },
  172. production: {
  173. options: {
  174. paths: ["less"],
  175. plugins: [
  176. new (require('less-plugin-clean-css'))()
  177. ],
  178. sourceMap: true,
  179. sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';},
  180. outputSourceFiles: false,
  181. sourceMapRootpath: '../',
  182. banner: '/*! searx | <%= grunt.template.today("dd-mm-yyyy") %> | <%= process.env.GIT_URL %> */\n'
  183. },
  184. files: {
  185. "css/searx.min.css": "src/less/style.less",
  186. "css/searx-rtl.min.css": "src/less/style-rtl.less"
  187. }
  188. },
  189. },
  190. });
  191. grunt.loadNpmTasks('grunt-contrib-watch');
  192. grunt.loadNpmTasks('grunt-contrib-copy');
  193. grunt.loadNpmTasks('grunt-contrib-uglify');
  194. grunt.loadNpmTasks('grunt-contrib-jshint');
  195. grunt.loadNpmTasks('grunt-contrib-concat');
  196. grunt.loadNpmTasks('grunt-contrib-less');
  197. grunt.loadNpmTasks('grunt-contrib-cssmin');
  198. grunt.loadNpmTasks('grunt-webfont');
  199. grunt.loadNpmTasks('grunt-stylelint');
  200. grunt.registerTask('test', ['jshint']);
  201. grunt.registerTask('default', [
  202. 'jshint',
  203. 'stylelint',
  204. 'copy',
  205. 'concat',
  206. 'uglify',
  207. 'less:development',
  208. 'less:production'
  209. ]);
  210. };