-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/vercel-analytics
- Loading branch information
Showing
44 changed files
with
1,382 additions
and
1,348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Moved pagination error to AstroErrorData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-astro': major | ||
--- | ||
|
||
Redesigned `create-astro` experience |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule grubby-group
added at
9a401d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { prompt } from '@astrojs/cli-kit'; | ||
import arg from 'arg'; | ||
import os from 'node:os'; | ||
import detectPackageManager from 'which-pm-runs'; | ||
|
||
import { getName, getVersion } from '../messages.js'; | ||
|
||
export interface Context { | ||
help: boolean; | ||
prompt: typeof prompt; | ||
cwd: string; | ||
pkgManager: string; | ||
username: string; | ||
version: string; | ||
skipHouston: boolean; | ||
dryRun?: boolean; | ||
yes?: boolean; | ||
projectName?: string; | ||
template?: string; | ||
ref: string; | ||
install?: boolean; | ||
git?: boolean; | ||
typescript?: string; | ||
stdin?: typeof process.stdin; | ||
stdout?: typeof process.stdout; | ||
exit(code: number): never; | ||
} | ||
|
||
export async function getContext(argv: string[]): Promise<Context> { | ||
const flags = arg( | ||
{ | ||
'--template': String, | ||
'--ref': String, | ||
'--yes': Boolean, | ||
'--no': Boolean, | ||
'--install': Boolean, | ||
'--no-install': Boolean, | ||
'--git': Boolean, | ||
'--no-git': Boolean, | ||
'--typescript': String, | ||
'--skip-houston': Boolean, | ||
'--dry-run': Boolean, | ||
'--help': Boolean, | ||
'--fancy': Boolean, | ||
|
||
'-y': '--yes', | ||
'-n': '--no', | ||
'-h': '--help', | ||
}, | ||
{ argv, permissive: true } | ||
); | ||
|
||
const pkgManager = detectPackageManager()?.name ?? 'npm'; | ||
const [username, version] = await Promise.all([getName(), getVersion()]); | ||
let cwd = flags['_'][0] as string; | ||
let { | ||
'--help': help = false, | ||
'--template': template, | ||
'--no': no, | ||
'--yes': yes, | ||
'--install': install, | ||
'--no-install': noInstall, | ||
'--git': git, | ||
'--no-git': noGit, | ||
'--typescript': typescript, | ||
'--fancy': fancy, | ||
'--skip-houston': skipHouston, | ||
'--dry-run': dryRun, | ||
'--ref': ref, | ||
} = flags; | ||
let projectName = cwd; | ||
|
||
if (no) { | ||
yes = false; | ||
if (install == undefined) install = false; | ||
if (git == undefined) git = false; | ||
if (typescript == undefined) typescript = 'strict'; | ||
} | ||
|
||
skipHouston = | ||
((os.platform() === 'win32' && !fancy) || skipHouston) ?? | ||
[yes, no, install, git, typescript].some((v) => v !== undefined); | ||
|
||
const context: Context = { | ||
help, | ||
prompt, | ||
pkgManager, | ||
username, | ||
version, | ||
skipHouston, | ||
dryRun, | ||
projectName, | ||
template, | ||
ref: ref ?? 'latest', | ||
yes, | ||
install: install ?? (noInstall ? false : undefined), | ||
git: git ?? (noGit ? false : undefined), | ||
typescript, | ||
cwd, | ||
exit(code) { | ||
process.exit(code); | ||
}, | ||
}; | ||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Context } from './context'; | ||
|
||
import { execa } from 'execa'; | ||
import { info, spinner, title } from '../messages.js'; | ||
|
||
export async function dependencies( | ||
ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'pkgManager' | 'cwd' | 'dryRun'> | ||
) { | ||
let deps = ctx.install ?? ctx.yes; | ||
if (deps === undefined) { | ||
({ deps } = await ctx.prompt({ | ||
name: 'deps', | ||
type: 'confirm', | ||
label: title('deps'), | ||
message: `Install dependencies?`, | ||
hint: 'recommended', | ||
initial: true, | ||
})); | ||
ctx.install = deps; | ||
} | ||
|
||
if (ctx.dryRun) { | ||
await info('--dry-run', `Skipping dependency installation`); | ||
} else if (deps) { | ||
await spinner({ | ||
start: `Dependencies installing with ${ctx.pkgManager}...`, | ||
end: 'Dependencies installed', | ||
while: () => install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }), | ||
}); | ||
} else { | ||
await info( | ||
ctx.yes === false ? 'deps [skip]' : 'No problem!', | ||
'Remember to install dependencies after setup.' | ||
); | ||
} | ||
} | ||
|
||
async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) { | ||
const installExec = execa(pkgManager, ['install'], { cwd }); | ||
return new Promise<void>((resolve, reject) => { | ||
installExec.on('error', (error) => reject(error)); | ||
installExec.on('close', () => resolve()); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import type { Context } from './context'; | ||
|
||
import { color } from '@astrojs/cli-kit'; | ||
import { execa } from 'execa'; | ||
import { info, spinner, title } from '../messages.js'; | ||
|
||
export async function git(ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' | 'dryRun'>) { | ||
if (fs.existsSync(path.join(ctx.cwd, '.git'))) { | ||
await info('Nice!', `Git has already been initialized`); | ||
return; | ||
} | ||
let _git = ctx.git ?? ctx.yes; | ||
if (_git === undefined) { | ||
({ git: _git } = await ctx.prompt({ | ||
name: 'git', | ||
type: 'confirm', | ||
label: title('git'), | ||
message: `Initialize a new git repository?`, | ||
hint: 'optional', | ||
initial: true, | ||
})); | ||
} | ||
|
||
if (ctx.dryRun) { | ||
await info('--dry-run', `Skipping Git initialization`); | ||
} else if (_git) { | ||
await spinner({ | ||
start: 'Git initializing...', | ||
end: 'Git initialized', | ||
while: () => init({ cwd: ctx.cwd }), | ||
}); | ||
} else { | ||
await info( | ||
ctx.yes === false ? 'git [skip]' : 'Sounds good!', | ||
`You can always run ${color.reset('git init')}${color.dim(' manually.')}` | ||
); | ||
} | ||
} | ||
|
||
async function init({ cwd }: { cwd: string }) { | ||
try { | ||
await execa('git', ['init'], { cwd, stdio: 'ignore' }); | ||
await execa('git', ['add', '-A'], { cwd, stdio: 'ignore' }); | ||
await execa( | ||
'git', | ||
[ | ||
'commit', | ||
'-m', | ||
'Initial commit from Astro', | ||
'--author="houston[bot] <astrobot-houston@users.noreply.github.com>"', | ||
], | ||
{ cwd, stdio: 'ignore' } | ||
); | ||
} catch (e) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { printHelp } from '../messages.js'; | ||
|
||
export function help() { | ||
printHelp({ | ||
commandName: 'create-astro', | ||
usage: '[dir] [...flags]', | ||
headline: 'Scaffold Astro projects.', | ||
tables: { | ||
Flags: [ | ||
['--template <name>', 'Specify your template.'], | ||
['--install / --no-install', 'Install dependencies (or not).'], | ||
['--git / --no-git', 'Initialize git repo (or not).'], | ||
['--yes (-y)', 'Skip all prompt by accepting defaults.'], | ||
['--no (-n)', 'Skip all prompt by declining defaults.'], | ||
['--dry-run', 'Walk through steps without executing.'], | ||
['--skip-houston', 'Skip Houston animation.'], | ||
], | ||
}, | ||
}); | ||
} |
Oops, something went wrong.