Revert "Add headless support to create-astro (#5898)"
This reverts commit d8919b1a21
.
This commit is contained in:
parent
fb6604d0aa
commit
1a6400d6ab
2 changed files with 65 additions and 87 deletions
|
@ -43,8 +43,6 @@ May be provided in place of prompts
|
||||||
| `--template` | Specify the template name ([list][examples]) |
|
| `--template` | Specify the template name ([list][examples]) |
|
||||||
| `--commit` | Specify a specific Git commit or branch to use from this repo (by default, `main` branch of this repo will be used) |
|
| `--commit` | Specify a specific Git commit or branch to use from this repo (by default, `main` branch of this repo will be used) |
|
||||||
| `--fancy` | For Windows users, `--fancy` will enable full unicode support |
|
| `--fancy` | For Windows users, `--fancy` will enable full unicode support |
|
||||||
| `--typescript` | Specify the [tsconfig][typescript] to use |
|
|
||||||
| `--yes`/`-y` | Skip prompts and use default values |
|
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
|
@ -62,4 +60,3 @@ yarn create astro my-astro-project --verbose
|
||||||
```
|
```
|
||||||
|
|
||||||
[examples]: https://github.com/withastro/astro/tree/main/examples
|
[examples]: https://github.com/withastro/astro/tree/main/examples
|
||||||
[typescript]: https://github.com/withastro/astro/tree/main/packages/astro/tsconfigs
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import { TEMPLATES } from './templates.js';
|
||||||
// broke our arg parser, since `--` is a special kind of flag. Filtering for `--` here
|
// broke our arg parser, since `--` is a special kind of flag. Filtering for `--` here
|
||||||
// fixes the issue so that create-astro now works on all npm version.
|
// fixes the issue so that create-astro now works on all npm version.
|
||||||
const cleanArgv = process.argv.filter((arg) => arg !== '--');
|
const cleanArgv = process.argv.filter((arg) => arg !== '--');
|
||||||
const args = yargs(cleanArgv, { boolean: ['fancy', 'y'], alias: { y: 'yes' } });
|
const args = yargs(cleanArgv, { boolean: ['fancy'] });
|
||||||
// Always skip Houston on Windows (for now)
|
// Always skip Houston on Windows (for now)
|
||||||
if (platform() === 'win32') args.skipHouston = true;
|
if (platform() === 'win32') args.skipHouston = true;
|
||||||
prompts.override(args);
|
prompts.override(args);
|
||||||
|
@ -226,34 +226,30 @@ export async function main() {
|
||||||
templateSpinner.text = green('Template copied!');
|
templateSpinner.text = green('Template copied!');
|
||||||
templateSpinner.succeed();
|
templateSpinner.succeed();
|
||||||
|
|
||||||
const install = args.y
|
const installResponse = await prompts(
|
||||||
? true
|
{
|
||||||
: (
|
type: 'confirm',
|
||||||
await prompts(
|
name: 'install',
|
||||||
{
|
message: `Would you like to install ${pkgManager} dependencies? ${reset(
|
||||||
type: 'confirm',
|
dim('(recommended)')
|
||||||
name: 'install',
|
)}`,
|
||||||
message: `Would you like to install ${pkgManager} dependencies? ${reset(
|
initial: true,
|
||||||
dim('(recommended)')
|
},
|
||||||
)}`,
|
{
|
||||||
initial: true,
|
onCancel: () => {
|
||||||
},
|
ora().info(
|
||||||
{
|
dim(
|
||||||
onCancel: () => {
|
'Operation cancelled. Your project folder has already been created, however no dependencies have been installed'
|
||||||
ora().info(
|
)
|
||||||
dim(
|
);
|
||||||
'Operation cancelled. Your project folder has already been created, however no dependencies have been installed'
|
process.exit(1);
|
||||||
)
|
},
|
||||||
);
|
}
|
||||||
process.exit(1);
|
);
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).install;
|
|
||||||
|
|
||||||
if (args.dryRun) {
|
if (args.dryRun) {
|
||||||
ora().info(dim(`--dry-run enabled, skipping.`));
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
||||||
} else if (install) {
|
} else if (installResponse.install) {
|
||||||
const installExec = execa(pkgManager, ['install'], { cwd });
|
const installExec = execa(pkgManager, ['install'], { cwd });
|
||||||
const installingPackagesMsg = `Installing packages${emojiWithFallback(' 📦', '...')}`;
|
const installingPackagesMsg = `Installing packages${emojiWithFallback(' 📦', '...')}`;
|
||||||
const installSpinner = await loadWithRocketGradient(installingPackagesMsg);
|
const installSpinner = await loadWithRocketGradient(installingPackagesMsg);
|
||||||
|
@ -272,32 +268,26 @@ export async function main() {
|
||||||
await info('No problem!', 'Remember to install dependencies after setup.');
|
await info('No problem!', 'Remember to install dependencies after setup.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitResponse = args.y
|
const gitResponse = await prompts(
|
||||||
? true
|
{
|
||||||
: (
|
type: 'confirm',
|
||||||
await prompts(
|
name: 'git',
|
||||||
{
|
message: `Would you like to initialize a new git repository? ${reset(dim('(optional)'))}`,
|
||||||
type: 'confirm',
|
initial: true,
|
||||||
name: 'git',
|
},
|
||||||
message: `Would you like to initialize a new git repository? ${reset(
|
{
|
||||||
dim('(optional)')
|
onCancel: () => {
|
||||||
)}`,
|
ora().info(
|
||||||
initial: true,
|
dim('Operation cancelled. No worries, your project folder has already been created')
|
||||||
},
|
);
|
||||||
{
|
process.exit(1);
|
||||||
onCancel: () => {
|
},
|
||||||
ora().info(
|
}
|
||||||
dim('Operation cancelled. No worries, your project folder has already been created')
|
);
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).git;
|
|
||||||
|
|
||||||
if (args.dryRun) {
|
if (args.dryRun) {
|
||||||
ora().info(dim(`--dry-run enabled, skipping.`));
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
||||||
} else if (gitResponse) {
|
} else if (gitResponse.git) {
|
||||||
await execaCommand('git init', { cwd });
|
await execaCommand('git init', { cwd });
|
||||||
ora().succeed('Git repository created!');
|
ora().succeed('Git repository created!');
|
||||||
} else {
|
} else {
|
||||||
|
@ -307,53 +297,44 @@ export async function main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.y && !args.typescript) {
|
const tsResponse = await prompts(
|
||||||
ora().warn(dim('--typescript <choice> missing. Defaulting to "strict"'));
|
{
|
||||||
args.typescript = 'strict';
|
type: 'select',
|
||||||
}
|
name: 'typescript',
|
||||||
|
message: 'How would you like to setup TypeScript?',
|
||||||
|
choices: [
|
||||||
|
{ value: 'strict', title: 'Strict', description: '(recommended)' },
|
||||||
|
{ value: 'strictest', title: 'Strictest' },
|
||||||
|
{ value: 'base', title: 'Relaxed' },
|
||||||
|
{ value: 'unsure', title: 'Help me choose' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onCancel: () => {
|
||||||
|
ora().info(
|
||||||
|
dim(
|
||||||
|
'Operation cancelled. Your project folder has been created but no TypeScript configuration file was created.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const tsResponse =
|
if (tsResponse.typescript === 'unsure') {
|
||||||
args.typescript ||
|
|
||||||
(
|
|
||||||
await prompts(
|
|
||||||
{
|
|
||||||
type: 'select',
|
|
||||||
name: 'typescript',
|
|
||||||
message: 'How would you like to setup TypeScript?',
|
|
||||||
choices: [
|
|
||||||
{ value: 'strict', title: 'Strict', description: '(recommended)' },
|
|
||||||
{ value: 'strictest', title: 'Strictest' },
|
|
||||||
{ value: 'base', title: 'Relaxed' },
|
|
||||||
{ value: 'unsure', title: 'Help me choose' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onCancel: () => {
|
|
||||||
ora().info(
|
|
||||||
dim(
|
|
||||||
'Operation cancelled. Your project folder has been created but no TypeScript configuration file was created.'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).typescript;
|
|
||||||
|
|
||||||
if (tsResponse === 'unsure') {
|
|
||||||
await typescriptByDefault();
|
await typescriptByDefault();
|
||||||
tsResponse.typescript = 'base';
|
tsResponse.typescript = 'base';
|
||||||
}
|
}
|
||||||
if (args.dryRun) {
|
if (args.dryRun) {
|
||||||
ora().info(dim(`--dry-run enabled, skipping.`));
|
ora().info(dim(`--dry-run enabled, skipping.`));
|
||||||
} else if (tsResponse) {
|
} else if (tsResponse.typescript) {
|
||||||
const templateTSConfigPath = path.join(cwd, 'tsconfig.json');
|
const templateTSConfigPath = path.join(cwd, 'tsconfig.json');
|
||||||
fs.readFile(templateTSConfigPath, (err, data) => {
|
fs.readFile(templateTSConfigPath, (err, data) => {
|
||||||
if (err && err.code === 'ENOENT') {
|
if (err && err.code === 'ENOENT') {
|
||||||
// If the template doesn't have a tsconfig.json, let's add one instead
|
// If the template doesn't have a tsconfig.json, let's add one instead
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
templateTSConfigPath,
|
templateTSConfigPath,
|
||||||
stringify({ extends: `astro/tsconfigs/${tsResponse}` }, null, 2)
|
stringify({ extends: `astro/tsconfigs/${tsResponse.typescript}` }, null, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue