@ehmicky/dev-tasks
Version:
Automated development tasks for my own projects
44 lines (34 loc) • 853 B
JavaScript
import{readFile}from"node:fs/promises";
import{argv}from"node:process";
import handleCliError from"handle-cli-error";
import{pathExists}from"path-exists";
import{printAutoChangelog}from"./auto.js";
import{printManualChangelog}from"./manual.js";
const runCli=async()=>{
try{
const[,,increment]=argv;
await printChangelog(increment)
}catch(error){
handleCliError(error,{
classes:{
TypeError:{stack:false},
default:{stack:true}
}
})
}
};
const printChangelog=async(increment)=>{
if(!(await pathExists(CHANGELOG_FILE))){
throw new TypeError(`Could not find ${CHANGELOG_FILE}.`)
}
const contents=await readFile(CHANGELOG_FILE,"utf8");
const contentsA=contents.trim();
if(contentsA===""){
await printAutoChangelog();
return
}
await printManualChangelog(contentsA,increment)
};
const CHANGELOG_FILE="CHANGELOG.md";
await runCli();