t-comm
Version:
专业、稳定、纯粹的工具库
92 lines (87 loc) • 2.85 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var fs_fs = require('../fs/fs.js');
var string_replaceAll = require('../string/replace-all.js');
require('fs');
var replaceList = [{
from: '🐛 Bug Fixes | Bug 修复',
to: 'Bug Fixes 🐞'
}, {
from: '✨ Features | 新功能',
to: 'Features 🎉'
}, {
from: '✏️ Documentation | 文档',
to: 'Documentation 📖'
}, {
from: '♻️ Code Refactoring | 代码重构',
to: 'Code Refactoring ♻️'
}, {
from: '🚀 Chore | 构建/工程依赖/工具',
to: 'Chore 🚀 '
}, {
from: '📦 Build System | 打包构建',
to: 'Build System 📦'
}, {
from: '✅ Tests | 测试',
to: 'Tests ✅'
}, {
from: '💄 Styles | 风格',
to: 'Styles 💄'
}];
function replaceChangeLogKeywords(data) {
if (data === void 0) {
data = '';
}
string_replaceAll.replaceAllPolyfill();
var newData = data;
for (var _i = 0, replaceList_1 = replaceList; _i < replaceList_1.length; _i++) {
var item = replaceList_1[_i];
var from = item.from,
to = item.to;
newData = newData.replaceAll(from, to);
}
return newData;
}
/**
* 同步最新版本的更新日志
* @param {object} params 参数
* @param {string} params.changelogPath 源 change-log路径
* @param {string} params.docChangelogPath 文档 change-log 路径
* @param {string} params.packageJsonPath package.json 路径
*
* @example
* ```ts
* const DOC_CHANGE_LOG_PATH = './docs/CHANGELOG.md';
* const SOURCE_CHANGE_LOG_PATH = './CHANGELOG.md';
*
* insertDocChangeLog({
* changelogPath: SOURCE_CHANGE_LOG_PATH,
* docChangeLog: DOC_CHANGE_LOG_PATH,
* packageJsonPath: './package.json',
* });
* ```
*/
function insertDocChangeLog(_a) {
var changelogPath = _a.changelogPath,
docChangelogPath = _a.docChangelogPath,
packageJsonPath = _a.packageJsonPath;
var changeLog = fs_fs.readFileSync(changelogPath, false);
var pkg = fs_fs.readFileSync(packageJsonPath, true);
var version = pkg.version;
// version = '1.0.31';
console.log('[insertDocChangeLog] version: ', version);
if (!version) return;
var reg = new RegExp("\\n([#]+\\s*\\[".concat(version, "\\].*?\\n)(?=[#]+\\s*\\[\\d+\\.\\d+\\.\\d+)"), 's');
var match = changeLog.match(reg);
if (!(match === null || match === void 0 ? void 0 : match[1])) return;
console.log('[insertDocChangeLog] match: ', match[1]);
var docChangeLog = fs_fs.readFileSync(docChangelogPath);
var newDocChangeLog = docChangeLog.replace(/(?=([#]{2,}))/, match[1]);
newDocChangeLog = replaceChangeLogKeywords(newDocChangeLog);
fs_fs.writeFileSync(docChangelogPath, newDocChangeLog);
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('child_process').execSync('git add .', {
stdio: 'inherit'
});
}
exports.insertDocChangeLog = insertDocChangeLog;