forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(BuildTool): adjust tools structure
- Loading branch information
Showing
18 changed files
with
345 additions
and
115 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
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 |
---|---|---|
|
@@ -3,7 +3,5 @@ | |
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"no-console": "off" | ||
} | ||
"rules": {} | ||
} |
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,105 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
import * as semver from 'semver'; | ||
import * as inquirer from 'inquirer'; | ||
import conventionalChangelog from 'conventional-changelog'; | ||
import config from 'conventional-changelog-alifd'; | ||
import { CWD, log, querySync, warn } from '../../utils'; | ||
|
||
const changelogPath = 'CHANGELOG.md'; | ||
const latestedLogPath = 'LATESTLOG.md'; | ||
|
||
function updateVersion(version: string, type = 'z', addend = 1) { | ||
if (!semver.valid(version)) { | ||
return version; | ||
} | ||
|
||
const versionArr: Array<string | number> = version.split('.'); | ||
|
||
switch (type) { | ||
case 'x': | ||
versionArr[2] = 0; | ||
versionArr[1] = 0; | ||
versionArr[0] = parseInt(versionArr[0] as string) + 1; | ||
break; | ||
case 'y': | ||
versionArr[2] = 0; | ||
versionArr[1] = parseInt(versionArr[1] as string) + 1; | ||
break; | ||
default: | ||
versionArr[2] = parseInt(versionArr[2] as string) + addend; | ||
} | ||
|
||
return versionArr.join('.'); | ||
} | ||
|
||
export async function changelog() { | ||
const packagePath = path.resolve('package.json'); | ||
|
||
const packageInfo = fs.readJSONSync(packagePath); | ||
|
||
// const npmInfo = yield getRemotePkgInfo(); | ||
|
||
const npmVersion = querySync('npm', ['show', packageInfo.name, 'version']); | ||
log(`[提示] [local:${packageInfo.version}] [npm:${npmVersion}] 请为本次提交指定新的版本号:`); | ||
|
||
const current = await inquirer.prompt([ | ||
{ | ||
name: 'version', | ||
type: 'input', | ||
default: updateVersion(packageInfo.version, 'z'), | ||
message: '请输入待发布的版本号:', | ||
validate: function (value) { | ||
if (!semver.valid(value) || semver.lte(value, npmVersion)) { | ||
warn('请输入正确的版本号,并且大于基线版本号!'); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}, | ||
]); | ||
|
||
packageInfo.version = current.version; | ||
|
||
await fs.writeJson(packagePath, packageInfo, { spaces: 2 }); | ||
|
||
log(`[提示] 回写版本号 ${packageInfo.version} 到 package.json success`); | ||
|
||
log(`正在生成 ${changelogPath} 文件,请稍等几秒钟...`); | ||
|
||
conventionalChangelog({ | ||
config, | ||
}).on('data', (chunk: Buffer) => { | ||
const log = chunk.toString().replace(/(\n## [.\d\w]+ )\(([\d-]+)\)\n/g, (all, s1, s2) => { | ||
return `${s1}/ ${s2}\n`; | ||
}); | ||
|
||
let changelogContent = fs.readFileSync(changelogPath, 'utf8'); | ||
changelogContent = changelogContent.split('\n').slice(1).join('\n'); | ||
fs.writeFileSync(changelogPath, `# Change Log \n\n${log}${changelogContent}`); | ||
|
||
const lines = log.split(/\n/g); | ||
let firstIndex = -1, | ||
secondIndex = -1; | ||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
if (/^##? \[/.test(line)) { | ||
if (firstIndex === -1) { | ||
firstIndex = i; | ||
} else if (secondIndex === -1) { | ||
secondIndex = i; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (firstIndex > -1) { | ||
secondIndex = secondIndex === -1 ? lines.length : secondIndex; | ||
const latestedLog = lines.slice(firstIndex, secondIndex - 1).join('\n'); | ||
fs.writeFileSync(latestedLogPath, `# Latest Log \n\n${latestedLog}`); | ||
} | ||
}); | ||
|
||
log(`成功将 ${changelogPath} 文件生成到 ${CWD} 目录下`); | ||
} |
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,10 @@ | ||
/* | ||
------------------------------------------------------------ | ||
author: 珵之 | ||
create: 2023-12-19 16:33:40 | ||
description: 生成 changelog 信息 | ||
------------------------------------------------------------ | ||
*/ | ||
import { changelog } from './build/tools/changelog'; | ||
|
||
changelog(); |
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,44 @@ | ||
/* | ||
------------------------------------------------------------ | ||
author: 珵之 | ||
create: 2023-12-19 15:19:10 | ||
description: css 样式检查 | ||
example: | ||
npm run check:stylelint button | ||
npm run check:stylelint button --fix | ||
npm run check:stylelint ./components/button table | ||
------------------------------------------------------------ | ||
*/ | ||
|
||
import chalk from 'chalk'; | ||
import { execSync, TARGETS, ARGV, getBin, log, error } from '../utils'; | ||
|
||
const binPath = getBin('stylelint'); | ||
|
||
if (!binPath) { | ||
throw new Error('Not found stylelint'); | ||
} | ||
|
||
if (!TARGETS.length) { | ||
log(chalk.yellow('[Example]:')); | ||
log('npm run check:stylelint button'); | ||
log('npm run check:stylelint button --fix'); | ||
log(`npm run check:stylelint ./components/button table`); | ||
|
||
throw new Error('请指定一个合法目录'); | ||
} | ||
|
||
const args: string[] = []; | ||
|
||
if (ARGV.fix) { | ||
args.push('--fix'); | ||
} | ||
args.push(...TARGETS); | ||
|
||
const result = execSync(binPath, args); | ||
|
||
if (result === true) { | ||
log('stylelint 校验通过'); | ||
} else if (result === false) { | ||
error('stylelint 校验失败'); | ||
} |
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,11 @@ | ||
/* | ||
------------------------------------------------------------ | ||
author: 珵之 | ||
create: 2023-12-19 17:13:32 | ||
description: 发布组件库 | ||
------------------------------------------------------------ | ||
*/ | ||
|
||
import { execSync } from './utils'; | ||
|
||
|
Oops, something went wrong.