diff --git a/.gitignore b/.gitignore index a54ae7d..db5fc32 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ dist lib temp +*.bak diff --git a/api-extractor.json b/api-extractor.json index ca2a31d..9cd6e17 100644 --- a/api-extractor.json +++ b/api-extractor.json @@ -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/" diff --git a/gulpfile.ts b/gulpfile.ts index 04b16e2..2aae401 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -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, @@ -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() @@ -58,12 +57,19 @@ 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') @@ -71,11 +77,14 @@ const apiExtractorGenerate: TaskFunc = async (cb) => { } // 调用 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 文件 @@ -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() } @@ -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({ @@ -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)