refactor: reduce number of leaked anys (#7465)

This commit is contained in:
Joshua Chen 2022-05-23 00:30:32 +08:00 committed by GitHub
parent 6e62bba30f
commit 89b0fff128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 121 additions and 89 deletions

View file

@ -65,7 +65,7 @@ async function askForPackageManagerChoice(): Promise<PackageManager> {
.map((p) => ({title: p, value: p}));
return (
await prompts(
(await prompts(
{
type: 'select',
name: 'packageManager',
@ -77,7 +77,7 @@ async function askForPackageManagerChoice(): Promise<PackageManager> {
logger.info`Falling back to name=${defaultPackageManager}`;
},
},
)
)) as {packageManager: PackageManager}
).packageManager;
}
@ -203,7 +203,7 @@ async function getGitCommand(gitStrategy: GitStrategy): Promise<string> {
case 'copy':
return 'git clone --recursive --depth 1';
case 'custom': {
const {command} = await prompts(
const {command} = (await prompts(
{
type: 'text',
name: 'command',
@ -215,7 +215,7 @@ async function getGitCommand(gitStrategy: GitStrategy): Promise<string> {
logger.info`Falling back to code=${'git clone'}`;
},
},
);
)) as {command: string};
return command ?? 'git clone';
}
case 'deep':
@ -245,7 +245,7 @@ async function getSiteName(
}
return reqName;
}
const {siteName} = await prompts(
const {siteName} = (await prompts(
{
type: 'text',
name: 'siteName',
@ -259,7 +259,7 @@ async function getSiteName(
process.exit(1);
},
},
);
)) as {siteName: string};
return siteName;
}
@ -324,7 +324,7 @@ async function getSource(
const template = cliOptions.gitStrategy
? 'Git repository'
: (
await prompts(
(await prompts(
{
type: 'select',
name: 'template',
@ -337,10 +337,10 @@ async function getSource(
process.exit(1);
},
},
)
)) as {template: Template | 'Git repository' | 'Local template'}
).template;
if (template === 'Git repository') {
const {gitRepoUrl} = await prompts(
const {gitRepoUrl} = (await prompts(
{
type: 'text',
name: 'gitRepoUrl',
@ -359,7 +359,7 @@ async function getSource(
process.exit(1);
},
},
);
)) as {gitRepoUrl: string};
let strategy = cliOptions.gitStrategy;
if (!strategy) {
({strategy} = await prompts(
@ -393,7 +393,7 @@ async function getSource(
strategy: strategy ?? 'deep',
};
} else if (template === 'Local template') {
const {templateDir} = await prompts(
const {templateDir} = (await prompts(
{
type: 'text',
name: 'templateDir',
@ -418,7 +418,7 @@ async function getSource(
process.exit(1);
},
},
);
)) as {templateDir: string};
return {
type: 'local',
path: templateDir,
@ -442,7 +442,7 @@ async function getSource(
}
async function updatePkg(pkgPath: string, obj: {[key: string]: unknown}) {
const pkg = await fs.readJSON(pkgPath);
const pkg = (await fs.readJSON(pkgPath)) as {[key: string]: unknown};
const newPkg = Object.assign(pkg, obj);
await fs.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);