Skip to content

Commit

Permalink
add dev version mark
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Apr 11, 2024
1 parent 8980501 commit 935ae0d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A Node.js CLI tool designed to manage project configurations and versions effici

- Interactive CLI for easy management of project settings.
- Supports updating project metadata such as name, description, and version.
- Automated version management including patch, minor, and major updates.
- Automated version management including dev, patch, minor, and major updates.
- Git integration for committing changes, tagging versions, and pushing updates.

## Getting Started
Expand All @@ -32,7 +32,7 @@ cinnabar-meta
#### Updating the project version

- Select `Update version`.
- Choose the version update type (patch, minor, major).
- Choose the version update type (dev, patch, minor, major).
- Confirm update (and, if necessary, commit and push).

## Contributing
Expand Down
3 changes: 3 additions & 0 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function getCinnabarData(folderPath) {
} finally {
if (cinnabarData.version == null) {
cinnabarData.version = {
dev: 0,
major: 0,
minor: 0,
patch: 0,
Expand Down Expand Up @@ -78,6 +79,7 @@ async function getPackageJson(folderPath) {
},
},
version: {
dev: 0,
major: versionSplitted[0],
minor: versionSplitted[1],
patch: versionSplitted[2],
Expand Down Expand Up @@ -106,6 +108,7 @@ async function getVersionJson(folderPath) {
description: data.description ?? versionJsonData.description ?? "app",
name: data.name ?? "app",
version: {
dev: 0,
major: data.major ?? 0,
minor: data.minor ?? 0,
patch: data.patch ?? 0,
Expand Down
91 changes: 71 additions & 20 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,50 @@ export function getFullVersionText(cinnabarData) {
/**
* Increments the specified version part and updates the version object.
* @param {object} version - The version object from cinnabar.json.
* @param {string} type - The type of version to increment ('major', 'minor', 'patch').
* @param {string} type - The type of version to increment ('major', 'minor', 'patch', 'dev').
* @returns {string} The new version string.
*/
function incrementVersion(version, type) {
let { major, minor, patch, revision } = version;
let { dev, major, minor, patch, revision } = version;
revision++;

switch (type) {
case "dev-major":
case "major":
major++;
minor = 0;
patch = 0;
dev = type == "dev-major" ? 1 : 0;
break;
case "dev-minor":
case "minor":
minor++;
patch = 0;
dev = type == "dev-minor" ? 1 : 0;
break;
case "dev-patch":
case "patch":
patch++;
dev = type == "dev-patch" ? 1 : 0;
break;
case "dev":
if (!dev) {
dev = 0;
}
dev++;
break;
case "release-dev":
dev = 0;
break;
}

return {
dev,
major,
minor,
patch,
revision,
text: `${major}.${minor}.${patch}`,
text: `${major}.${minor}.${patch}${dev ? "-dev." + dev : ""}`,
timestamp: Math.round(Date.now() / 1000),
};
}
Expand All @@ -59,24 +75,59 @@ function incrementVersion(version, type) {
* @param {string} folderPath - The path to the folder containing the files.
*/
export async function updateVersion(cinnabarData, folderPath) {
const { major, minor, patch } = cinnabarData.version;
const currentVersionText = `${major}.${minor}.${patch}`;
const { dev, major, minor, patch } = cinnabarData.version;
const currentVersionText = `${major}.${minor}.${patch}${dev ? "-dev." + dev : ""}`;

const versionChoices = [{ name: "Back", value: "back" }];

if (dev && dev > 0) {
versionChoices.push(
...[
{
name: `Update dev (${currentVersionText} -> ${major}.${minor}.${patch}-dev.${(dev ?? 0) + 1})`,
value: "dev",
},
{
name: `Release dev (${currentVersionText} -> ${major}.${minor}.${patch})`,
value: "release-dev",
},
],
);
} else {
versionChoices.push(
...[
{
name: `Start dev patch (${currentVersionText} -> ${major}.${minor}.${patch + 1}-dev.1)`,
value: "dev-patch",
},
{
name: `Start dev minor (${currentVersionText} -> ${major}.${minor + 1}.0-dev.1)`,
value: "dev-minor",
},
{
name: `Start dev major (${currentVersionText} -> ${major + 1}.0.0-dev.1)`,
value: "dev-major",
},
],
);
}

const versionChoices = [
{ name: "Back", value: "back" },
{
name: `Update patch (${currentVersionText} -> ${major}.${minor}.${patch + 1})`,
value: "patch",
},
{
name: `Update minor (${currentVersionText} -> ${major}.${minor + 1}.0)`,
value: "minor",
},
{
name: `Update major (${currentVersionText} -> ${major + 1}.0.0)`,
value: "major",
},
];
versionChoices.push(
...[
{
name: `Update patch (${currentVersionText} -> ${major}.${minor}.${patch + 1})`,
value: "patch",
},
{
name: `Update minor (${currentVersionText} -> ${major}.${minor + 1}.0)`,
value: "minor",
},
{
name: `Update major (${currentVersionText} -> ${major + 1}.0.0)`,
value: "major",
},
],
);

const { versionType } = await inquirer.prompt({
choices: versionChoices,
Expand Down

0 comments on commit 935ae0d

Please sign in to comment.