Skip to content

Commit

Permalink
feat(cli): 支持 create 传递framework,css和typescript并且调整 templateSource 的优…
Browse files Browse the repository at this point in the history
…先级 (#16157)

* fix: 修复 readConfig 时引入 babel 导致问题

# Conflicts:
#	packages/taro-helper/src/utils.ts

* feat: vite 小程序端的 chunks 拆分

* fix(harmony): 修复读取配置时缺少常量注入

* fix: 修复读取配置时缺少常量的注入

* chore(release): publish 4.0.3-alpha.0 --tag=alpha

* feat: 修复vite的分chunk

* chore(release): publish 4.0.3-alpha.1 --tag=alpha

* fix: 修改readConfig方法

* chore(release): publish 4.0.3-alpah.2 --tag=alpha

* chore(release): publish 4.0.3-alpha.3 --tag=alpha

* feat: 修改mini chunks

* chore(release): publish 4.0.3-alpha.4 --tag=alpha

* feat: 支持 create 传递framework,css和typescript并且调整 templateSource 的优先级

* fix(lint): lint

---------

Co-authored-by: ZakaryCode <zakarycode@gmail.com>
Co-authored-by: liuzejia <liuzejia@SZMAC-FV0MR4G7.local>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent 4558798 commit 600af0f
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) {
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 600af0f

Please sign in to comment.