diff options
author | 2021-06-08 15:12:07 +0000 | |
---|---|---|
committer | 2021-06-08 15:12:07 +0000 | |
commit | a7594cfcdf7f12b1eba9b060e749b6d5690da167 (patch) | |
tree | 4ec64204300e32094e837e88418f68d7266fc87f /packages/create-astro/src | |
parent | 6bca7c83a7e2d62015f45f873b0f69f11b4d902b (diff) | |
download | astro-a7594cfcdf7f12b1eba9b060e749b6d5690da167.tar.gz astro-a7594cfcdf7f12b1eba9b060e749b6d5690da167.tar.zst astro-a7594cfcdf7f12b1eba9b060e749b6d5690da167.zip |
[ci] yarn format
Diffstat (limited to 'packages/create-astro/src')
-rw-r--r-- | packages/create-astro/src/index.ts | 125 | ||||
-rw-r--r-- | packages/create-astro/src/templates.ts | 35 |
2 files changed, 81 insertions, 79 deletions
diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 5bf16e490..c42a1942c 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -9,79 +9,78 @@ const args = yargs(process.argv); prompts.override(args); export function mkdirp(dir: string) { - try { - fs.mkdirSync(dir, { recursive: true }); - } catch (e) { - if (e.code === 'EEXIST') return; - throw e; - } + try { + fs.mkdirSync(dir, { recursive: true }); + } catch (e) { + if (e.code === 'EEXIST') return; + throw e; + } } - const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); export async function main() { - console.log('\n' + bold('Welcome to Astro!') + gray(` (create-astro v${version})`)); - console.log(`If you encounter a problem, visit ${cyan('https://github.com/snowpack/astro/issues')} to search or file a new issue.\n`); - - console.log(green(`>`) + gray(` Prepare for liftoff.`)); - console.log(green(`>`) + gray(` Gathering mission details...`)); + console.log('\n' + bold('Welcome to Astro!') + gray(` (create-astro v${version})`)); + console.log(`If you encounter a problem, visit ${cyan('https://github.com/snowpack/astro/issues')} to search or file a new issue.\n`); + + console.log(green(`>`) + gray(` Prepare for liftoff.`)); + console.log(green(`>`) + gray(` Gathering mission details...`)); - const cwd = args['_'][2] || '.'; - if (fs.existsSync(cwd)) { - if (fs.readdirSync(cwd).length > 0) { - const response = await prompts({ - type: 'confirm', - name: 'forceOverwrite', - message: 'Directory not empty. Continue?', - initial: false - }); - if (!response.forceOverwrite) { - process.exit(1); - } - } - } else { - mkdirp(cwd); - } + const cwd = args['_'][2] || '.'; + if (fs.existsSync(cwd)) { + if (fs.readdirSync(cwd).length > 0) { + const response = await prompts({ + type: 'confirm', + name: 'forceOverwrite', + message: 'Directory not empty. Continue?', + initial: false, + }); + if (!response.forceOverwrite) { + process.exit(1); + } + } + } else { + mkdirp(cwd); + } - const options = /** @type {import('./types/internal').Options} */ (await prompts([ - { - type: 'select', - name: 'template', - message: 'Which app template would you like to use?', - choices: TEMPLATES - }, - ])); + const options = /** @type {import('./types/internal').Options} */ await prompts([ + { + type: 'select', + name: 'template', + message: 'Which app template would you like to use?', + choices: TEMPLATES, + }, + ]); - const emitter = degit(`snowpackjs/astro/examples/${options.template}`, { - cache: false, - force: true, - verbose: false, - }); - - try { - // emitter.on('info', info => { console.log(info.message) }); - await emitter.clone(cwd); - } catch (err) { - // degit is compiled, so the stacktrace is pretty noisy. Just report the message. - console.error(red(err.message)); - process.exit(1); - } + const emitter = degit(`snowpackjs/astro/examples/${options.template}`, { + cache: false, + force: true, + verbose: false, + }); - console.log(bold(green('✔ Copied project files'))); + try { + // emitter.on('info', info => { console.log(info.message) }); + await emitter.clone(cwd); + } catch (err) { + // degit is compiled, so the stacktrace is pretty noisy. Just report the message. + console.error(red(err.message)); + process.exit(1); + } - console.log('\nNext steps:'); - let i = 1; + console.log(bold(green('✔ Copied project files'))); - 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, yarn, etc)`); - console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`); - console.log(` ${i++}: ${bold(cyan('npm start'))} (or pnpm, yarn, etc)`); + const relative = path.relative(process.cwd(), cwd); + if (relative !== '') { + console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`); + } - console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`); - console.log('\nStuck? Visit us at https://astro.build/chat\n'); -}
\ No newline at end of file + console.log(` ${i++}: ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`); + console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`); + console.log(` ${i++}: ${bold(cyan('npm start'))} (or pnpm, yarn, etc)`); + + console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`); + console.log('\nStuck? Visit us at https://astro.build/chat\n'); +} diff --git a/packages/create-astro/src/templates.ts b/packages/create-astro/src/templates.ts index 63254a311..dce085314 100644 --- a/packages/create-astro/src/templates.ts +++ b/packages/create-astro/src/templates.ts @@ -1,16 +1,19 @@ -export const TEMPLATES = [, - { - title: 'Starter Kit (Generic)', - value: 'starter' - }, { - title: 'Blog', - value: 'blog' - }, - { - title: 'Documentation', - value: 'docs' - }, - { - title: 'Portfolio', - value: 'portfolio' - }];
\ No newline at end of file +export const TEMPLATES = [ + , + { + title: 'Starter Kit (Generic)', + value: 'starter', + }, + { + title: 'Blog', + value: 'blog', + }, + { + title: 'Documentation', + value: 'docs', + }, + { + title: 'Portfolio', + value: 'portfolio', + }, +]; |