|
1 | 1 | #!/usr/bin/env node
|
2 |
| -import fs from 'node:fs'; |
3 |
| -import path from 'node:path'; |
4 |
| -import process from 'node:process'; |
5 |
| -import * as p from '@clack/prompts'; |
6 |
| -import { bold, cyan, grey, yellow } from 'kleur/colors'; |
7 |
| -import { create } from './index.js'; |
8 |
| -import { dist, package_manager } from './utils.js'; |
9 | 2 |
|
10 |
| -const { version } = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8')); |
11 |
| -let cwd = process.argv[2] || '.'; |
12 |
| - |
13 |
| -console.log(` |
14 |
| -${grey(`create-svelte version ${version}`)} |
15 |
| -`); |
16 |
| - |
17 |
| -p.intro('Welcome to SvelteKit!'); |
18 |
| - |
19 |
| -if (cwd === '.') { |
20 |
| - const dir = await p.text({ |
21 |
| - message: 'Where should we create your project?', |
22 |
| - placeholder: ' (hit Enter to use current directory)' |
23 |
| - }); |
24 |
| - |
25 |
| - if (p.isCancel(dir)) process.exit(1); |
26 |
| - |
27 |
| - if (dir) { |
28 |
| - cwd = /** @type {string} */ (dir); |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| -if (fs.existsSync(cwd)) { |
33 |
| - if (fs.readdirSync(cwd).length > 0) { |
34 |
| - const force = await p.confirm({ |
35 |
| - message: 'Directory not empty. Continue?', |
36 |
| - initialValue: false |
37 |
| - }); |
38 |
| - |
39 |
| - // bail if `force` is `false` or the user cancelled with Ctrl-C |
40 |
| - if (force !== true) { |
41 |
| - process.exit(1); |
42 |
| - } |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| -const options = await p.group( |
47 |
| - { |
48 |
| - template: (_) => |
49 |
| - p.select({ |
50 |
| - message: 'Which Svelte app template?', |
51 |
| - options: fs.readdirSync(dist('templates')).map((dir) => { |
52 |
| - const meta_file = dist(`templates/${dir}/meta.json`); |
53 |
| - const { title, description } = JSON.parse(fs.readFileSync(meta_file, 'utf8')); |
54 |
| - |
55 |
| - return { |
56 |
| - label: title, |
57 |
| - hint: description, |
58 |
| - value: dir |
59 |
| - }; |
60 |
| - }) |
61 |
| - }), |
62 |
| - |
63 |
| - types: ({ results }) => |
64 |
| - p.select({ |
65 |
| - message: 'Add type checking with TypeScript?', |
66 |
| - initialValue: /** @type {'checkjs' | 'typescript' | null} */ ( |
67 |
| - results.template === 'skeletonlib' ? 'checkjs' : 'typescript' |
68 |
| - ), |
69 |
| - options: [ |
70 |
| - { |
71 |
| - label: 'Yes, using TypeScript syntax', |
72 |
| - value: 'typescript' |
73 |
| - }, |
74 |
| - { |
75 |
| - label: 'Yes, using JavaScript with JSDoc comments', |
76 |
| - value: 'checkjs' |
77 |
| - }, |
78 |
| - { label: 'No', value: null } |
79 |
| - ] |
80 |
| - }), |
81 |
| - |
82 |
| - features: () => |
83 |
| - p.multiselect({ |
84 |
| - message: 'Select additional options (use arrow keys/space bar)', |
85 |
| - required: false, |
86 |
| - options: [ |
87 |
| - { |
88 |
| - value: 'eslint', |
89 |
| - label: 'Add ESLint for code linting' |
90 |
| - }, |
91 |
| - { |
92 |
| - value: 'prettier', |
93 |
| - label: 'Add Prettier for code formatting' |
94 |
| - }, |
95 |
| - { |
96 |
| - value: 'playwright', |
97 |
| - label: 'Add Playwright for browser testing' |
98 |
| - }, |
99 |
| - { |
100 |
| - value: 'vitest', |
101 |
| - label: 'Add Vitest for unit testing' |
102 |
| - }, |
103 |
| - { |
104 |
| - value: 'svelte5', |
105 |
| - label: 'Try the Svelte 5 preview (unstable!)' |
106 |
| - } |
107 |
| - ] |
108 |
| - }) |
109 |
| - }, |
110 |
| - { onCancel: () => process.exit(1) } |
111 |
| -); |
112 |
| - |
113 |
| -await create(cwd, { |
114 |
| - name: path.basename(path.resolve(cwd)), |
115 |
| - template: /** @type {'default' | 'skeleton' | 'skeletonlib'} */ (options.template), |
116 |
| - types: /** @type {'checkjs' | 'typescript' | null} */ (options.types), |
117 |
| - prettier: options.features.includes('prettier'), |
118 |
| - eslint: options.features.includes('eslint'), |
119 |
| - playwright: options.features.includes('playwright'), |
120 |
| - vitest: options.features.includes('vitest'), |
121 |
| - svelte5: options.features.includes('svelte5') |
122 |
| -}); |
123 |
| - |
124 |
| -p.outro('Your project is ready!'); |
125 |
| - |
126 |
| -if (!options.types && options.template === 'skeletonlib') { |
127 |
| - const warning = yellow('▲'); |
128 |
| - console.log( |
129 |
| - `${warning} You chose to not add type checking, but TypeScript will still be installed in order to generate type definitions when building the library\n` |
130 |
| - ); |
131 |
| -} |
132 |
| - |
133 |
| -console.log('Install more integrations with:'); |
134 |
| -console.log(bold(cyan(' npx svelte-add'))); |
135 |
| - |
136 |
| -console.log('\nNext steps:'); |
137 |
| -let i = 1; |
138 |
| - |
139 |
| -const relative = path.relative(process.cwd(), cwd); |
140 |
| -if (relative !== '') { |
141 |
| - console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`); |
142 |
| -} |
143 |
| - |
144 |
| -console.log(` ${i++}: ${bold(cyan(`${package_manager} install`))}`); |
145 |
| -// prettier-ignore |
146 |
| -console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional)`); |
147 |
| -console.log(` ${i++}: ${bold(cyan(`${package_manager} run dev -- --open`))}`); |
148 |
| - |
149 |
| -console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`); |
150 |
| -console.log(`\nStuck? Visit us at ${cyan('https://svelte.dev/chat')}`); |
| 3 | +console.warn("'npm create svelte' has been replaced with 'npx sv create'"); |
0 commit comments