@@ -4,6 +4,11 @@ import { create } from 'create-svelte' // @latest
44
55$ . verbose = false
66
7+ // Fix stupid `zx -i` logic (https://github.com/google/zx/blob/main/src/deps.ts)
8+ const SHIM_I = 'imp' + 'ort'
9+ const SHIM_F = 'fr' + 'om'
10+ const SHIM_R = 'req' + 'uire'
11+
712async function patchFiles ( files , ...replacers ) {
813 for ( const file of [ files ] . flat ( ) ) {
914 let contents = await fs . readFile ( file , 'utf8' )
@@ -46,7 +51,7 @@ export async function addTailwindcss({ name }) {
4651 await patchPackage ( name , '+@tailwindcss/typography' )
4752 await patchFiles ( path . join ( name , 'tailwind.config.cjs' ) , [
4853 'plugins: []' ,
49- `plugins: [require ('@tailwindcss/typography')]`
54+ `plugins: [${ SHIM_R } ('@tailwindcss/typography')]`
5055 ] )
5156}
5257
@@ -85,11 +90,11 @@ export async function addFontsource({ name }) {
8590 await patchPackage ( name , '+@fontsource/inter' )
8691 await patchFiles ( path . join ( name , 'src' , 'routes' , '+layout.svelte' ) , [
8792 `<script>` ,
88- `<script>import '@fontsource/inter/variable.css';`
93+ `<script>${ SHIM_I } '@fontsource/inter/variable.css';`
8994 ] )
9095 await patchFiles (
9196 path . join ( name , 'tailwind.config.cjs' ) ,
92- [ `const config` , `const dt = require ('tailwindcss/defaultTheme');\n\nconst config` ] ,
97+ [ `const config` , `const dt = ${ SHIM_R } ('tailwindcss/defaultTheme');\n\nconst config` ] ,
9398 [ `extend: {}` , `extend: { fontFamily: { sans: ['InterVariable', ...dt.fontFamily.sans] } }` ]
9499 )
95100}
@@ -98,11 +103,11 @@ export async function addIconify({ name }) {
98103 await patchPackage ( name , '+@iconify/svelte' , '+@iconify-icons/mdi' )
99104 await fs . outputFile (
100105 path . join ( name , 'src' , 'lib' , 'icons.js' ) ,
101- `import Icon, { addIcon } from '@iconify/svelte/dist/OfflineIcon.svelte';\nimport check from '@iconify-icons/mdi/check';\n\naddIcon('check', check);\n\nexport { Icon as default }\n`
106+ `${ SHIM_I } Icon, { addIcon } ${ SHIM_F } '@iconify/svelte/dist/OfflineIcon.svelte';\n ${ SHIM_I } check ${ SHIM_F } '@iconify-icons/mdi/check';\n\naddIcon('check', check);\n\nexport { Icon as default }\n`
102107 )
103108 await patchFiles (
104109 path . join ( name , 'src' , 'routes' , '+page.svelte' ) ,
105- [ `<h1>` , `<script>import Icon from '$lib/icons'</script>\n\n<h1>` ] ,
110+ [ `<h1>` , `<script>${ SHIM_I } Icon ${ SHIM_F } '$lib/icons'</script>\n\n<h1>` ] ,
106111 [ `</p>` , `</p>\n\n<Icon class="w-12 h-12" icon='check' />\n` ]
107112 )
108113}
0 commit comments