diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/create_sprite.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/create_sprite.js b/scripts/create_sprite.js new file mode 100644 index 0000000..3bd4cf4 --- /dev/null +++ b/scripts/create_sprite.js | |||
@@ -0,0 +1,36 @@ | |||
1 | const SVGSpriter = require('svg-sprite'); | ||
2 | const fs = require('fs'); | ||
3 | const path = require('path'); | ||
4 | |||
5 | const args = process.argv.slice(2); | ||
6 | const sprite = args.pop(); | ||
7 | |||
8 | const spriter = new SVGSpriter({ | ||
9 | mode: { | ||
10 | symbol: { | ||
11 | dest: "", | ||
12 | sprite, | ||
13 | } | ||
14 | }, | ||
15 | shape: { | ||
16 | transform: [] | ||
17 | } | ||
18 | }); | ||
19 | |||
20 | for (const id of args) { | ||
21 | const file = path.resolve(__dirname, `../dist/${id}.svg`); | ||
22 | spriter.add(file, null, fs.readFileSync(file, { encoding: 'utf-8' })); | ||
23 | } | ||
24 | |||
25 | spriter.compile((error, result) => { | ||
26 | if (error) { | ||
27 | console.error(error); | ||
28 | return; | ||
29 | } | ||
30 | for (var mode in result) { | ||
31 | for (var resource in result[mode]) { | ||
32 | console.log(result[mode][resource].path); | ||
33 | fs.writeFileSync(result[mode][resource].path, result[mode][resource].contents); | ||
34 | } | ||
35 | } | ||
36 | }); | ||