summaryrefslogtreecommitdiffstats
path: root/scripts/create_sprite.js
blob: d03dc0f459f2de73f679a13878de091c0781df66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node

import SVGSpriter from "svg-sprite";
import { readFileSync, writeFileSync } from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));

const args = process.argv.slice(2);
const sprite = args.pop();

const spriter = new SVGSpriter({
    mode: {
        symbol: {
            dest: "",
            sprite,
        },
    },
    shape: {
        transform: [],
    },
});

for (const id of args) {
    const file = resolve(__dirname, `../dist/${id}.svg`);
    spriter.add(file, null, readFileSync(file, { encoding: "utf-8" }));
}

spriter.compile((error, result) => {
    if (error) {
        console.error(error);
        return;
    }
    for (var mode in result) {
        for (var resource in result[mode]) {
            console.log(result[mode][resource].path);
            writeFileSync(
                result[mode][resource].path,
                result[mode][resource].contents
            );
        }
    }
});