create-svelte
Advanced tools
Comparing version 3.0.4 to 3.1.0
291
bin.js
#!/usr/bin/env node | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { bold, cyan, gray, green, yellow } from 'kleur/colors'; | ||
import prompts from 'prompts'; | ||
import * as p from '@clack/prompts'; | ||
import { bold, cyan, grey, yellow } from 'kleur/colors'; | ||
import { create } from './index.js'; | ||
import { dist } from './utils.js'; | ||
// prettier-ignore | ||
const disclaimer = ` | ||
${bold(cyan('Welcome to SvelteKit!'))} | ||
`; | ||
const { version } = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8')); | ||
let cwd = process.argv[2] || '.'; | ||
async function main() { | ||
console.log(gray(`\ncreate-svelte version ${version}`)); | ||
console.log(disclaimer); | ||
console.log(` | ||
${grey(`create-svelte version ${version}`)} | ||
`); | ||
let cwd = process.argv[2] || '.'; | ||
p.intro('Welcome to SvelteKit!'); | ||
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 (cwd === '.') { | ||
const dir = await p.text({ | ||
message: 'Where should we create your project?', | ||
placeholder: ' (hit Enter to use current directory)' | ||
}); | ||
if (opts.dir) { | ||
cwd = opts.dir; | ||
} | ||
if (p.isCancel(dir)) process.exit(1); | ||
if (dir) { | ||
cwd = /** @type {string} */ (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 (fs.existsSync(cwd)) { | ||
if (fs.readdirSync(cwd).length > 0) { | ||
const force = await p.confirm({ | ||
message: 'Directory not empty. Continue?', | ||
initialValue: false | ||
}); | ||
if (!response.value) { | ||
process.exit(1); | ||
} | ||
// bail if `force` is `false` or the user cancelled with Ctrl-C | ||
if (force !== true) { | ||
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 { title, description } = JSON.parse(fs.readFileSync(meta_file, 'utf8')); | ||
const options = await p.group( | ||
{ | ||
template: () => | ||
p.select({ | ||
message: 'Which Svelte app template?', | ||
options: fs.readdirSync(dist('templates')).map((dir) => { | ||
const meta_file = dist(`templates/${dir}/meta.json`); | ||
const { title, description } = JSON.parse(fs.readFileSync(meta_file, 'utf8')); | ||
return { | ||
title, | ||
description, | ||
value: dir | ||
}; | ||
}) | ||
}, | ||
{ | ||
type: 'select', | ||
name: 'types', | ||
message: 'Add type checking with TypeScript?', | ||
initial: false, | ||
choices: [ | ||
{ | ||
title: 'Yes, using JavaScript with JSDoc comments', | ||
value: 'checkjs' | ||
}, | ||
{ | ||
title: 'Yes, using TypeScript syntax', | ||
value: 'typescript' | ||
}, | ||
{ title: 'No', value: null } | ||
] | ||
}, | ||
{ | ||
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' | ||
}, | ||
{ | ||
type: 'toggle', | ||
name: 'vitest', | ||
message: 'Add Vitest for unit testing?', | ||
initial: false, | ||
active: 'Yes', | ||
inactive: 'No' | ||
} | ||
], | ||
{ | ||
onCancel: () => { | ||
process.exit(1); | ||
} | ||
} | ||
) | ||
); | ||
return { | ||
label: title, | ||
hint: description, | ||
value: dir | ||
}; | ||
}) | ||
}), | ||
options.name = path.basename(path.resolve(cwd)); | ||
types: () => | ||
p.select({ | ||
message: 'Add type checking with TypeScript?', | ||
options: [ | ||
{ | ||
label: 'Yes, using JavaScript with JSDoc comments', | ||
value: 'checkjs' | ||
}, | ||
{ | ||
label: 'Yes, using TypeScript syntax', | ||
value: 'typescript' | ||
}, | ||
{ label: 'No', value: null } | ||
] | ||
}), | ||
await create(cwd, options); | ||
features: () => | ||
p.multiselect({ | ||
message: 'Select additional options', | ||
required: false, | ||
options: [ | ||
{ | ||
value: 'eslint', | ||
label: 'Add ESLint for code linting' | ||
}, | ||
{ | ||
value: 'prettier', | ||
label: 'Add Prettier for code formatting' | ||
}, | ||
{ | ||
value: 'playwright', | ||
label: 'Add Playwright for browser testing' | ||
}, | ||
{ | ||
value: 'vitest', | ||
label: 'Add Vitest for unit testing' | ||
} | ||
] | ||
}) | ||
}, | ||
{ onCancel: () => process.exit(1) } | ||
); | ||
console.log(bold(green('\nYour project is ready!'))); | ||
await create(cwd, { | ||
name: path.basename(path.resolve(cwd)), | ||
template: /** @type {'default' | 'skeleton' | 'skeletonlib'} */ (options.template), | ||
types: options.types, | ||
prettier: options.features.includes('prettier'), | ||
eslint: options.features.includes('eslint'), | ||
playwright: options.features.includes('playwright'), | ||
vitest: options.features.includes('vitest') | ||
}); | ||
if (options.types === 'typescript') { | ||
console.log(bold('✔ Typescript')); | ||
console.log(' Inside Svelte components, use <script lang="ts">'); | ||
} else if (options.types === 'checkjs') { | ||
console.log(bold('✔ Type-checked JavaScript')); | ||
console.log(' https://www.typescriptlang.org/tsconfig#checkJs'); | ||
} else if (options.template === 'skeletonlib') { | ||
const warning = yellow('▲'); | ||
console.log( | ||
`${warning} You chose to not add type checking, but TypeScript will still be installed in order to generate type definitions when building the library` | ||
); | ||
} | ||
p.outro(`Your project is ready!`); | ||
if (options.eslint) { | ||
console.log(bold('✔ ESLint')); | ||
console.log(cyan(' https://github.com/sveltejs/eslint-plugin-svelte3')); | ||
} | ||
if (options.types === 'typescript') { | ||
console.log(bold('✔ Typescript')); | ||
console.log(' Inside Svelte components, use <script lang="ts">\n'); | ||
} else if (options.types === 'checkjs') { | ||
console.log(bold('✔ Type-checked JavaScript')); | ||
console.log(cyan(' https://www.typescriptlang.org/tsconfig#checkJs\n')); | ||
} else if (options.template === 'skeletonlib') { | ||
const warning = yellow('▲'); | ||
console.log( | ||
`${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` | ||
); | ||
} | ||
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.features.includes('eslint')) { | ||
console.log(bold('✔ ESLint')); | ||
console.log(cyan(' https://github.com/sveltejs/eslint-plugin-svelte3\n')); | ||
} | ||
if (options.playwright) { | ||
console.log(bold('✔ Playwright')); | ||
console.log(cyan(' https://playwright.dev')); | ||
} | ||
if (options.features.includes('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\n')); | ||
} | ||
if (options.vitest) { | ||
console.log(bold('✔ Vitest')); | ||
console.log(cyan(' https://vitest.dev')); | ||
} | ||
if (options.features.includes('playwright')) { | ||
console.log(bold('✔ Playwright')); | ||
console.log(cyan(' https://playwright.dev\n')); | ||
} | ||
console.log('\nInstall community-maintained integrations:'); | ||
console.log(cyan(' https://github.com/svelte-add/svelte-add')); | ||
if (options.features.includes('vitest')) { | ||
console.log(bold('✔ Vitest')); | ||
console.log(cyan(' https://vitest.dev\n')); | ||
} | ||
console.log('\nNext steps:'); | ||
let i = 1; | ||
console.log('Install community-maintained integrations:'); | ||
console.log(cyan(' https://github.com/svelte-add/svelte-add')); | ||
const relative = path.relative(process.cwd(), cwd); | ||
if (relative !== '') { | ||
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`); | ||
} | ||
console.log('\nNext steps:'); | ||
let i = 1; | ||
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')}`); | ||
const relative = path.relative(process.cwd(), cwd); | ||
if (relative !== '') { | ||
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`); | ||
} | ||
main(); | ||
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')}`); |
{ | ||
"name": "create-svelte", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"repository": { | ||
@@ -14,4 +14,4 @@ "type": "git", | ||
"dependencies": { | ||
"kleur": "^4.1.5", | ||
"prompts": "^2.4.2" | ||
"@clack/prompts": "^0.6.0", | ||
"kleur": "^4.1.5" | ||
}, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
1083820
3492
+ Added@clack/prompts@^0.6.0
+ Added@clack/core@0.3.5(transitive)
+ Added@clack/prompts@0.6.3(transitive)
+ Addedpicocolors@1.1.1(transitive)
- Removedprompts@^2.4.2
- Removedkleur@3.0.3(transitive)
- Removedprompts@2.4.2(transitive)