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