Skip to content
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

feat(cli): 支持 create 传递framework,css和typescript并且调整 templateSource 的优先级 #16157

Merged
merged 17 commits into from
Jul 25, 2024
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
22 changes: 12 additions & 10 deletions packages/taro-cli/src/create/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,19 @@ export default class Page extends Creator {
let templateSource = DEFAULT_TEMPLATE_SRC
if (!homedir) chalk.yellow('找不到用户根目录,使用默认模版源!')

const taroConfigPath = path.join(homedir, TARO_CONFIG_FOLDER)
const taroConfig = path.join(taroConfigPath, TARO_BASE_CONFIG)

if (fs.existsSync(taroConfig)) {
const config = await fs.readJSON(taroConfig)
templateSource = config && config.templateSource ? config.templateSource : DEFAULT_TEMPLATE_SRC
if (this.conf.templateSource) {
templateSource = this.conf.templateSource
} else {
templateSource = this.conf.templateSource || DEFAULT_TEMPLATE_SRC

await fs.createFile(taroConfig)
await fs.writeJSON(taroConfig, { templateSource })
const taroConfigPath = path.join(homedir, TARO_CONFIG_FOLDER)
const taroConfig = path.join(taroConfigPath, TARO_BASE_CONFIG)
if (fs.existsSync(taroConfig)) {
const config = await fs.readJSON(taroConfig)
templateSource = config && config.templateSource ? config.templateSource : DEFAULT_TEMPLATE_SRC
} else {
await fs.createFile(taroConfig)
await fs.writeJSON(taroConfig, { templateSource })
templateSource = DEFAULT_TEMPLATE_SRC
}
}

// 从模板源下载模板
Expand Down
6 changes: 6 additions & 0 deletions packages/taro-cli/src/presets/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export default (ctx: IPluginContext) => {
const description = options.description || ''
const afterCreate = options.afterCreate
const templateSource = options.templateSource
const framework = options.framework
const css = options.css
const typescript = options.typescript
const clone = options.clone
const { chalk } = ctx.helper
const { appPath } = ctx.paths
Expand All @@ -57,6 +60,9 @@ export default (ctx: IPluginContext) => {
const page = new Page({
clone,
subPkg: options.subpkg,
framework,
css,
typescript,
pageDir: options.dir,
pageName: name,
projectDir: appPath,
Expand Down
Loading