-
Notifications
You must be signed in to change notification settings - Fork 4.9k
taro-cli新增支持可动态扩展ask导航步骤 #17715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
taro-cli新增支持可动态扩展ask导航步骤 #17715
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ export interface IProjectConf { | |||||||||||||||||||||||||||||||||
| hideDefaultTemplate?: boolean | ||||||||||||||||||||||||||||||||||
| framework: FrameworkType | ||||||||||||||||||||||||||||||||||
| compiler?: CompilerType | ||||||||||||||||||||||||||||||||||
| ask?: (config: {}) => Promise<void> | void | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| type CustomPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||||||||||||||||||||||||||||||||||
|
|
@@ -126,6 +127,14 @@ export default class Project extends Creator { | |||||||||||||||||||||||||||||||||
| await this.askTemplate(conf, prompts, templates) | ||||||||||||||||||||||||||||||||||
| const templateChoiceAnswer = await inquirer.prompt<IProjectConf>(prompts) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 导航步骤扩展 | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| if (typeof conf.ask === 'function') { | ||||||||||||||||||||||||||||||||||
| const { ask, ...other } = conf | ||||||||||||||||||||||||||||||||||
| await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) }) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } catch (e) { } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 改进错误处理并修复未使用变量的问题 当前实现存在以下问题:
// 导航步骤扩展
try {
if (typeof conf.ask === 'function') {
- const { ask, ...other } = conf
- await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
+ const { ask: _, ...other } = conf
+ await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
}
-} catch (e) { }
+} catch (e) {
+ console.log(chalk.yellow('执行导航步骤扩展时发生错误: '), e)
+}改进说明:
📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 133-133: 'ask' is assigned a value but never used. (@typescript-eslint/no-unused-vars) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||
| ...answers, | ||||||||||||||||||||||||||||||||||
| ...compilerAndTemplateSourceAnswer, | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
改进类型定义以提供更好的类型安全性
当前使用
{}作为类型定义存在问题,{}实际上表示"任何非空值"而不是空对象。根据之前的讨论,这个ask函数需要接收配置参数,建议使用更具体的类型定义。这样可以:
{}类型📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 46-46: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
🪛 ESLint
[error] 46-46: Don't use
{}as a type.{}actually means "any non-nullish value".objectinstead.unknowninstead.Record<string, never>instead.NonNullable<unknown>instead.(@typescript-eslint/ban-types)
🤖 Prompt for AI Agents