-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
三少
committed
Feb 11, 2022
1 parent
827ee52
commit 922300c
Showing
25 changed files
with
1,889 additions
and
1,386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ swan | |
tt | ||
h5 | ||
kwai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ swan | |
tt | ||
h5 | ||
kwai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ swan | |
tt | ||
h5 | ||
kwai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,75 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const path = require('path') | ||
|
||
const configName = { | ||
weapp: { | ||
srcConfigName: 'project.weapp.json', | ||
distConfigName: 'project.config.json', | ||
}, | ||
alipay: { | ||
srcConfigName: 'project.alipay.json', | ||
distConfigName: 'mini.project.json', | ||
}, | ||
tt: { | ||
srcConfigName: 'project.tt.json', | ||
distConfigName: 'project.config.json', | ||
}, | ||
dd: { | ||
srcConfigName: 'project.dd.json', | ||
distConfigName: 'mini.project.json', | ||
}, | ||
} | ||
|
||
module.exports = function (ctx) { | ||
ctx.onBuildFinish(() => { | ||
if (process.env.TARO_ENV !== 'h5') { | ||
const { appPath, sourcePath, outputPath } = ctx.paths | ||
const { printLog, processTypeEnum, fs } = ctx.helper | ||
const pkg = fs.readJSONSync(path.resolve(process.cwd(), './package.json')) | ||
const srcConfigName = | ||
configName[ctx.initialConfig.outputRoot].srcConfigName | ||
const distConfigName = | ||
configName[ctx.initialConfig.outputRoot].distConfigName | ||
ctx.registerMethod( | ||
'generateProjectConfig', | ||
({ srcConfigName, distConfigName }) => { | ||
// 混合模式不需要生成项目配置 | ||
const { blended } = ctx.runOpts | ||
if (blended) return | ||
|
||
if (process.env.TARO_ENV !== 'h5') { | ||
const { appPath, sourcePath, outputPath } = ctx.paths | ||
const { printLog, processTypeEnum, fs } = ctx.helper | ||
const pkg = fs.readJSONSync( | ||
path.resolve(process.cwd(), './package.json'), | ||
) | ||
|
||
if (fs.existsSync(`${outputPath}/${distConfigName}`)) { | ||
if (process.env.TARO_ENV === 'tt') { | ||
const origProjectConfig = fs.readJSONSync( | ||
`${outputPath}/${distConfigName}`, | ||
) | ||
if (origProjectConfig.appid) return | ||
} else { | ||
return | ||
if (fs.existsSync(`${outputPath}/${distConfigName}`)) { | ||
if (process.env.TARO_ENV === 'tt') { | ||
const origProjectConfig = fs.readJSONSync( | ||
`${outputPath}/${distConfigName}`, | ||
) | ||
if (origProjectConfig.appid) return | ||
} else { | ||
return | ||
} | ||
} | ||
} | ||
|
||
// 生成 project.config.json | ||
const projectConfigFileName = srcConfigName | ||
let projectConfigPath = path.join(appPath, projectConfigFileName) | ||
if (!fs.existsSync(projectConfigPath)) { | ||
// 若项目根目录不存在对应平台的 projectConfig 文件,则尝试从源代码目录查找 | ||
projectConfigPath = path.join(sourcePath, projectConfigFileName) | ||
if (!fs.existsSync(projectConfigPath)) return | ||
} | ||
// 生成 project.config.json | ||
const projectConfigFileName = srcConfigName | ||
let projectConfigPath = path.join(appPath, projectConfigFileName) | ||
if (!fs.existsSync(projectConfigPath)) { | ||
// 若项目根目录不存在对应平台的 projectConfig 文件,则尝试从源代码目录查找 | ||
projectConfigPath = path.join(sourcePath, projectConfigFileName) | ||
if (!fs.existsSync(projectConfigPath)) return | ||
} | ||
|
||
const origProjectConfig = fs.readJSONSync(projectConfigPath) | ||
// compileType 是 plugin 时不修改 miniprogramRoot 字段 | ||
let distProjectConfig = origProjectConfig | ||
if (origProjectConfig.compileType !== 'plugin') { | ||
distProjectConfig = Object.assign({}, origProjectConfig, { | ||
miniprogramRoot: './', | ||
}) | ||
if ( | ||
ctx.initialConfig.outputRoot === 'weapp' || | ||
ctx.initialConfig.outputRoot === 'tt' | ||
) { | ||
distProjectConfig.appid = | ||
pkg.appId[ctx.initialConfig.outputRoot][process.env.API_ENV] | ||
const origProjectConfig = fs.readJSONSync(projectConfigPath) | ||
// compileType 是 plugin 时不修改 miniprogramRoot 字段 | ||
let distProjectConfig = origProjectConfig | ||
if (origProjectConfig.compileType !== 'plugin') { | ||
distProjectConfig = Object.assign({}, origProjectConfig, { | ||
miniprogramRoot: './', | ||
}) | ||
if ( | ||
process.env.API_ENV === 'dev' || | ||
process.env.API_ENV === 'stable' | ||
ctx.initialConfig.outputRoot === 'weapp' || | ||
ctx.initialConfig.outputRoot === 'qq' || | ||
ctx.initialConfig.outputRoot === 'kwai' || | ||
ctx.initialConfig.outputRoot === 'swan' || | ||
ctx.initialConfig.outputRoot === 'tt' | ||
) { | ||
distProjectConfig.setting.urlCheck = false | ||
distProjectConfig.appid = | ||
pkg.appId[ctx.initialConfig.outputRoot][process.env.API_ENV] | ||
if ( | ||
process.env.API_ENV === 'dev' || | ||
process.env.API_ENV === 'stable' | ||
) { | ||
distProjectConfig.setting.urlCheck = false | ||
} | ||
} | ||
} | ||
ctx.writeFileToDist({ | ||
filePath: distConfigName, | ||
content: JSON.stringify(distProjectConfig, null, 2), | ||
}) | ||
printLog( | ||
processTypeEnum.GENERATE, | ||
'工具配置', | ||
`${outputPath}/${distConfigName}`, | ||
) | ||
} | ||
ctx.writeFileToDist({ | ||
filePath: distConfigName, | ||
content: JSON.stringify(distProjectConfig, null, 2), | ||
}) | ||
printLog( | ||
processTypeEnum.GENERATE, | ||
'工具配置', | ||
`${outputPath}/${distConfigName}`, | ||
) | ||
} | ||
}) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.