1
0

Fix sveld plugin

This commit is contained in:
venashial
2022-07-16 16:28:15 -07:00
parent fe415cbd77
commit 75f6235111
+22 -15
View File
@@ -11,6 +11,28 @@ export default function sveld() {
// TODO: Make more efficient & handle typescript types with `svelte2tsx` // TODO: Make more efficient & handle typescript types with `svelte2tsx`
async transform(src, id) { async transform(src, id) {
if (id.includes('/src/components/')) { if (id.includes('/src/components/')) {
await generateComponentApi()
}
},
async buildStart() {
await generateComponentApi()
},
}
}
async function parseRaw(raw, filePath) {
let { code } = await svelte.preprocess(raw, preprocess, {
filename: filePath,
})
return new ComponentParser({
verbose: false,
}).parseSvelteComponent(code, {
filePath,
moduleName: filePath,
})
}
async function generateComponentApi() {
const output = {} const output = {}
const componentFiles = await fs.readdir(path.resolve('./src/components')) const componentFiles = await fs.readdir(path.resolve('./src/components'))
@@ -28,19 +50,4 @@ export default function sveld() {
} }
await fs.writeFile(path.resolve('./generated/COMPONENT_API.json'), JSON.stringify(output)) await fs.writeFile(path.resolve('./generated/COMPONENT_API.json'), JSON.stringify(output))
}
},
}
}
async function parseRaw(raw, filePath) {
let { code } = await svelte.preprocess(raw, preprocess, {
filename: filePath,
})
return new ComponentParser({
verbose: false,
}).parseSvelteComponent(code, {
filePath,
moduleName: filePath,
})
} }