diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/build.sh | 19 | ||||
| -rwxr-xr-x | scripts/build_showcase.sh | 6 | ||||
| -rw-r--r-- | scripts/create_sprite.js | 44 | 
3 files changed, 47 insertions, 22 deletions
| diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index 62822a3..0000000 --- a/scripts/build.sh +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | handle () { | ||
| 4 | scour -i "$1" -o "output${1#"src/icons"}" \ | ||
| 5 | --enable-viewboxing \ | ||
| 6 | --enable-id-stripping \ | ||
| 7 | --enable-comment-stripping \ | ||
| 8 | --remove-descriptive-elements \ | ||
| 9 | --strip-xml-prolog \ | ||
| 10 | --shorten-ids | ||
| 11 | } | ||
| 12 | export -f handle | ||
| 13 | |||
| 14 | mkdir -p output | ||
| 15 | |||
| 16 | find "src/icons" \ | ||
| 17 | -type f \ | ||
| 18 | -name "*.svg" \ | ||
| 19 | -print0 | parallel -0 handle {} | ||
| diff --git a/scripts/build_showcase.sh b/scripts/build_showcase.sh index 402c5e4..3ebcfea 100755 --- a/scripts/build_showcase.sh +++ b/scripts/build_showcase.sh | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | mkdir -p showcase | 3 | mkdir -p showcase | 
| 4 | 4 | ||
| 5 | mapfile -d $'\0' icon_files < <(find "output" \ | 5 | mapfile -d $'\0' icon_files < <(find "dist" \ | 
| 6 | -type f \ | 6 | -type f \ | 
| 7 | -name "*.svg" \ | 7 | -name "*.svg" \ | 
| 8 | -print0) | 8 | -print0) | 
| @@ -11,7 +11,7 @@ icons="[]" | |||
| 11 | 11 | ||
| 12 | for icon in "${icon_files[@]}"; do | 12 | for icon in "${icon_files[@]}"; do | 
| 13 | title=$icon | 13 | title=$icon | 
| 14 | title=${title#output/} | 14 | title=${title#dist/} | 
| 15 | title=${title%.svg} | 15 | title=${title%.svg} | 
| 16 | 16 | ||
| 17 | content=$(cat "$icon" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g') | 17 | content=$(cat "$icon" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g') | 
| @@ -28,7 +28,7 @@ icons=$(echo "$icons" | jq "sort_by(.title)") | |||
| 28 | 28 | ||
| 29 | echo "{ icons: $icons }" > "$meta_file" | 29 | echo "{ icons: $icons }" > "$meta_file" | 
| 30 | 30 | ||
| 31 | pandoc "src/showcase/index.md" \ | 31 | echo "" | pandoc \ | 
| 32 | -f markdown \ | 32 | -f markdown \ | 
| 33 | -t html5 \ | 33 | -t html5 \ | 
| 34 | --no-highlight \ | 34 | --no-highlight \ | 
| diff --git a/scripts/create_sprite.js b/scripts/create_sprite.js new file mode 100644 index 0000000..d03dc0f --- /dev/null +++ b/scripts/create_sprite.js | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/usr/bin/env node | ||
| 2 | |||
| 3 | import SVGSpriter from "svg-sprite"; | ||
| 4 | import { readFileSync, writeFileSync } from "fs"; | ||
| 5 | import { dirname, resolve } from "path"; | ||
| 6 | import { fileURLToPath } from "url"; | ||
| 7 | |||
| 8 | const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| 9 | |||
| 10 | const args = process.argv.slice(2); | ||
| 11 | const sprite = args.pop(); | ||
| 12 | |||
| 13 | const spriter = new SVGSpriter({ | ||
| 14 | mode: { | ||
| 15 | symbol: { | ||
| 16 | dest: "", | ||
| 17 | sprite, | ||
| 18 | }, | ||
| 19 | }, | ||
| 20 | shape: { | ||
| 21 | transform: [], | ||
| 22 | }, | ||
| 23 | }); | ||
| 24 | |||
| 25 | for (const id of args) { | ||
| 26 | const file = resolve(__dirname, `../dist/${id}.svg`); | ||
| 27 | spriter.add(file, null, readFileSync(file, { encoding: "utf-8" })); | ||
| 28 | } | ||
| 29 | |||
| 30 | spriter.compile((error, result) => { | ||
| 31 | if (error) { | ||
| 32 | console.error(error); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | for (var mode in result) { | ||
| 36 | for (var resource in result[mode]) { | ||
| 37 | console.log(result[mode][resource].path); | ||
| 38 | writeFileSync( | ||
| 39 | result[mode][resource].path, | ||
| 40 | result[mode][resource].contents | ||
| 41 | ); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | }); | ||
