Skip to content

Commit 00a8379

Browse files
committed
Flatten the code
1 parent 8419af9 commit 00a8379

File tree

1 file changed

+75
-81
lines changed

1 file changed

+75
-81
lines changed

index.mjs

Lines changed: 75 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ if (!name) {
77
process.exit(1)
88
}
99

10-
function p(...args) {
11-
return path.join(name, ...args)
12-
}
10+
const p = (...args) => path.join(name, ...args)
1311

1412
async function patchFiles(files, ...replacers) {
1513
for (const file of [files].flat()) {
@@ -32,26 +30,29 @@ async function patchPackage(...dependencies) {
3230
await fs.writeJson(file, pkg, { spaces: 2 })
3331
}
3432

35-
await spinner('replace favicon', async () => {
36-
const req = await fetch('https://cdn.jsdelivr.net/gh/zerodevx/sveltekit-starter/favicon.png')
37-
const blob = await req.blob()
38-
const buf = await blob.arrayBuffer()
39-
await fs.writeFile(p('static', 'favicon.png'), Buffer.from(buf))
40-
})
33+
let done
34+
const loading = spinner('patching...', () => new Promise((resolve) => (done = resolve)))
35+
36+
const favicon = await fetch('https://cdn.jsdelivr.net/gh/zerodevx/sveltekit-starter/favicon.png')
37+
.then((r) => r.blob())
38+
.then((b) => b.arrayBuffer())
39+
await fs.writeFile(p('static', 'favicon.png'), Buffer.from(favicon))
40+
41+
await patchPackage(
42+
'+tailwindcss',
43+
'+autoprefixer',
44+
'+@tailwindcss/typography',
45+
'+@fontsource-variable/inter',
46+
'+@iconify/tailwind',
47+
'+@iconify-json/mdi',
48+
'+prettier-plugin-tailwindcss',
49+
'-@sveltejs/adapter-auto',
50+
'+@sveltejs/adapter-static'
51+
)
4152

42-
await spinner('add tailwindcss, iconify and fontsource', async () => {
43-
await patchPackage(
44-
'+tailwindcss',
45-
'+autoprefixer',
46-
'+@tailwindcss/typography',
47-
'+@fontsource-variable/inter',
48-
'+@iconify/tailwind',
49-
'+@iconify-json/mdi',
50-
'+prettier-plugin-tailwindcss'
51-
)
52-
await fs.writeFile(
53-
p('tailwind.config.js'),
54-
`import { addIconSelectors } from '@iconify/tailwind'
53+
await fs.writeFile(
54+
p('tailwind.config.js'),
55+
`import { addIconSelectors } from '@iconify/tailwind'
5556
import typography from '@tailwindcss/typography'
5657
import dt from 'tailwindcss/defaultTheme'
5758
@@ -67,84 +68,77 @@ export default {
6768
},
6869
plugins: [addIconSelectors(['mdi']), typography]
6970
}`
70-
)
71-
await fs.writeFile(
72-
p('postcss.config.js'),
73-
`/** @type {import('postcss-load-config').Config} */
71+
)
72+
73+
await fs.writeFile(
74+
p('postcss.config.js'),
75+
`/** @type {import('postcss-load-config').Config} */
7476
export default {
7577
plugins: {
7678
tailwindcss: {},
7779
autoprefixer: {}
7880
}
7981
}`
80-
)
81-
await fs.writeFile(
82-
p('src', 'app.pcss'),
83-
`/* Write your global styles here, in PostCSS syntax */
82+
)
83+
84+
await fs.writeFile(
85+
p('src', 'app.css'),
86+
`/* Write your global styles here, in PostCSS syntax */
8487
@tailwind base;
8588
@tailwind components;
8689
@tailwind utilities;`
87-
)
88-
await fs.writeFile(
89-
p('src', 'routes', '+layout.svelte'),
90-
`<script>
90+
)
91+
92+
await fs.writeFile(
93+
p('src', 'routes', '+layout.svelte'),
94+
`<script>
9195
import '@fontsource-variable/inter'
92-
import '../app.pcss'
96+
import '../app.css'
9397
</script>
9498
9599
<slot />`
96-
)
97-
await patchFiles(p('src', 'routes', '+page.svelte'), [
98-
`</h1>`,
99-
`</h1>\n<span class="iconify mdi--heart text-xl text-red-600 animate-pulse" />\n`
100-
])
101-
await patchFiles(
102-
p('svelte.config.js'),
103-
[`import`, `import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\nimport`],
104-
[`\n};`, `, preprocess: [vitePreprocess()]\n};`]
105-
)
106-
})
100+
)
107101

