@@ -7,9 +7,7 @@ if (!name) {
7
7
process . exit ( 1 )
8
8
}
9
9
10
- function p ( ...args ) {
11
- return path . join ( name , ...args )
12
- }
10
+ const p = ( ...args ) => path . join ( name , ...args )
13
11
14
12
async function patchFiles ( files , ...replacers ) {
15
13
for ( const file of [ files ] . flat ( ) ) {
@@ -32,26 +30,29 @@ async function patchPackage(...dependencies) {
32
30
await fs . writeJson ( file , pkg , { spaces : 2 } )
33
31
}
34
32
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
+ )
41
52
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'
55
56
import typography from '@tailwindcss/typography'
56
57
import dt from 'tailwindcss/defaultTheme'
57
58
@@ -67,84 +68,77 @@ export default {
67
68
},
68
69
plugins: [addIconSelectors(['mdi']), typography]
69
70
}`
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} */
74
76
export default {
75
77
plugins: {
76
78
tailwindcss: {},
77
79
autoprefixer: {}
78
80
}
79
81
}`
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 */
84
87
@tailwind base;
85
88
@tailwind components;
86
89
@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>
91
95
import '@fontsource-variable/inter'
92
- import '../app.pcss '
96
+ import '../app.css '
93
97
</script>
94
98
95
99
<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
+ )
107
101
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` )
123
103
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
+ ] )
130
108
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
+ ] )
136
124
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
146
137
} )
147
138
139
+ done ( )
140
+ await loading
141
+
148
142
echo `
149
143
All done! Complete the setup with:
150
144
0 commit comments