Skip to content

Instantly share code, notes, and snippets.

@andy0130tw
Created August 2, 2023 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy0130tw/cb627375e146f3d1b6a323854e0c8aa6 to your computer and use it in GitHub Desktop.
Save andy0130tw/cb627375e146f3d1b6a323854e0c8aa6 to your computer and use it in GitHub Desktop.
SvelteKit will skip generating types if it cannot detect TypeScript environment. Therefore this ad-hoc script is born.
import child_process from 'node:child_process'
function run(cmd) {
child_process.execSync(cmd, { stdio: 'inherit' })
}
;(async () => {
let ts_patched = false
try {
await import('typescript')
} catch (err) {
console.log('Typescript not detected. Installing...')
run('npm i typescript -D')
ts_patched = true
}
console.log('Running sync...')
run('npx --yes svelte-kit sync')
if (ts_patched) {
console.log('Removing typescript...')
run('npm r typescript')
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment