diff --git a/.rczrc b/.rczrc.json similarity index 71% rename from .rczrc rename to .rczrc.json index ea4301a..8ecc533 100644 --- a/.rczrc +++ b/.rczrc.json @@ -3,6 +3,7 @@ "commands", "changelog", "readme", - "release" + "release", + "config" ] } diff --git a/README.md b/README.md index 043a821..ce81777 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Resultium commit standardization library ## Configuration -You can create an `.rczrc` file in your root directory and specify available scopes and commit types +You can create an `.rczrc`, `.rczrc.json` or `rcz.config.json` file in your root directory and specify available scopes and commit types ```json { diff --git a/package.json b/package.json index 550a8bc..e20396a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@resultium/rcz", - "version": "1.4.0", + "version": "1.5.0", "description": "Resultium commit standardization library, based on conventional commits", "main": "./dist/index.js", "bin": { diff --git a/src/index.ts b/src/index.ts index 18c9913..e4a7c1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,18 @@ const GetConfig = async () => { await fs.promises.readFile(path.join(process.cwd(), ".rczrc")) ).toString() ) as Config; + } else if (fs.existsSync(path.join(process.cwd(), ".rczrc.json"))) { + return JSON.parse( + ( + await fs.promises.readFile(path.join(process.cwd(), ".rczrc.json")) + ).toString() + ) as Config; + } else if (fs.existsSync(path.join(process.cwd(), "rcz.config.json"))) { + return JSON.parse( + ( + await fs.promises.readFile(path.join(process.cwd(), "rcz.config.json")) + ).toString() + ) as Config; } else { return null; } @@ -39,8 +51,10 @@ program .command("commit") .description("Create a conventional commit") .option("-S, --sign", "sign the commit") + .option("--amend", "amend commit message to the last commit") .action(async (options) => { const sign = options.sign ? true : false; + const amend = options.amend ? true : false; const config = await GetConfig(); @@ -51,10 +65,12 @@ program process.exit(0); } - const stageAll = await confirm({ - message: "Stage all changes?", - initialValue: true, - }); + const stageAll = amend + ? null + : await confirm({ + message: "Stage all changes?", + initialValue: true, + }); if (isCancel(stageAll)) { cancel("Commit creation cancelled"); @@ -99,6 +115,11 @@ program value: "refactor", hint: "code change that neither fixes a bug nor adds a feature", }, + { + label: "chore", + value: "chore", + hint: "changes that are routinely, e.g. dependency update or a release commit", + }, ], }); @@ -192,14 +213,24 @@ program if (stageAll) { await simpleGit() .add(".") - .commit(commitMessage, sign ? ["-S"] : []); + .commit( + commitMessage, + sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : [] + ); } else { - await simpleGit().commit(commitMessage, sign ? ["-S"] : []); + await simpleGit().commit( + commitMessage, + sign ? (amend ? ["-S", "--amend"] : ["-S"]) : amend ? ["--amend"] : [] + ); } note(commitMessage); - outro("Finished creating a conventional commit, feel free to push"); + outro( + `Finished ${ + amend ? "amending" : "creating" + } a conventional commit, feel free to push` + ); }); program @@ -436,7 +467,7 @@ program config?.types?.map((type) => type.value).join("|") || "feat|fix|build|ci|docs|perf|refactor" })(\\((${ - config?.scopes?.join("|") || "..*" + config?.scopes ? [...config?.scopes, "release"] : "..*" })\\))?!?: .* ?(\\(..*\\))?((\n\n..*)?(\n\n..*)?)?`, "gm" );