ern-container-publisher-cocoapod-git
Version:
Electrode Native CocoaPod Git Container Publisher
86 lines • 5.9 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ern_core_1 = require("ern-core");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
class CocoaPodGitPublisher {
get name() {
return 'cocoapod-git';
}
get platforms() {
return ['ios'];
}
publish({ containerPath, containerVersion, url, platform, extra }) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
return __awaiter(this, void 0, void 0, function* () {
const workingGitDir = ern_core_1.createTmpDir();
const branch = (extra && extra.branch) || 'main';
const allowVersionOverwrite = (extra && extra.allowVersionOverwrite) || false;
const pathToXCFramework = path_1.default.join(containerPath, 'ElectrodeContainer.xcframework');
if (!url) {
throw new Error('url is required');
}
if (!fs_1.default.existsSync(pathToXCFramework)) {
throw new Error(`Couldn't find container xcframework in ${pathToXCFramework}`);
}
try {
ern_core_1.shell.pushd(workingGitDir);
const git = ern_core_1.gitCli();
const re = new RegExp(`refs/heads/${branch}`);
const remoteHeads = yield ern_core_1.gitCli().raw(['ls-remote', '--heads', url]);
ern_core_1.log.debug(`workingGitDir: ${workingGitDir}`);
if (re.test(remoteHeads)) {
ern_core_1.log.debug(`${branch} branch exists in remote. Reusing it.`);
ern_core_1.log.debug(`Running 'git clone ${url} . --single-branch --branch ${branch} --depth 1`);
yield ern_core_1.gitCli().clone(url, '.', ['--single-branch', '--branch', branch, '--depth', '1']);
}
else {
ern_core_1.log.debug(`${branch} branch does not exists in remote. Creating it.`);
ern_core_1.log.debug(`Running 'git clone ${url} . --depth 1`);
yield ern_core_1.gitCli().clone(url, '.', ['--depth', '1']);
yield git.checkoutLocalBranch(branch);
}
ern_core_1.shell.rm('-rf', path_1.default.join(workingGitDir, '*'));
ern_core_1.shell.cp('-Rf', path_1.default.join(containerPath, 'ElectrodeContainer.xcframework'), workingGitDir);
yield ern_core_1.mustacheUtils.mustacheRenderToOutputFileUsingTemplateFile(path_1.default.join(__dirname, 'ElectrodeContainer.podspec.mustache'), {
containerVersion,
url,
name: (_b = (_a = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "ElectrodeContainer",
summary: (_d = (_c = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _c === void 0 ? void 0 : _c.summary) !== null && _d !== void 0 ? _d : "Electrode Native Container",
homepage: (_f = (_e = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _e === void 0 ? void 0 : _e.homepage) !== null && _f !== void 0 ? _f : "https://native.electrode.io",
license: (_h = (_g = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _g === void 0 ? void 0 : _g.license) !== null && _h !== void 0 ? _h : "MIT",
author: (_k = (_j = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _j === void 0 ? void 0 : _j.author) !== null && _k !== void 0 ? _k : "Electrode Native Platform",
swift_version: (_m = (_l = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _l === void 0 ? void 0 : _l.swift_version) !== null && _m !== void 0 ? _m : "5.0",
deployment_target: (_p = (_o = extra === null || extra === void 0 ? void 0 : extra.podspec) === null || _o === void 0 ? void 0 : _o.deployment_target) !== null && _p !== void 0 ? _p : "11.0"
}, path_1.default.join(workingGitDir, 'ElectrodeContainer.podspec'));
yield git.add('./*');
yield git.commit(`Container v${containerVersion}`);
const tagsOptions = allowVersionOverwrite ? ['-f'] : [];
yield git.tag([`v${containerVersion}`, ...tagsOptions]);
yield git.push('origin', branch);
yield git.raw(['push', 'origin', '--tags', ...tagsOptions]);
ern_core_1.log.info('[=== Completed publication of the Container ===]');
ern_core_1.log.info(`[Publication url : ${url}]`);
ern_core_1.log.info(`[Git Branch: ${branch}]`);
ern_core_1.log.info(`[Git Tag: v${containerVersion}]`);
}
finally {
ern_core_1.shell.popd();
}
});
}
}
exports.default = CocoaPodGitPublisher;
//# sourceMappingURL=index.js.map
;