Skip to content

Commit

Permalink
Merge pull request #145 from castore-dev/fix-bug-in-set-packages-vers…
Browse files Browse the repository at this point in the history
…ions-script

fix: bug in setPackagesVersions script
  • Loading branch information
ThomasAribart authored Sep 1, 2023
2 parents be8529d + 45a679d commit 4e5b563
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions scripts/setPackagesVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@ import { join } from 'path';

const newVersionTag = process.argv[2];

const semanticVersioningRegex =
if (newVersionTag === undefined) {
throw new Error('Please provide a version tag');
}

const PREFIXED_SEM_VER_REGEX =
/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;

const prefixedSemVerMatches = newVersionTag.match(PREFIXED_SEM_VER_REGEX);

if (
newVersionTag === undefined ||
!semanticVersioningRegex.test(newVersionTag)
!PREFIXED_SEM_VER_REGEX.test(newVersionTag) ||
prefixedSemVerMatches === null
) {
throw new Error('Invalid version');
throw new Error(
'Please provide a version tag that follows semantic versioning prefixed with v (e.g. "v1.2.3")',
);
}

const NEW_VERSION = newVersionTag.slice(1);
const [, NEW_SEM_VER_MAJOR, NEW_SEM_VER_MINOR, NEW_SEM_VER_PATCH] = [
...prefixedSemVerMatches,
] as [string, string, string, string];

const [VERSION_MAJOR] = newVersionTag.match(semanticVersioningRegex) as [
string,
];
const NEW_SEM_VER = [
NEW_SEM_VER_MAJOR,
NEW_SEM_VER_MINOR,
NEW_SEM_VER_PATCH,
].join('.');

type PackageJson = {
version?: string;
Expand All @@ -36,13 +48,13 @@ packagesNames.forEach(packageName => {
readFileSync(packageJsonPath).toString(),
) as PackageJson;

packageJson.version = NEW_VERSION;
packageJson.version = NEW_SEM_VER;

const dependencies = packageJson.dependencies;
if (dependencies !== undefined) {
Object.keys(dependencies).forEach(dependencyName => {
if (dependencyName.startsWith('@castore/')) {
dependencies[dependencyName] = NEW_VERSION;
dependencies[dependencyName] = NEW_SEM_VER;
}
});
}
Expand All @@ -51,7 +63,7 @@ packagesNames.forEach(packageName => {
if (peerDependencies !== undefined) {
Object.keys(peerDependencies).forEach(dependencyName => {
if (dependencyName.startsWith('@castore/')) {
peerDependencies[dependencyName] = `^${VERSION_MAJOR}.0.0`;
peerDependencies[dependencyName] = `^${NEW_SEM_VER_MAJOR}.0.0`;
}
});
}
Expand Down

0 comments on commit 4e5b563

Please sign in to comment.