storybook-addon-valkyrie-theme/scripts/eject-typescript.mjs

30 lines
861 B
JavaScript
Raw Normal View History

2024-10-18 10:01:24 +00:00
#!/usr/bin/env zx
// Copy TS files and delete src
await $`cp -r ./src ./srcTS`;
await $`rm -rf ./src`;
await $`mkdir ./src`;
// Convert TS code to JS
await $`babel --no-babelrc --presets @babel/preset-typescript ./srcTS -d ./src --extensions \".js,.jsx,.ts,.tsx\" --ignore "./srcTS/typings.d.ts"`;
// Format the newly created .js files
await $`prettier --write ./src`;
// Add in minimal files required for the TS build setup
await $`touch ./src/dummy.ts`;
await $`printf "export {};" >> ./src/dummy.ts`;
await $`touch ./src/typings.d.ts`;
await $`printf 'declare module "global";' >> ./src/typings.d.ts`;
// Clean up
await $`rm -rf ./srcTS`;
console.log(
chalk.green.bold`
TypeScript Ejection complete!`,
chalk.green`
Addon code converted with JS. The TypeScript build setup is still available in case you want to adopt TypeScript in the future.
`
);