"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.bumpVersion = bumpVersion;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const child_process_1 = require("child_process");
async function bumpVersion(type, preTag = 'beta') {
const rootPath = path.resolve(__dirname, '../../../..');
const packageJsonPath = path.join(rootPath, 'package.json');
const cargoTomlPath = path.join(rootPath, 'Cargo.toml');
const projectVersionPath = path.join(rootPath, 'project-version.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const currentVersion = packageJson.version;
const versionMatch = currentVersion.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
if (!versionMatch) {
throw new Error(`Invalid version format: ${currentVersion}`);
}
let [, major, minor, patch, pre] = versionMatch;
let majorNum = parseInt(major);
let minorNum = parseInt(minor);
let patchNum = parseInt(patch);
let newVersion;
let channel = 'stable';
switch (type) {
case 'major':
majorNum++;
minorNum = 0;
patchNum = 0;
newVersion = `${majorNum}.${minorNum}.${patchNum}`;
break;
case 'minor':
minorNum++;
patchNum = 0;
newVersion = `${majorNum}.${minorNum}.${patchNum}`;
break;
case 'patch':
patchNum++;
newVersion = `${majorNum}.${minorNum}.${patchNum}`;
break;
case 'pre':
const preVersion = pre ? parseInt(pre.split('.')[1] || '0') + 1 : 0;
newVersion = `${majorNum}.${minorNum}.${patchNum}-${preTag}.${preVersion}`;
channel = preTag;
break;
}
let commit;
try {
commit = (0, child_process_1.execSync)('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
}
catch (error) {
console.warn('⚠️ Could not get git commit hash');
}
packageJson.version = newVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
console.log(`✅ Updated package.json to ${newVersion}`);
let cargoToml = fs.readFileSync(cargoTomlPath, 'utf-8');
cargoToml = cargoToml.replace(/version = "[\d\.]+-?[a-z\.]*\d*"/, `version = "${newVersion}"`);
fs.writeFileSync(cargoTomlPath, cargoToml);
console.log(`✅ Updated Cargo.toml to ${newVersion}`);
const projectVersion = {
version: newVersion,
channel,
build: 1, commit
};
fs.writeFileSync(projectVersionPath, JSON.stringify(projectVersion, null, 2) + '\n');
console.log(`✅ Updated project-version.json to ${newVersion}`);
const wixFilePath = path.join(rootPath, 'installer', 'windows', 'devalang.wxs');
if (fs.existsSync(wixFilePath)) {
try {
let wixContent = fs.readFileSync(wixFilePath, 'utf-8');
wixContent = wixContent.replace(/<\?define ProductVersion="[\d\.]+\-?[a-z\.]*\d*" \?>/, `<` + `?define ProductVersion="${newVersion}" ?` + `>`);
fs.writeFileSync(wixFilePath, wixContent);
console.log(`✅ Updated installer/windows/devalang.wxs to ${newVersion}`);
}
catch (error) {
console.warn('⚠️ Could not update installer/windows/devalang.wxs:', error);
}
}
else {
console.warn('⚠️ installer/windows/devalang.wxs not found, skipping');
}
return newVersion;
}