This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

52 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const android_plugins_1 = require("../plugins/android-plugins");
const WarningAggregator = __importStar(require("../utils/warnings"));
exports.withVersion = config => {
return android_plugins_1.withAppBuildGradle(config, config => {
if (config.modResults.language === 'groovy') {
config.modResults.contents = setVersionCode(config, config.modResults.contents);
config.modResults.contents = setVersionName(config, config.modResults.contents);
}
else {
WarningAggregator.addWarningAndroid('android-version', `Cannot automatically configure app build.gradle if it's not groovy`);
}
return config;
});
};
function getVersionName(config) {
var _a;
return (_a = config.version) !== null && _a !== void 0 ? _a : null;
}
exports.getVersionName = getVersionName;
function setVersionName(config, buildGradle) {
const versionName = getVersionName(config);
if (versionName === null) {
return buildGradle;
}
const pattern = new RegExp(`versionName ".*"`);
return buildGradle.replace(pattern, `versionName "${versionName}"`);
}
exports.setVersionName = setVersionName;
function getVersionCode(config) {
var _a, _b;
return (_b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.versionCode) !== null && _b !== void 0 ? _b : null;
}
exports.getVersionCode = getVersionCode;
function setVersionCode(config, buildGradle) {
const versionCode = getVersionCode(config);
if (versionCode === null) {
return buildGradle;
}
const pattern = new RegExp(`versionCode.*`);
return buildGradle.replace(pattern, `versionCode ${versionCode}`);
}
exports.setVersionCode = setVersionCode;
//# sourceMappingURL=Version.js.map