@shuyun-ep-team/scripts
Version:
为项目提供相应的脚本,使其减少繁琐的配置。
42 lines • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dayjs_1 = __importDefault(require("dayjs"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const git_1 = require("./utils/git");
function getDebugJsonInfo() {
const { commitDate, commitId, commitMessage, committer } = git_1.getCommit();
const branch = git_1.getBranch();
const tags = git_1.getTags();
const tag = tags.find(({ commitId: id }) => commitId && id === commitId);
const debugInfo = {
branch,
committer,
commit_id: commitId,
commit_date: dayjs_1.default(commitDate).format('YYYY/MM/DD HH:mm:ss'),
commit_message: commitMessage,
tag: tag ? tag.tag : '',
publish_date: dayjs_1.default().format('YYYY/MM/DD HH:mm:ss')
};
if (!tag) {
Reflect.deleteProperty(debugInfo, 'tag');
}
return debugInfo;
}
function createDebugFile(path, append) {
try {
const config = getDebugJsonInfo();
if (append) {
config.append = append;
}
const text = JSON.stringify(config, null, 2);
fs_extra_1.default.writeFileSync(path, text, 'utf-8');
}
catch (err) {
throw new Error(err);
}
}
exports.createDebugFile = createDebugFile;
//# sourceMappingURL=debug.js.map