Skip to content

Commit

Permalink
chore(config): upgrade configs style
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwong committed Nov 5, 2021
1 parent 4b67aed commit 8401bd2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ dist

lib
temp
*.bak
1 change: 0 additions & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./lib/index.d.ts",
"bundledPackages": [ ],
// 生成 api 报告,生成的还没 .d.ts 看的舒服,关了
"apiReport": {
"enabled": false,
"reportFolder": "./lib/"
Expand Down
54 changes: 35 additions & 19 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ const paths = {
lib: path.join(__dirname, '/lib'),
}


// 删除 lib 文件
const clearLibFile: TaskFunc = async (cb) => {
const clearLibFile: TaskFunc = async cb => {
fse.removeSync(paths.lib)
log.progress('Deleted lib file')
cb()
}

// rollup 打包
const buildByRollup: TaskFunc = async (cb) => {
const buildByRollup: TaskFunc = async cb => {
const inputOptions = {
input: rollupConfig.input,
external: rollupConfig.external,
Expand All @@ -49,7 +48,7 @@ const buildByRollup: TaskFunc = async (cb) => {

// 写入需要遍历输出配置
if (Array.isArray(outOptions)) {
outOptions.forEach(async (outOption) => {
outOptions.forEach(async outOption => {
await bundle.write(outOption)
})
cb()
Expand All @@ -58,24 +57,34 @@ const buildByRollup: TaskFunc = async (cb) => {
}

// api-extractor 整理 .d.ts 文件
const apiExtractorGenerate: TaskFunc = async (cb) => {
const apiExtractorJsonPath: string = path.join(__dirname, './api-extractor.json')
const apiExtractorGenerate: TaskFunc = async cb => {
const apiExtractorJsonPath: string = path.join(
__dirname,
'./api-extractor.json',
)
// 加载并解析 api-extractor.json 文件
const extractorConfig: ExtractorConfig = await ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath)
const extractorConfig: ExtractorConfig = await ExtractorConfig.loadFileAndPrepare(
apiExtractorJsonPath,
)
// 判断是否存在 index.d.ts 文件,这里必须异步先访问一边,不然后面找不到会报错
const isExist: boolean = await fse.pathExists(extractorConfig.mainEntryPointFilePath)
const isExist: boolean = await fse.pathExists(
extractorConfig.mainEntryPointFilePath,
)

if (!isExist) {
log.error('API Extractor not find index.d.ts')
return
}

// 调用 API
const extractorResult: ExtractorResult = await Extractor.invoke(extractorConfig, {
localBuild: true,
// 在输出中显示信息
showVerboseMessages: true,
})
const extractorResult: ExtractorResult = await Extractor.invoke(
extractorConfig,
{
localBuild: true,
// 在输出中显示信息
showVerboseMessages: true,
},
)

if (extractorResult.succeeded) {
// 删除多余的 .d.ts 文件
Expand All @@ -88,12 +97,14 @@ const apiExtractorGenerate: TaskFunc = async (cb) => {
log.progress('API Extractor completed successfully')
cb()
} else {
log.error(`API Extractor completed with ${extractorResult.errorCount} errors`
+ ` and ${extractorResult.warningCount} warnings`)
log.error(
`API Extractor completed with ${extractorResult.errorCount} errors` +
` and ${extractorResult.warningCount} warnings`,
)
}
}

const complete: TaskFunc = (cb) => {
const complete: TaskFunc = cb => {
log.progress('---- end ----')
cb()
}
Expand All @@ -103,10 +114,15 @@ const complete: TaskFunc = (cb) => {
// 2. rollup 打包
// 3. api-extractor 生成统一的声明文件, 删除多余的声明文件
// 4. 完成
export const build = series(clearLibFile, buildByRollup, apiExtractorGenerate, complete)
export const build = series(
clearLibFile,
buildByRollup,
apiExtractorGenerate,
complete,
)

// 自定义生成 changelog
export const changelog: TaskFunc = async (cb) => {
export const changelog: TaskFunc = async cb => {
const changelogPath: string = path.join(paths.root, 'CHANGELOG.md')
// 对命令 conventional-changelog -p angular -i CHANGELOG.md -w -r 0
const changelogPipe = await conventionalChangelog({
Expand All @@ -116,7 +132,7 @@ export const changelog: TaskFunc = async (cb) => {
changelogPipe.setEncoding('utf8')

const resultArray = ['# 工具库更新日志\n\n']
changelogPipe.on('data', (chunk) => {
changelogPipe.on('data', chunk => {
// 原来的 commits 路径是进入提交列表
chunk = chunk.replace(/\/commits\//g, '/commit/')
resultArray.push(chunk)
Expand Down

0 comments on commit 8401bd2

Please sign in to comment.