-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
52 lines (41 loc) · 1.18 KB
/
handler.js
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
import { resolve } from 'node:path'
import fs from 'node:fs'
function find (obj) {
if (typeof obj === 'object') {
if (obj.name === '@vituum/vite-plugin-latte') {
return obj
} else {
for (const key in obj) {
const result = find(obj[key])
if (result !== null) {
return result
}
}
}
}
return null
}
const DEFAULT_CONFIG_FILES = [
'vite.config.js',
'vite.config.mjs',
'vite.config.ts',
'vite.config.cjs',
'vite.config.mts',
'vite.config.cts'
]
let resolvedPath
for (const filename of DEFAULT_CONFIG_FILES) {
const filePath = resolve(process.cwd(), filename)
if (!fs.existsSync(filePath)) continue
resolvedPath = filePath
break
}
const vite = (await import(resolvedPath)).default
let params = JSON.parse(process.argv[4])
const name = process.argv[2]
const type = process.argv[3]
params = params.map(value => Buffer.from(value, 'base64').toString('utf-8'))
const output = await find(vite.plugins)._options[type][name](...params)
if (output) {
console.log(Buffer.from(output.toString(), 'utf-8').toString('base64'))
}