@@ -4,6 +4,11 @@ import { create } from 'create-svelte' // @latest
4
4
5
5
$ . verbose = false
6
6
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
+
7
12
async function patchFiles ( files , ...replacers ) {
8
13
for ( const file of [ files ] . flat ( ) ) {
9
14
let contents = await fs . readFile ( file , 'utf8' )
@@ -46,7 +51,7 @@ export async function addTailwindcss({ name }) {
46
51
await patchPackage ( name , '+@tailwindcss/typography' )
47
52
await patchFiles ( path . join ( name , 'tailwind.config.cjs' ) , [
48
53
'plugins: []' ,
49
- `plugins: [require ('@tailwindcss/typography')]`
54
+ `plugins: [${ SHIM_R } ('@tailwindcss/typography')]`
50
55
] )
51
56
}
52
57
@@ -85,11 +90,11 @@ export async function addFontsource({ name }) {
85
90
await patchPackage ( name , '+@fontsource/inter' )
86
91
await patchFiles ( path . join ( name , 'src' , 'routes' , '+layout.svelte' ) , [
87
92
`<script>` ,
88
- `<script>import '@fontsource/inter/variable.css';`
93
+ `<script>${ SHIM_I } '@fontsource/inter/variable.css';`
89
94
] )
90
95
await patchFiles (
91
96
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` ] ,
93
98
[ `extend: {}` , `extend: { fontFamily: { sans: ['InterVariable', ...dt.fontFamily.sans] } }` ]
94
99
)
95
100
}
@@ -98,11 +103,11 @@ export async function addIconify({ name }) {
98
103
await patchPackage ( name , '+@iconify/svelte' , '+@iconify-icons/mdi' )
99
104
await fs . outputFile (
100
105
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`
102
107
)
103
108
await patchFiles (
104
109
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>` ] ,
106
111
[ `</p>` , `</p>\n\n<Icon class="w-12 h-12" icon='check' />\n` ]
107
112
)
108
113
}
0 commit comments