108-
await spinner('patch prettier', async () => {
109-
let config = await fs.readJson(p('.prettierrc'))
110-
config.plugins = [...config.plugins, 'prettier-plugin-tailwindcss']
111-
await fs.writeJson(p('.prettierrc'), {
112-
...config,
113-
printWidth: 100,
114-
useTabs: false,
115-
semi: false,
116-
singleQuote: true,
117-
trailingComma: 'none',
118-
proseWrap: 'always',
119-
svelteSortOrder: 'options-scripts-markup-styles',
120-
svelteIndentScriptAndStyle: false
121-
})
122-
})
102+
await fs.writeFile(p('src', 'routes', '+layout.js'), `export const prerender = true\n`)
123103

124-
await spinner('patch eslint', async () => {
125-
await patchFiles(p('eslint.config.js'), [
126-
`languageOptions`,
127-
`rules:{'no-tabs':'error','no-unexpected-multiline':'error'}, languageOptions`
128-
])
129-
})
104+
await patchFiles(p('src', 'routes', '+page.svelte'), [
105+
`</h1>`,
106+
`</h1>\n<span class="iconify mdi--heart text-xl text-red-600 animate-pulse" />\n`
107+
])
130108

131-
await spinner('add adapter-static', async () => {
132-
await patchFiles(p('svelte.config.js'), [`adapter-auto`, `adapter-static`])
133-
await patchPackage(name, '-@sveltejs/adapter-auto', '+@sveltejs/adapter-static')
134-
await fs.writeFile(p('src', 'routes', '+layout.js'), `export const prerender = true\n`)
135-
})
109+
await patchFiles(
110+
p('svelte.config.js'),
111+
[`import`, `import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\nimport`],
112+
[
113+
`adapter-auto';`,
114+
`adapter-static';\nimport { readFileSync } from 'node:fs';\n\nconst { version: name } = JSON.parse(readFileSync(new URL('package.json', import.meta.url), 'utf8'));`
115+
],
116+
[`adapter()`, `adapter(), version:{name}`],
117+
[`\n};`, `, preprocess: [vitePreprocess()]\n};`]
118+
)
119+
120+
await patchFiles(p('eslint.config.js'), [
121+
`languageOptions`,
122+
`rules:{'no-tabs':'error','no-unexpected-multiline':'error'}, languageOptions`
123+
])
136124

137-
await spinner('add versioning', async () => {
138-
await patchFiles(
139-
p('svelte.config.js'),
140-
[
141-
`static';`,
142-
`static';\nimport { readFileSync } from 'node:fs'\n\nconst { version: name } = JSON.parse(readFileSync(new URL('package.json', import.meta.url), 'utf8'))\n`
143-
],
144-
[`adapter()`, `adapter(), version:{name}`]
145-
)
125+
const prettier = await fs.readJson(p('.prettierrc'))
126+
prettier.plugins = [...prettier.plugins, 'prettier-plugin-tailwindcss']
127+
await fs.writeJson(p('.prettierrc'), {
128+
...prettier,
129+
printWidth: 100,
130+
useTabs: false,
131+
semi: false,
132+
singleQuote: true,
133+
trailingComma: 'none',
134+
proseWrap: 'always',
135+
svelteSortOrder: 'options-scripts-markup-styles',
136+
svelteIndentScriptAndStyle: false
146137
})
147138

139+
done()
140+
await loading
141+
148142
echo`
149143
All done! Complete the setup with:
150144

0 commit comments

Comments
 (0)