Skip to content

Commit 83fdac8

Browse files
committed
feat: add custom platform support
- Added support for custom platforms. - Implemented CustomUpdater class. - Added bump_targets config option. - Improved error handling. - Updated documentation.
1 parent 51d169b commit 83fdac8

2 files changed

Lines changed: 146 additions & 9 deletions

File tree

dist/index.js

Lines changed: 145 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Taj <[email protected]>
77
* Homepage: https://github.com/taj54/universal-version-bump#readme
88
* License: MIT
9-
* Generated on Fri, 29 Aug 2025 17:28:44 GMT
9+
* Generated on Fri, 29 Aug 2025 18:37:37 GMT
1010
*/
1111
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
1212
/******/ var __webpack_modules__ = ({
@@ -32667,12 +32667,13 @@ var __importStar = (this && this.__importStar) || (function () {
3266732667
};
3266832668
})();
3266932669
Object.defineProperty(exports, "__esModule", ({ value: true }));
32670-
exports.TARGET_PATH = exports.GIT_TAG = exports.TARGET_PLATFORM = exports.RELEASE_TYPE = void 0;
32670+
exports.BUMP_TARGETS = exports.TARGET_PATH = exports.GIT_TAG = exports.TARGET_PLATFORM = exports.RELEASE_TYPE = void 0;
3267132671
const core = __importStar(__nccwpck_require__(9999));
3267232672
exports.RELEASE_TYPE = (core.getInput('release_type') || 'patch');
3267332673
exports.TARGET_PLATFORM = core.getInput('target_platform');
3267432674
exports.GIT_TAG = core.getInput('git_tag') === 'true';
3267532675
exports.TARGET_PATH = core.getInput('target_path') || '.';
32676+
exports.BUMP_TARGETS = JSON.parse(core.getInput('bump_targets') || '[]');
3267632677

3267732678

3267832679
/***/ }),
@@ -32801,7 +32802,8 @@ async function run() {
3280132802
const { updaterService, gitService, changelogService } = await initializeServices();
3280232803
const platform = updaterService.getPlatform(targetPlatform);
3280332804
core.info(`Detected platform: ${platform}`);
32804-
const version = updaterService.updateVersion(platform, releaseType);
32805+
const bumpTargets = (0, utils_1.safeParseJSON)(config_1.BUMP_TARGETS);
32806+
const version = updaterService.updateVersion(platform, releaseType, bumpTargets);
3280532807
core.setOutput('new_version', version);
3280632808
// Generate and update changelog
3280732809
const latestTag = await gitService.getLatestTag();
@@ -33266,6 +33268,7 @@ __exportStar(__nccwpck_require__(5417), exports);
3326633268
Object.defineProperty(exports, "__esModule", ({ value: true }));
3326733269
exports.UpdaterService = void 0;
3326833270
const errors_1 = __nccwpck_require__(4830);
33271+
const customUpdater_1 = __nccwpck_require__(5432);
3326933272
/**
3327033273
* Service for managing version updates.
3327133274
*/
@@ -33302,17 +33305,122 @@ class UpdaterService {
3330233305
* @param releaseType The type of release (major, minor, patch).
3330333306
* @returns The new version string.
3330433307
*/
33305-
updateVersion(platform, releaseType) {
33306-
const updater = this.updaterRegistry.getUpdater(platform);
33307-
if (!updater) {
33308-
throw new errors_1.VersionBumpError(`No updater found for platform: ${platform}`);
33308+
updateVersion(platform, releaseType, bumpTargets = []) {
33309+
if (platform === 'custom') {
33310+
if (bumpTargets.length === 0) {
33311+
throw new errors_1.VersionBumpError('No bump_targets provided for custom platform.');
33312+
}
33313+
let lastBumpedVersion = '';
33314+
for (const target of bumpTargets) {
33315+
const customUpdater = new customUpdater_1.CustomUpdater(target.path, target.variable);
33316+
lastBumpedVersion = customUpdater.bumpVersion(releaseType);
33317+
}
33318+
return lastBumpedVersion;
33319+
}
33320+
else {
33321+
const updater = this.updaterRegistry.getUpdater(platform);
33322+
if (!updater) {
33323+
throw new errors_1.VersionBumpError(`No updater found for platform: ${platform}`);
33324+
}
33325+
return updater.bumpVersion(releaseType);
3330933326
}
33310-
return updater.bumpVersion(releaseType);
3331133327
}
3331233328
}
3331333329
exports.UpdaterService = UpdaterService;
3331433330

3331533331

33332+
/***/ }),
33333+
33334+
/***/ 5432:
33335+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
33336+
33337+
"use strict";
33338+
33339+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
33340+
if (k2 === undefined) k2 = k;
33341+
var desc = Object.getOwnPropertyDescriptor(m, k);
33342+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
33343+
desc = { enumerable: true, get: function() { return m[k]; } };
33344+
}
33345+
Object.defineProperty(o, k2, desc);
33346+
}) : (function(o, m, k, k2) {
33347+
if (k2 === undefined) k2 = k;
33348+
o[k2] = m[k];
33349+
}));
33350+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
33351+
Object.defineProperty(o, "default", { enumerable: true, value: v });
33352+
}) : function(o, v) {
33353+
o["default"] = v;
33354+
});
33355+
var __importStar = (this && this.__importStar) || (function () {
33356+
var ownKeys = function(o) {
33357+
ownKeys = Object.getOwnPropertyNames || function (o) {
33358+
var ar = [];
33359+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33360+
return ar;
33361+
};
33362+
return ownKeys(o);
33363+
};
33364+
return function (mod) {
33365+
if (mod && mod.__esModule) return mod;
33366+
var result = {};
33367+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33368+
__setModuleDefault(result, mod);
33369+
return result;
33370+
};
33371+
})();
33372+
Object.defineProperty(exports, "__esModule", ({ value: true }));
33373+
exports.CustomUpdater = void 0;
33374+
const core = __importStar(__nccwpck_require__(9999));
33375+
const utils_1 = __nccwpck_require__(9499);
33376+
class CustomUpdater {
33377+
constructor(filePath, variableName) {
33378+
this.platform = 'custom';
33379+
this.currentVersion = null;
33380+
this.filePath = filePath;
33381+
this.variableName = variableName;
33382+
this.fileHandler = new utils_1.FileHandler();
33383+
this.manifestParser = new utils_1.ManifestParser(this.fileHandler);
33384+
}
33385+
canHandle() {
33386+
// This updater is explicitly called, so it can always handle if constructed.
33387+
return true;
33388+
}
33389+
getCurrentVersion() {
33390+
if (this.currentVersion) {
33391+
return this.currentVersion;
33392+
}
33393+
try {
33394+
// eslint-disable-next-line no-useless-escape
33395+
const regex = new RegExp(`(${this.variableName}\s*=\s*['"]?)([\\d.]+)(['"]?)`);
33396+
this.currentVersion = this.manifestParser.getVersion(this.filePath, 'regex', {
33397+
regex: regex,
33398+
});
33399+
return this.currentVersion;
33400+
}
33401+
catch (error) {
33402+
core.debug(`Could not read or parse version from ${this.filePath}: ${error}`);
33403+
}
33404+
return null;
33405+
}
33406+
bumpVersion(releaseType) {
33407+
const oldVersion = this.getCurrentVersion();
33408+
if (!oldVersion) {
33409+
throw new Error(`Could not find current version for variable '${this.variableName}' in file '${this.filePath}'`);
33410+
}
33411+
const newVersion = (0, utils_1.calculateNextVersion)(oldVersion, releaseType);
33412+
// eslint-disable-next-line no-useless-escape
33413+
const regexReplace = new RegExp(`(${this.variableName}\s*=\s*['"]?)${oldVersion}(['"]?)`);
33414+
this.manifestParser.updateVersion(this.filePath, newVersion, 'regex', {
33415+
regexReplace: regexReplace,
33416+
});
33417+
core.info(`Bumped ${this.variableName} in ${this.filePath} from ${oldVersion} to ${newVersion}`);
33418+
return newVersion;
33419+
}
33420+
}
33421+
exports.CustomUpdater = CustomUpdater;
33422+
33423+
3331633424
/***/ }),
3331733425

