Skip to content

Commit 229ad63

Browse files
author
yangjijiang
committed
taro-cli新增支持可动态扩展ask导航步骤
1 parent edb74da commit 229ad63

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/taro-cli/src/create/project.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface IProjectConf {
4343
hideDefaultTemplate?: boolean
4444
framework: FrameworkType
4545
compiler?: CompilerType
46+
ask?: Function
4647
}
4748

4849
type CustomPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -126,6 +127,14 @@ export default class Project extends Creator {
126127
await this.askTemplate(conf, prompts, templates)
127128
const templateChoiceAnswer = await inquirer.prompt<IProjectConf>(prompts)
128129

130+
// 导航步骤扩展
131+
try {
132+
if (typeof conf.ask === 'function') {
133+
const { ask, ...other } = conf
134+
await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
135+
}
136+
} catch (e) { }
137+
129138
return {
130139
...answers,
131140
...compilerAndTemplateSourceAnswer,

packages/taro-cli/src/presets/commands/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default (ctx: IPluginContext) => {
1414
'--template [template]': '项目模板',
1515
'--css [css]': 'CSS预处理器(sass/less/stylus/none)',
1616
'--autoInstall': '自动安装依赖',
17+
'--ask [ask]': '扩展脚手架的导航步骤',
1718
'-h, --help': 'output usage information'
1819
},
1920
async fn (opts) {
@@ -34,6 +35,7 @@ export default (ctx: IPluginContext) => {
3435
hideDefaultTemplate,
3536
sourceRoot,
3637
autoInstall,
38+
ask
3739
} = opts.options
3840

3941
const Project = require('../../create/project').default
@@ -52,7 +54,8 @@ export default (ctx: IPluginContext) => {
5254
compiler,
5355
hideDefaultTemplate,
5456
autoInstall,
55-
css
57+
css,
58+
ask
5659
})
5760

5861
project.create()

0 commit comments

Comments
 (0)