Skip to content

Commit

Permalink
Make update version script more general
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotes committed Nov 13, 2024
1 parent 40989e3 commit a9f0498
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 151 deletions.
140 changes: 0 additions & 140 deletions packages/typir-langium/package-lock.json

This file was deleted.

31 changes: 20 additions & 11 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@ import fs from 'fs-extra';
import path from 'path';

async function runUpdate() {
const langiumPath = getPath('typir', true);
const langiumPackage = await fs.readJson(langiumPath);
const version = langiumPackage.version;
const versions = await Promise.all([
getVersionOf('typir'),
getVersionOf('typir-langium'),
]);
await Promise.all([
replaceAll('typir', true, version),
replaceAll('typir-langium', true, version),
replaceAll('ox', false, version),
replaceAll('lox', false, version),
replaceAll('typir', true, versions),
replaceAll('typir-langium', true, versions),
replaceAll('ox', false, versions),
replaceAll('lox', false, versions),
]);
}

async function replaceAll(project, pkg, version) {
async function replaceAll(project, pkg, versions) {
const path = getPath(project, pkg);
let content = await fs.readFile(path, 'utf-8');
content = content
.replace(/(?<="typir": "[~\^]?)\d+\.\d+\.\d+/g, version)
.replace(/(?<="typir-langium": "[~\^]?)\d+\.\d+\.\d+/g, version)
versions.forEach(([project, version]) => {
const regex = new RegExp("(?<=\"" + project + "\": \"[~\\^]?)\\d+\\.\\d+\\.\\d+", "g");
console.log(regex);
content = content.replace(regex, version);
});
await fs.writeFile(path, content);
}

function getPath(project, pkg) {
return path.join(pkg ? 'packages' : 'examples', project, 'package.json');
}

async function getVersionOf(project) {
const typirPath = getPath(project, true);
const typirPackage = await fs.readJson(typirPath);
return [project, typirPackage.version];
}

runUpdate();

0 comments on commit a9f0498

Please sign in to comment.