You've already forked AstralRinth
forked from didirus/AstralRinth
Fix sveld plugin
This commit is contained in:
@@ -11,25 +11,12 @@ 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/')) {
|
||||||
const output = {}
|
await generateComponentApi()
|
||||||
|
|
||||||
const componentFiles = await fs.readdir(path.resolve('./src/components'))
|
|
||||||
|
|
||||||
for (const fileName of componentFiles.filter((name) => name.endsWith('.svelte'))) {
|
|
||||||
const filePath = path.resolve('./src/components', fileName)
|
|
||||||
const raw = (await fs.readFile(filePath)).toString()
|
|
||||||
output[fileName] = await parseRaw(raw, filePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await fs.mkdir(path.resolve('./generated'))
|
|
||||||
} catch {
|
|
||||||
// Do nothing, directory already exists
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile(path.resolve('./generated/COMPONENT_API.json'), JSON.stringify(output))
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async buildStart() {
|
||||||
|
await generateComponentApi()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,3 +31,23 @@ async function parseRaw(raw, filePath) {
|
|||||||
moduleName: filePath,
|
moduleName: filePath,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function generateComponentApi() {
|
||||||
|
const output = {}
|
||||||
|
|
||||||
|
const componentFiles = await fs.readdir(path.resolve('./src/components'))
|
||||||
|
|
||||||
|
for (const fileName of componentFiles.filter((name) => name.endsWith('.svelte'))) {
|
||||||
|
const filePath = path.resolve('./src/components', fileName)
|
||||||
|
const raw = (await fs.readFile(filePath)).toString()
|
||||||
|
output[fileName] = await parseRaw(raw, filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.mkdir(path.resolve('./generated'))
|
||||||
|
} catch {
|
||||||
|
// Do nothing, directory already exists
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(path.resolve('./generated/COMPONENT_API.json'), JSON.stringify(output))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user