Skip to content

Commit ce591eb

Browse files
committed
Fix zx autoinstall parsing
1 parent 82dd296 commit ce591eb

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This combo-patcher uses [zx](https://github.com/google/zx), so make sure that's
2020
run:
2121

2222
```
23-
$ zx --install https://raw.githubusercontent.com/zerodevx/sveltekit-starter/main/index.mjs <app-name> [flags]
23+
$ zx -i https://raw.githubusercontent.com/zerodevx/sveltekit-starter/main/index.mjs <app-name> [flags]
2424
```
2525

2626
This generates the starter based on the last known SvelteKit decisions, then saves the output to

index.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
712
async 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

Comments
 (0)