-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.ts
58 lines (51 loc) · 1.23 KB
/
sprite.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/** @format */
import prompts from 'prompts';
import { spawn } from 'child_process';
import jsdom from 'jsdom';
import fs from 'node:fs';
(async () => {
const sprite = await prompts({
type: 'select',
name: 'sprite',
message: 'Select a sprite',
initial: 0,
choices: [
{
title: 'Bootstrap',
value: 'bootstrap',
description: 'Build sprite of Bootstrap icons'
}
]
});
if (sprite.sprite === 'bootstrap') {
const run = spawn(
'svg2sprite ./src/assets/icons ./src/assets/sprite.svg --inline --stripAttrs class --stripAttrs fill --stripAttrs xmlns',
{
shell: true,
stdio: 'inherit'
}
);
run.on('close', () => {
fs.readFile('./src/assets/sprite.svg', 'utf8', (error, sprite) => {
if (error) {
throw error;
}
jsdom.JSDOM.fromFile('./public/index.html').then(dom => {
// @ts-ignore
dom.window.document.querySelector("[data-sprite='bootstrap']").innerHTML = sprite.trim();
fs.writeFile('./public/index.html', dom.serialize(), error => {
if (error) {
throw error;
}
spawn('prettier --write index.html --log-level silent', {
shell: true,
stdio: 'inherit'
});
});
});
});
});
} else {
console.log('Ok, Bye!');
}
})();