Skip to content

Commit

Permalink
add a command for bumping WebOn-versions (#9)
Browse files Browse the repository at this point in the history
* add a command for bumping WebOn-versions

* improve error logs
  • Loading branch information
nomo-app authored Feb 21, 2024
1 parent 3b9ff6f commit e433b4a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ Run `nomo-webon-cli --help` to see a list of available commands:
Options:
-v, --version output the version number
Commands:
login Log into a ZENCON account
build <assetDir> Build a WebOn archive
deploy <archive> <deployTarget> Deploy a WebOn archive
init <publicDir> Create a nomo_manifest.json
init <publicDir> Create a cli-config and/or a manifest.
bumpVersion <manifest> Increases the version of a WebOn.
```
46 changes: 46 additions & 0 deletions src/bump-version/bump-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { resolve } from "path";
import { readFileSync, existsSync, writeFileSync } from "fs";
import { logFatal } from "../util/util";
import { NomoManifest } from "../init/interface";
import { _isValidSemanticVersion } from "../util/validate-manifest";

export async function bumpVersion(args: {
manifestPath: string;
}): Promise<void> {
const manifestPath = resolve(args.manifestPath);
if (!existsSync(manifestPath)) {
logFatal(`Manifest does not exist: ${manifestPath}`);
}

const nomoManifestContent = readFileSync(manifestPath, "utf-8");
const nomoManifest: NomoManifest = JSON.parse(nomoManifestContent);
const webonVersion = nomoManifest.webon_version;
if (!webonVersion) {
logFatal(`webon_version is missing in ${manifestPath}`);
}
if (!_isValidSemanticVersion({ version: webonVersion })) {
logFatal(
`webon_version ${webonVersion} in ${manifestPath} does not comply with semantic versioning regexp`
);
}

const versionParts = webonVersion.split(".");
const major = versionParts[0];
const minor = versionParts[1];
const patch = versionParts[2];
if (!major || !minor || !patch) {
logFatal(
`webon_version ${webonVersion} in ${manifestPath} does not contain major, minor or patch`
);
}
const newPatch = parseInt(patch) + 1;
const newVersion = `${major}.${minor}.${newPatch}`;
nomoManifest.webon_version = newVersion;

const newManifestContent = JSON.stringify(nomoManifest, null, 2);

writeFileSync(manifestPath, newManifestContent);
console.log(
`Bumped webon_version to ${newVersion}. Wrote to ${manifestPath}`
);
}
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import commander from "commander";
import { extractVersion } from "./util/extract-version";
import { buildWebOn } from "./build-webon/build-webon";
import { deployWebOn } from "./deploy-webon/deploy-webon";
import { bumpVersion } from "./bump-version/bump-version";
import { init } from "./init/init";

process.on("unhandledRejection", (error) => {
Expand Down Expand Up @@ -32,6 +33,19 @@ function commanderInitWebOn() {
});
}

function commanderBumpVersion() {
commander
.command("bumpVersion <manifest>")
.description(
"Increases the version of a WebOn."
)
.action((manifest) => {
runAsyncCommand(async () => {
await bumpVersion({ manifestPath: manifest });
});
});
}

function commanderDeployWebOn() {
commander
.command("deploy <archive> <deployTarget>")
Expand Down Expand Up @@ -62,6 +76,7 @@ export function run(process: NodeJS.Process, cliBinDir: string): void {
commanderBuildWebOn();
commanderDeployWebOn();
commanderInitWebOn();
commanderBumpVersion();
commander
.version(extractVersion({ cliBinDir }), "-v, --version")
.parse(process.argv);
Expand Down
2 changes: 1 addition & 1 deletion src/util/validate-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function validateManifest({
}
}

function _isValidSemanticVersion({ version }: { version: string }): boolean {
export function _isValidSemanticVersion({ version }: { version: string }): boolean {
const pattern = /^(\d+)\.(\d+)\.(\d+)$/;
const regex = new RegExp(pattern);
return regex.test(version);
Expand Down

0 comments on commit e433b4a

Please sign in to comment.