forked from sveltejs/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·160 lines (135 loc) · 3.86 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { bold, cyan, gray, green, red } from 'kleur/colors';
import prompts from 'prompts';
import { create } from './index.js';
import { dist } from './utils.js';
// prettier-ignore
const disclaimer = `
${bold(cyan('Welcome to SvelteKit!'))}
${bold(red('This is beta software; expect bugs and missing features.'))}
Problems? Open an issue on ${cyan('https://github.com/sveltejs/kit/issues')} if none exists already.
`;
const { version } = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8'));
async function main() {
console.log(gray(`\ncreate-svelte version ${version}`));
console.log(disclaimer);
let cwd = process.argv[2] || '.';
if (cwd === '.') {
const opts = await prompts([
{
type: 'text',
name: 'dir',
message: 'Where should we create your project?\n (leave blank to use current directory)'
}
]);
if (opts.dir) {
cwd = opts.dir;
}
}
if (fs.existsSync(cwd)) {
if (fs.readdirSync(cwd).length > 0) {
const response = await prompts({
type: 'confirm',
name: 'value',
message: 'Directory not empty. Continue?',
initial: false
});
if (!response.value) {
process.exit(1);
}
}
}
const options = /** @type {import('./types/internal').Options} */ (
await prompts(
[
{
type: 'select',
name: 'template',
message: 'Which Svelte app template?',
choices: fs.readdirSync(dist('templates')).map((dir) => {
const meta_file = dist(`templates/${dir}/meta.json`);
const meta = JSON.parse(fs.readFileSync(meta_file, 'utf8'));
return {
title: meta.description,
value: dir
};
})
},
{
type: 'toggle',
name: 'typescript',
message: 'Use TypeScript?',
initial: false,
active: 'Yes',
inactive: 'No'
},
{
type: 'toggle',
name: 'eslint',
message: 'Add ESLint for code linting?',
initial: false,
active: 'Yes',
inactive: 'No'
},
{
type: 'toggle',
name: 'prettier',
message: 'Add Prettier for code formatting?',
initial: false,
active: 'Yes',
inactive: 'No'
},
{
type: 'toggle',
name: 'playwright',
message: 'Add Playwright for browser testing?',
initial: false,
active: 'Yes',
inactive: 'No'
}
],
{
onCancel: () => {
process.exit(1);
}
}
)
);
options.name = path.basename(path.resolve(cwd));
await create(cwd, options);
console.log(bold(green('\nYour project is ready!')));
if (options.typescript) {
console.log(bold('✔ Typescript'));
console.log(' Inside Svelte components, use <script lang="ts">');
}
if (options.eslint) {
console.log(bold('✔ ESLint'));
console.log(cyan(' https://github.com/sveltejs/eslint-plugin-svelte3'));
}
if (options.prettier) {
console.log(bold('✔ Prettier'));
console.log(cyan(' https://prettier.io/docs/en/options.html'));
console.log(cyan(' https://github.com/sveltejs/prettier-plugin-svelte#options'));
}
if (options.playwright) {
console.log(bold('✔ Playwright'));
console.log(cyan(' https://playwright.dev'));
}
console.log('\nInstall community-maintained integrations:');
console.log(cyan(' https://github.com/svelte-add/svelte-adders'));
console.log('\nNext steps:');
let i = 1;
const relative = path.relative(process.cwd(), cwd);
if (relative !== '') {
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
}
console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, etc)`);
// prettier-ignore
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional)`);
console.log(` ${i++}: ${bold(cyan('npm run dev -- --open'))}`);
console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
console.log(`\nStuck? Visit us at ${cyan('https://svelte.dev/chat')}\n`);
}
main();