Skip to content

Instantly share code, notes, and snippets.

@dalf
Last active November 10, 2021 21:03
Show Gist options
  • Save dalf/504cc61047369df159d8e031dbcd652c to your computer and use it in GitHub Desktop.
Save dalf/504cc61047369df159d8e031dbcd652c to your computer and use it in GitHub Desktop.
/*jshint esversion: 6 */
module.exports = function(grunt) {
const path = require('path');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
scripts: {
files: ['src/**'],
tasks: ['eslint', 'copy', 'concat', 'uglify', 'less:development', 'less:production']
}
},
eslint: {
options: {
configFile: '.eslintrc.json',
failOnError: false
},
target: [
'src/js/main/*.js',
'src/js/head/*.js',
'../__common__/js/*.js'
],
},
stylelint: {
options: {
formatter: 'unix',
},
src: [
'src/less/**/*.less',
]
},
copy: {
js: {
expand: true,
cwd: './node_modules',
dest: './js/',
flatten: true,
filter: 'isFile',
timestamp: true,
src: [
'./leaflet/dist/leaflet.js',
]
},
css: {
expand: true,
cwd: './node_modules',
dest: './css/',
flatten: true,
filter: 'isFile',
timestamp: true,
src: [
'./leaflet/dist/leaflet.css',
]
},
leaflet_images: {
expand: true,
cwd: './node_modules',
dest: './css/images/',
flatten: true,
filter: 'isFile',
timestamp: true,
src: [
'./leaflet/dist/images/*.png',
]
},
},
concat: {
head_and_body: {
options: {
separator: ';'
},
files: {
'js/searxng.head.js': ['src/js/head/*.js'],
'js/searxng.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js']
}
}
},
uglify: {
options: {
output: {
comments: 'some'
},
ie8: false,
warnings: true,
compress: false,
mangle: true,
sourceMap: true
},
dist: {
files: {
'js/searxng.head.min.js': ['js/searxng.head.js'],
'js/searxng.min.js': ['js/searxng.js']
}
}
},
less: {
development: {
options: {
paths: ["less"],
},
files: {
"css/searxng.css": "src/less/style.less",
"css/searxng-rtl.css": "src/less/style-rtl.less"
}
},
production: {
options: {
paths: ["less"],
plugins: [
new (require('less-plugin-clean-css'))()
],
sourceMap: true,
sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';},
outputSourceFiles: false,
sourceMapRootpath: '../',
},
files: {
"css/searxng.min.css": "src/less/style.less",
"css/searxng-rtl.min.css": "src/less/style-rtl.less"
}
},
},
svg2jinja: {
all: {
src: {
'error': 'node_modules/ionicons/dist/svg/alert-circle.svg',
'warning': 'node_modules/ionicons/dist/svg/alert-circle-outline.svg',
'close': 'node_modules/ionicons/dist/svg/close-outline.svg',
'chevron-up-outline': 'node_modules/ionicons/dist/svg/chevron-up-outline.svg',
'menu-outline': 'node_modules/ionicons/dist/svg/menu-outline.svg',
'ellipsis-vertical-outline': 'node_modules/ionicons/dist/svg/ellipsis-vertical-outline.svg',
'magnet-outline': 'node_modules/ionicons/dist/svg/magnet-outline.svg',
'globe-outline': 'node_modules/ionicons/dist/svg/globe-outline.svg',
'search-outline': 'node_modules/ionicons/dist/svg/search-outline.svg',
'image-outline': 'node_modules/ionicons/dist/svg/image-outline.svg',
'play-outline': 'node_modules/ionicons/dist/svg/play-outline.svg',
'newspaper-outline': 'node_modules/ionicons/dist/svg/newspaper-outline.svg',
'location-outline': 'node_modules/ionicons/dist/svg/location-outline.svg',
'musical-notes-outline': 'node_modules/ionicons/dist/svg/musical-notes-outline.svg',
'layers-outline': 'node_modules/ionicons/dist/svg/layers-outline.svg',
'school-outline': 'node_modules/ionicons/dist/svg/school-outline.svg',
'file-tray-full-outline': 'node_modules/ionicons/dist/svg/file-tray-full-outline.svg',
'people-outline': 'node_modules/ionicons/dist/svg/people-outline.svg',
},
dest: '../../../templates/simple/icons.html'
},
},
});
grunt.registerMultiTask('svg2jinja', 'Create Jinja2 macro', function() {
const ejs = require('ejs');
const icons = {}
for(const iconName in this.data.src) {
const svgFileName = this.data.src[iconName];
try {
icons[iconName] = grunt.file.read(svgFileName, { encoding: 'utf8' })
} catch (err) {
console.error(err)
}
}
const template = `{%- set icons = {
<% for (const iconName in icons) { %> '<%- iconName %>':'<%- icons[iconName] %>',
<% } %>
}
-%}
{% macro icon(action, alt) -%}
<span class="ion-icon-big ion-{{ action }}" title="{{ alt }}">{{ icons[action] | safe }}</span>
{%- endmacro %}
{% macro icon_small(action) -%}
<span class="ion-icon ion-{{ action }}" title="{{ alt }}">{{ icons[action] | safe }}</span>
{%- endmacro %}
`;
const result = ejs.render(template, { icons });
grunt.file.write(this.data.dest, result, { encoding: 'utf8' });
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-stylelint');
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('test', ['jshint']);
grunt.registerTask('default', [
'eslint',
'stylelint',
'copy',
'concat',
'svg2jinja',
'uglify',
'less:development',
'less:production'
]);
};
{
"devDependencies": {
"eslint": "^8.0.1",
"grunt": "~1.4.1",
"grunt-contrib-concat": "~2.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^4.0.0",
"grunt-contrib-jshint": "~3.1.1",
"grunt-contrib-less": "~3.0.0",
"grunt-contrib-uglify": "~5.0.1",
"grunt-contrib-watch": "~1.1.0",
"grunt-eslint": "^23.0.0",
"grunt-stylelint": "^0.16.0",
"grunt-exec": "^3.0.0",
"ionicons": "^5.5.4",
"less": "^4.1.1",
"less-plugin-clean-css": "^1.5.1",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^22.0.0",
"ejs": "^3.1.6"
},
"dependencies": {
"autocomplete-js": "2.7.1",
"leaflet": "^1.7.1",
"normalize.css": "^8.0.1",
"svg2png": "^4.1.1"
},
"scripts": {
"all": "npm install && grunt",
"build": "grunt",
"eslint": "grunt eslint",
"watch": "grunt watch",
"webfont": "grunt webfont",
"clean": "rm -Rf node_modules package-lock.json ion.less",
"stylelint": "grunt stylelint",
"stylelint-fix": "grunt stylelint --fix"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment