Skip to content

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

Merged
merged 6 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/taro-cli/src/create/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface IProjectConf {
hideDefaultTemplate?: boolean
framework: FrameworkType
compiler?: CompilerType
ask?: (config: object) => Promise<void> | void
}

type CustomPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
Expand Down Expand Up @@ -126,6 +127,16 @@ 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 ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
}
} catch (e) {
console.error(e)
}

return {
...answers,
...compilerAndTemplateSourceAnswer,
Expand Down
4 changes: 3 additions & 1 deletion packages/taro-cli/src/presets/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default (ctx: IPluginContext) => {
hideDefaultTemplate,
sourceRoot,
autoInstall,
ask
} = opts.options

const Project = require('../../create/project').default
Expand All @@ -52,7 +53,8 @@ export default (ctx: IPluginContext) => {
compiler,
hideDefaultTemplate,
autoInstall,
css
css,
ask
})

project.create()
Expand Down