-
Notifications
You must be signed in to change notification settings - Fork 22
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
Showing
5 changed files
with
97 additions
and
11 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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import _ from 'shelljs' | ||
import biliConfig from '../bili.config' | ||
import fs from 'fs-extra' | ||
import globby from 'globby' | ||
import path from 'path' | ||
import { assign, ii, parallel } from '../src' | ||
|
||
ii(async function main() { | ||
// 工作目录 | ||
const wd = path.join(__dirname, '..') | ||
|
||
// 切换至工作目录 | ||
_.cd(wd) | ||
|
||
// 清空 lib 文件夹 | ||
_.rm('-rf', 'lib') | ||
|
||
// 构建包 | ||
_.exec('yarn bili') | ||
|
||
// 合并 ***.d.ts 为 index.d.ts | ||
const dFiles = await globby('lib/**/*.d.ts', { | ||
cwd: wd, | ||
absolute: true, | ||
}) | ||
const contentList = await parallel( | ||
dFiles.map(dFile => async () => { | ||
let content = /(index|test)\.d\.ts$/.test(dFile) ? '' : await fs.readFile(dFile) | ||
content = content.toString().replace(/^import .+ from .+$/gm, '') | ||
await fs.remove(dFile) | ||
return content | ||
}), | ||
) | ||
await fs.writeFile( | ||
path.join(wd, 'lib/index.d.ts'), | ||
contentList.filter(Boolean).join('\n\n'), | ||
) | ||
|
||
// 删除空文件夹 | ||
const emptyDirs = await globby('lib/*', { | ||
cwd: wd, | ||
onlyDirectories: true, | ||
absolute: true, | ||
}) | ||
await parallel( | ||
emptyDirs.map(emptyDir => async () => { | ||
await fs.remove(emptyDir) | ||
}), | ||
) | ||
|
||
// 替换 Object.assign 为自带的 assign | ||
_.ls('lib/*.js').forEach(builtFile => { | ||
_.sed( | ||
'-i', | ||
biliConfig.babel && biliConfig.babel.objectAssign || 'Object.assign', | ||
assign.name, | ||
builtFile, | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -920,6 +920,12 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/fs-extra@^7.0.0": | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-7.0.0.tgz#9c4ad9e1339e7448a76698829def1f159c1b636c" | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/glob@*", "@types/glob@^7.1.1": | ||
version "7.1.1" | ||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" | ||
|
@@ -1001,7 +1007,7 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/shelljs@^0.8.0": | ||
"@types/shelljs@^0.8.0", "@types/shelljs@^0.8.5": | ||
version "0.8.5" | ||
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.5.tgz#1e507b2f6d1f893269bd3e851ec24419ef9beeea" | ||
dependencies: | ||
|
@@ -2962,6 +2968,14 @@ [email protected], fs-extra@^7.0.0: | |
jsonfile "^4.0.0" | ||
universalify "^0.1.0" | ||
|
||
fs-extra@^8.0.1: | ||
version "8.0.1" | ||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.0.1.tgz#90294081f978b1f182f347a440a209154344285b" | ||
dependencies: | ||
graceful-fs "^4.1.2" | ||
jsonfile "^4.0.0" | ||
universalify "^0.1.0" | ||
|
||
fs-minipass@^1.2.5: | ||
version "1.2.5" | ||
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d" | ||
|
@@ -5972,7 +5986,7 @@ rollup-plugin-postcss@^2.0.3: | |
rollup-pluginutils "^2.0.1" | ||
style-inject "^0.3.0" | ||
|
||
rollup-plugin-replace@^2.1.0: | ||
rollup-plugin-replace@^2.1.0, rollup-plugin-replace@^2.2.0: | ||
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-2.2.0.tgz#f41ae5372e11e7a217cde349c8b5d5fd115e70e3" | ||
dependencies: | ||
|
@@ -6136,7 +6150,7 @@ shebang-regex@^1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" | ||
|
||
shelljs@^0.8.2: | ||
shelljs@^0.8.2, shelljs@^0.8.3: | ||
version "0.8.3" | ||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097" | ||
dependencies: | ||
|