-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create release script and refactor build
- Loading branch information
Showing
3 changed files
with
114 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
exports.packages = [ | ||
{ | ||
entry: '@dxjs/core', | ||
global: 'Dx', | ||
externals: [ | ||
{ entry: 'react', global: 'React' }, | ||
{ entry: 'react-dom', global: 'ReactDom' }, | ||
{ entry: 'redux', global: 'redux' }, | ||
{ entry: 'react-redux', global: 'reactRedux' }, | ||
{ entry: '@dxjs/common', global: 'DxCommon' }, | ||
{ entry: 'reflect-metadata', global: '' }, | ||
], | ||
}, | ||
{ | ||
entry: '@dxjs/common', | ||
global: 'DxCommon', | ||
externals: [ | ||
{ entry: 'react', global: 'React' }, | ||
{ entry: 'react-dom', global: 'ReactDom' }, | ||
{ entry: 'react-redux', global: 'ReactRedux' }, | ||
{ entry: 'reflect-metadata', global: '' }, | ||
], | ||
}, | ||
]; | ||
|
||
const UMD = 'UMD'; | ||
const UMD_DEV = 'UMD_DEV'; | ||
const CJS = 'CJS'; | ||
const CJS_DEV = 'CJS_DEV'; | ||
|
||
exports.bundleTypes = [UMD, UMD_DEV, CJS, CJS_DEV]; | ||
exports.UMD = UMD; | ||
exports.UMD_DEV = UMD_DEV; | ||
exports.CJS = CJS; | ||
exports.CJS_DEV = CJS_DEV; |
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,59 @@ | ||
/** | ||
* 当前脚本会在 pre-push 的时候执行, | ||
* 执行前判断 commit log 是否 release(release_type): xxx 的格式 | ||
* 如果是 commit type 是 release 则修改 package.json 并且打个 tag | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const semver = require('semver'); | ||
const { sync } = require('conventional-commits-parser'); | ||
const defaultChangelogOpts = require('conventional-changelog-angular'); | ||
const cp = require('child_process'); | ||
|
||
const CWD = process.cwd(); | ||
|
||
function formatCommitMessage() { | ||
const commitLog = cp | ||
.execSync('git log -n 1 --pretty=format:"%B"') | ||
.toString('utf8') | ||
.trim(); | ||
|
||
return sync(commitLog, defaultChangelogOpts); | ||
} | ||
|
||
function updateVersion(pkgPath) { | ||
if (!fs.existsSync(pkgPath)) return; | ||
const commit = formatCommitMessage(); | ||
if (commit.type.toLowerCase() !== 'release') return; | ||
|
||
const packageJSON = JSON.parse(fs.readFileSync(pkgPath).toString('utf8')); | ||
const currentVersion = packageJSON.version; | ||
const nextVersion = semver.inc(currentVersion, commit.scope || 'patch'); | ||
fs.writeFileSync(pkgPath, JSON.stringify({ ...packageJSON, version: nextVersion }, null, 2)); | ||
|
||
return nextVersion; | ||
} | ||
|
||
function updatePackageVersion() { | ||
fs.readdirSync('packages').forEach(name => { | ||
const dirname = path.join(CWD, 'packages', name); | ||
if (!fs.statSync(dirname).isDirectory) return; | ||
updateVersion(path.join(dirname, 'package.json')); | ||
}); | ||
} | ||
|
||
function updateGlobalVersion() { | ||
const version = updateVersion(path.join(CWD, 'package.json')); | ||
|
||
cp.execSync('git tag v' + version); | ||
} | ||
|
||
function run() { | ||
updateGlobalVersion(); | ||
updatePackageVersion(); | ||
|
||
cp.execSync('git add package.json && git add */**/package.json && git commit --amend --no-edit'); | ||
} | ||
|
||
run(); |