Skip to content

Commit

Permalink
feat: 支持 create 传递framework,css和typescript并且调整 templateSource 的优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzejia authored and liuzejia committed Jul 25, 2024
1 parent ee576e0 commit c0cda1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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) {

Check failure on line 165 in packages/taro-cli/src/create/page.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Expected space(s) after "if"

Check failure on line 165 in packages/taro-cli/src/create/page.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Expected space(s) after "if"

Check failure on line 165 in packages/taro-cli/src/create/page.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-12)

Expected space(s) after "if"

Check failure on line 165 in packages/taro-cli/src/create/page.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Expected space(s) after "if"
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

0 comments on commit c0cda1d

Please sign in to comment.