diff --git a/packages/automatic-versioning/package.json b/packages/automatic-versioning/package.json
index 0c8ca24..853cf5e 100644
--- a/packages/automatic-versioning/package.json
+++ b/packages/automatic-versioning/package.json
@@ -14,7 +14,8 @@
},
"dependencies": {
"@actions/exec": "1.1.1",
- "@colors/colors": "1.5.0"
+ "@colors/colors": "1.5.0",
+ "commander": "11.1.0"
},
"author": "SLIIT FOSS",
"license": "MIT",
diff --git a/packages/automatic-versioning/readme.md b/packages/automatic-versioning/readme.md
index 656b35f..43a5bf5 100644
--- a/packages/automatic-versioning/readme.md
+++ b/packages/automatic-versioning/readme.md
@@ -93,12 +93,12 @@ yarn bump-version
- Fix - bump patch version
```
-## Disable commit
+## Skip commit
-- By default automatic-versioning will commit the newly incremented version to source control. To disable this behavior, add the following to your script: "--no-commit"
+- By default automatic-versioning will commit the newly incremented version to source control. To disable this behavior, add the following to your script: "--skip-commit"
```bash
- npx automatic-versioning --name= --no-commit
+ npx automatic-versioning --name= --skip-commit
```
## Disable version bumping for specific commit
@@ -107,21 +107,13 @@ yarn bump-version
git commit -m "Feat: some feature --no-bump"
```
-## Disable --no-bump commit message edit
-
-- By default automatic-versioning will edit the commit message in no-bump commits and remove the no-bump part from the commit message. Sometimes such as in the case of monorepos, this can prove to be a problem. To disable this behavior, add the following to your script: "--no-commit-edit"
-
-```bash
- npx automatic-versioning --name= --no-commit-edit
-```
-
-## Custom app directory to run incrementing script
+## Custom app directory to run versioning script
```bash
- npx automatic-versioning --name= --rootDir=
+ npx automatic-versioning --name= --root=
```
-## Recursively search commit history to find version bump trigger
+## Recursively search commit history to find a supporting prefix to trigger a version bump
```bash
npx automatic-versioning --name= --recursive
@@ -152,3 +144,10 @@ yarn bump-version
```bash
npx automatic-versioning --name= --ignore-prefixes=ci,docs
```
+
+---
+
+## Migration from V1 to V2
+
+- `--no-commit-edit` option has been removed as commits no longer cause problems with the versioning script
+- `--no-commit` option has been renamed to `--skip-commit`
diff --git a/packages/automatic-versioning/src/index.js b/packages/automatic-versioning/src/index.js
index b5d945e..6e255e3 100644
--- a/packages/automatic-versioning/src/index.js
+++ b/packages/automatic-versioning/src/index.js
@@ -2,46 +2,59 @@
/* eslint-disable no-console */
-import path from "path";
-
-import defaultRunner from "./types/default";
-import tagBasedRunner from "./types/tag-based";
+import { default as path } from "path";
+import { program, Option } from "commander";
+import { version } from "../package.json";
+import { defaultRunner, tagBasedRunner } from "./types";
require("@colors/colors");
-const args = process.argv.slice(2);
+program
+ .name("automatic-versioning")
+ .description("CLI for automated commit based semantic versioning with excellent support for monorepositories")
+ .version(version);
+
+program
+ .addOption(
+ new Option("-n, --name ", "name of the library being versioned").default("@sliit-foss/automatic-versioning")
+ )
+ .option("-r, --root ", "root directory to use when executing the script")
+ .option("--skip-commit", "do not commit the incremented version")
+ .option("--tag-based", "run versioning based on git tags");
+
+[
+ new Option("--recursive", "recursively search for a matching commit prefix"),
+ new Option("--prerelease-tag ", "prerelease tag to use when running on a prerelease branch"),
+ new Option("--prerelease-branch ", "run prereleases on this branch"),
+ new Option(
+ "--ignore-prefixes ",
+ "comma separated list of commit prefixes to ignore when searching for a matching prefix"
+ )
+].forEach((option) => program.addOption(option.conflicts("tagBased")));
+
+const opts = program.parse().opts();
const defaultRootDir = "../../../../";
-let prereleaseTag,
- prereleaseBranch,
- ignorePrefixes = [];
-let name = "@sliit-foss/automatic-versioning";
-let rootDir = defaultRootDir;
-let noCommitEdit = false,
- noCommit = false,
- recursive = false;
-
-args.forEach((arg) => {
- if (arg.includes("--name=")) name = arg.replace("--name=", "");
- if (arg.includes("--rootDir=")) rootDir += arg.replace("--rootDir=", "");
- if (arg.includes("--no-commit-edit")) noCommitEdit = true;
- if (arg.includes("--no-commit")) noCommit = true;
- if (arg.includes("--recursive")) recursive = true;
- if (arg.includes("--prerelease-tag=")) prereleaseTag = arg.replace("--prerelease-tag=", "");
- if (arg.includes("--prerelease-branch=")) prereleaseBranch = arg.replace("--prerelease-branch=", "");
- if (arg.includes("--ignore-prefixes=")) ignorePrefixes = arg.replace("--ignore-prefixes=", "")?.split(",") ?? [];
-});
-
-console.log(`Running version bump for ${name}`.green);
-
-if (rootDir !== defaultRootDir) {
- const parentDir = path.resolve(__dirname, rootDir);
+opts.root ??= defaultRootDir;
+opts.ignorePrefixes = opts.ignorePrefixes?.split(",") ?? [];
+
+console.log(`Running versioning script for ${opts.name}`.green);
+
+if (opts.root !== defaultRootDir) {
+ const parentDir = path.resolve(__dirname, opts.root);
process.chdir(parentDir);
}
-if (args.includes("--tag-based")) {
- tagBasedRunner(name, noCommit);
+if (opts.tagBased) {
+ tagBasedRunner(opts.name, opts.skipCommit);
} else {
- defaultRunner(name, noCommit, noCommitEdit, recursive, prereleaseTag, prereleaseBranch, ignorePrefixes);
+ defaultRunner(
+ opts.name,
+ opts.skipCommit,
+ opts.recursive,
+ opts.prereleaseTag,
+ opts.prereleaseBranch,
+ opts.ignorePrefixes
+ );
}
diff --git a/packages/automatic-versioning/src/types/default.js b/packages/automatic-versioning/src/types/default.js
index 7c2facd..3f43dcd 100644
--- a/packages/automatic-versioning/src/types/default.js
+++ b/packages/automatic-versioning/src/types/default.js
@@ -19,7 +19,7 @@ const getCommitPrefix = async (recursive, ignorePrefixes, n = 1) => {
return getCommitPrefix(recursive, ignorePrefixes, n + 1);
};
-const runner = (name, noCommit, noCommitEdit, recursive = false, prereleaseTag, prereleaseBranch, ignorePrefixes) => {
+const runner = (name, noCommit, recursive = false, prereleaseTag, prereleaseBranch, ignorePrefixes) => {
run("git show --first-parent ./").then(async (diff) => {
if (diff) {
console.log(`Diff found, running versioning for ${name}`.green);
@@ -90,14 +90,10 @@ const runner = (name, noCommit, noCommitEdit, recursive = false, prereleaseTag,
}
});
} else {
- if (noCommitEdit) {
- console.log(`No bump found in commit message, skipping version bump`.yellow);
- } else {
- console.log(`No bump found in commit message, skipping version bump and editing commit message`.yellow);
- run(`git commit --amend -m "${commitMessage.replace(/--no-bump/g, "")}"`).then(() => {
- console.log("Successfully edited commit message".green);
- });
- }
+ console.log(`No bump found in commit message, skipping version bump and editing commit message`.yellow);
+ run(`git commit --amend -m "${commitMessage.replace(/--no-bump/g, "")}"`).then(() => {
+ console.log("Successfully edited commit message".green);
+ });
}
} else {
console.log(`No diff found, skipping version bump for ${name}`.yellow);
diff --git a/packages/automatic-versioning/src/types/index.js b/packages/automatic-versioning/src/types/index.js
new file mode 100644
index 0000000..707f669
--- /dev/null
+++ b/packages/automatic-versioning/src/types/index.js
@@ -0,0 +1,2 @@
+export { default as defaultRunner } from "./default";
+export { default as tagBasedRunner } from "./tag-based";
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 27dadd1..859ba59 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -78,6 +78,9 @@ importers:
'@colors/colors':
specifier: 1.5.0
version: 1.5.0
+ commander:
+ specifier: 11.1.0
+ version: 11.1.0
packages/clusterizer: {}
@@ -91,7 +94,7 @@ importers:
dependencies:
'@sliit-foss/module-logger':
specifier: 1.1.5
- version: link:../module-logger
+ version: 1.1.5
express-http-context:
specifier: 1.2.4
version: 1.2.4
@@ -100,7 +103,7 @@ importers:
dependencies:
'@sliit-foss/module-logger':
specifier: 1.1.5
- version: link:../module-logger
+ version: 1.1.5
packages/leaderboard:
dependencies:
@@ -128,7 +131,7 @@ importers:
dependencies:
'@sliit-foss/module-logger':
specifier: 1.1.5
- version: link:../module-logger
+ version: 1.1.5
axios:
specifier: 1.3.2
version: 1.3.2
@@ -158,7 +161,7 @@ importers:
version: 7.20.7
'@sliit-foss/functions':
specifier: 2.2.3
- version: link:../../packages/functions
+ version: 2.2.3
devDependencies:
'@babel/core':
specifier: 7.21.5
@@ -2890,6 +2893,21 @@ packages:
'@sinonjs/commons': 2.0.0
dev: false
+ /@sliit-foss/functions@2.2.3:
+ resolution: {integrity: sha512-SH4ymghdrpBFQj6h/TkfG+uO/NG180PT0P7a/MYyeNBu4YYbIjkE6jQJ76RaXAoMwZjtPHsKLmW8FT8OJL8DLQ==}
+ dependencies:
+ '@sliit-foss/module-logger': 1.1.5
+ express-http-context: 1.2.4
+ dev: false
+
+ /@sliit-foss/module-logger@1.1.5:
+ resolution: {integrity: sha512-bKpKi0Yp/ZDYP3yaZTT2zw2f2c49qIkCK5NLKE+qs4UctZtWc1cRSDZZVDP/QAEQ7UMeIECFKX5l+ig8obMvlQ==}
+ dependencies:
+ express-http-context: 1.2.4
+ winston: 3.8.2
+ winston-daily-rotate-file: 4.7.1(winston@3.8.2)
+ dev: false
+
/@tsconfig/node10@1.0.9:
resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==}
@@ -3689,6 +3707,11 @@ packages:
delayed-stream: 1.0.0
dev: false
+ /commander@11.1.0:
+ resolution: {integrity: sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==}
+ engines: {node: '>=16'}
+ dev: false
+
/compare-func@2.0.0:
resolution: {integrity: sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==}
dependencies: