Skip to content

Commit

Permalink
feat: 构建流程优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed May 30, 2019
1 parent 664b634 commit 88daef3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 11 deletions.
5 changes: 5 additions & 0 deletions bili.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const config: Config = {
dir: 'lib',
format: ['cjs', 'es', 'umd', 'umd-min'],
moduleName: 'vtils',
sourceMap: false,
},
babel: {
minimal: true,
objectAssign: '__OBJECT_ASSIGN__',
},
}

Expand Down
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "vtils",
"version": "1.6.3",
"description": "一些常用的 JavaScript 工具函数",
"main": "lib/vtils.cjs.js",
"module": "lib/vtils.es.js",
"unpkg": "lib/vtils.min.js",
"jsdelivr": "lib/vtils.min.js",
"description": "小巧实用的 JavaScript 工具类库",
"main": "lib/index.js",
"module": "lib/index.esm.js",
"unpkg": "lib/index.umd.js",
"jsdelivr": "lib/index.umd.js",
"types": "lib/index.d.ts",
"homepage": "https://github.com/fjc0k/vtils",
"license": "MIT",
Expand All @@ -18,6 +18,8 @@
"url": "https://github.com/fjc0k/vtils/issues"
},
"keywords": [
"javascript",
"typescript",
"utils"
],
"files": [
Expand All @@ -31,10 +33,10 @@
"scripts": {
"docsOnly": "typedoc --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeProtected --exclude **/libs/**/* --out docs --theme minimal --mode file src/index.ts",
"docs": "yarn docsOnly && gh-pages -d docs",
"lint": "eslint --fix --ext .ts src/ test/",
"lint": "eslint --fix --ext .ts src/ scripts/",
"testOnly": "jest",
"test": "jest --coverage",
"build": "bili",
"build": "yarn ts-node --compiler-options '{\"module\":\"commonjs\"}' --files scripts/build.ts",
"release": "standard-version -a && git push --follow-tags origin master && yarn build && yarn docs && npm publish"
},
"eslintConfig": {
Expand All @@ -61,19 +63,24 @@
},
"devDependencies": {
"@tarojs/taro-h5": "^1.2.26",
"@types/fs-extra": "^7.0.0",
"@types/globby": "^9.1.0",
"@types/jest": "^24.0.13",
"@types/shelljs": "^0.8.5",
"@types/sinon": "^5.0.5",
"bili": "^4.8.0",
"codecov": "^3.1.0",
"eslint": "^5.9.0",
"eslint-config-io": "^0.5.0",
"fs-extra": "^8.0.1",
"gh-pages": "^2.0.1",
"globby": "^9.2.0",
"jest": "^24.8.0",
"moment": "^2.22.2",
"nervjs": "^1.3.13",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-typescript2": "^0.21.1",
"shelljs": "^0.8.3",
"standard-version": "^4.4.0",
"ts-jest": "^24.0.2",
"ts-node": "^8.0.2",
Expand Down
60 changes: 60 additions & 0 deletions scripts/build.ts
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,
)
})
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"strict": true,
"target": "es5",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
Expand Down
20 changes: 17 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 88daef3

Please sign in to comment.