3331833426
/***/ 553:
@@ -33853,6 +33961,35 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3385333961
__exportStar(__nccwpck_require__(2431), exports);
3385433962
__exportStar(__nccwpck_require__(1013), exports);
3385533963
__exportStar(__nccwpck_require__(2521), exports);
33964+
__exportStar(__nccwpck_require__(8396), exports);
33965+
33966+
33967+
/***/ }),
33968+
33969+
/***/ 8396:
33970+
/***/ ((__unused_webpack_module, exports) => {
33971+
33972+
"use strict";
33973+
33974+
Object.defineProperty(exports, "__esModule", ({ value: true }));
33975+
exports.safeParseJSON = safeParseJSON;
33976+
/**
33977+
* Safely parses a JSON string.
33978+
* Returns null (or a fallback) if parsing fails or input is invalid.
33979+
*/
33980+
/* eslint-disable @typescript-eslint/no-explicit-any */
33981+
function safeParseJSON(str) {
33982+
try {
33983+
if (!str || typeof str !== 'string' || str.trim() === '') {
33984+
return undefined;
33985+
}
33986+
return JSON.parse(str);
33987+
}
33988+
catch (e) {
33989+
console.error('Invalid JSON:', e);
33990+
return undefined;
33991+
}
33992+
}
3385633993

3385733994

3385833995
/***/ }),

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)