|
1 | | -import { convertPreset } from '@visbot/webvsc'; |
2 | | -import { basename, extname } from 'node:path'; |
3 | 1 | import { stat } from 'node:fs/promises'; |
| 2 | +import { basename, extname } from 'node:path'; |
| 3 | +import { convertPreset } from '@visbot/webvsc'; |
4 | 4 |
|
5 | 5 | export default function ViteAvsPlugin() { |
6 | | - return { |
7 | | - name: 'avs', |
8 | | - async transform(code: string, id: string) { |
9 | | - if (!/\.avs$/.test(id) && !/\.wvs$/.test(id)) { |
10 | | - return; |
11 | | - } |
| 6 | + return { |
| 7 | + name: 'avs', |
| 8 | + async transform(code: string, id: string) { |
| 9 | + if (!/\.avs$/.test(id) && !/\.wvs$/.test(id)) { |
| 10 | + return; |
| 11 | + } |
12 | 12 |
|
13 | | - const textEncoder = new TextEncoder(); |
| 13 | + const textEncoder = new TextEncoder(); |
14 | 14 |
|
15 | | - const input = textEncoder.encode(code) |
16 | | - const ext = extname(id); |
17 | | - const name = basename(id, ext); |
18 | | - const date = (await stat(id)).mtime || new Date(); |
| 15 | + const input = textEncoder.encode(code); |
| 16 | + const ext = extname(id); |
| 17 | + const name = basename(id, ext); |
| 18 | + const date = (await stat(id)).mtime || new Date(); |
19 | 19 |
|
20 | | - const output = convertPreset(input, name, date); |
| 20 | + const output = convertPreset(input, name, date); |
21 | 21 |
|
22 | | - return { |
23 | | - code: [ |
24 | | - `const data = ${JSON.stringify(output)};`, |
25 | | - 'export default data;' |
26 | | - ].join('') |
27 | | - }; |
28 | | - } |
29 | | - } |
| 22 | + return { |
| 23 | + code: [`const data = ${JSON.stringify(output)};`, 'export default data;'].join(''), |
| 24 | + }; |
| 25 | + }, |
| 26 | + }; |
30 | 27 | } |
0 commit comments