gruntfile.js 6.1 KB

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