Skip to content

Commit 0a26318

Browse files
committed
Behold the Emergence
1 parent bbd01ae commit 0a26318

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

index.mjs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env zx
2+
3+
import { create } from 'create-svelte' // @latest
4+
5+
if (!argv._.length) {
6+
echo`Error: please specify the app name`
7+
process.exit(1)
8+
}
9+
const name = argv._[0]
10+
if (await fs.pathExists(name)) {
11+
if (!argv.o) {
12+
echo`Error: path ${path.sep}${name} already exists, specify -o flag to overwrite`
13+
process.exit(1)
14+
}
15+
await fs.remove(name)
16+
}
17+
18+
async function patchFile(filename, pattern, replacement) {
19+
const infile = await fs.readFile(filename, 'utf8')
20+
await fs.writeFile(filename, infile.replace(pattern, replacement))
21+
}
22+
23+
// Scaffold skeleton from `create-svelte`
24+
const template = argv.t || 'skeleton'
25+
await create(name, {
26+
name,
27+
template,
28+
types: 'checkjs',
29+
prettier: true,
30+
eslint: true,
31+
playwright: true,
32+
vitest: false
33+
})
34+
echo`- created ${template} template`
35+
36+
// Add `tailwindcss`
37+
await $`cd ${argv._[0]} && npx svelte-add@latest tailwindcss`.quiet()
38+
echo`- added tailwindcss`
39+
40+
// Patch `prettier`
41+
await fs.writeJson(
42+
path.join(name, '.prettierrc'),
43+
{
44+
...(await fs.readJson(path.join(name, '.prettierrc'))),
45+
printWidth: 100,
46+
useTabs: false,
47+
semi: false,
48+
singleQuote: true,
49+
trailingComma: 'none',
50+
proseWrap: 'always',
51+
svelteSortOrder: 'options-scripts-markup-styles',
52+
svelteIndentScriptAndStyle: false
53+
},
54+
{ spaces: 2 }
55+
)
56+
echo`- patched prettier config`
57+
58+
// Patch `eslint`
59+
await patchFile(
60+
path.join(name, '.eslintrc.cjs'),
61+
`}\n};`,
62+
`},\n\trules: { 'no-tabs': 'error', 'no-unexpected-multiline': 'error' }\n};`
63+
)
64+
echo`- patched eslint config`
65+
66+
// Use `adapter-static`
67+
await patchFile(path.join(name, 'package.json'), `adapter-auto`, `adapter-static`)
68+
await patchFile(path.join(name, 'svelte.config.js'), `adapter-auto`, `adapter-static`)
69+
await fs.outputFile(
70+
path.join(name, 'src', 'routes', '+layout.js'),
71+
`export const prerender = true\n`
72+
)
73+
echo`- patched adapter-static`
74+
75+
echo`
76+
All done! Complete the setup with:
77+
78+
$ cd ${name} && npm i && npm run format
79+
`

0 commit comments

Comments
 (0)