UNPKG

ern-container-publisher-cocoapod-spec

Version:

Electrode Native CocoaPod Spec Container Publisher

77 lines 4.37 kB
"use strict"; 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 CocoaPodSpecPublisher { get name() { return 'cocoapod-spec'; } get platforms() { return ['ios']; } publish({ containerPath, containerVersion, url, platform, extra, }) { return __awaiter(this, void 0, void 0, function* () { const workingGitDir = ern_core_1.createTmpDir(); const branch = (extra && extra.branch) || 'master'; const allowVersionOverwrite = (extra && extra.allowVersionOverwrite) || false; if (!url) { throw new Error('url is required'); } if (!(extra === null || extra === void 0 ? void 0 : extra.sourceRepoUrl)) { throw new Error('extra.sourceRepoUrl is required'); } 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); } const versionDir = path_1.default.join(workingGitDir, 'ElectrodeContainer', containerVersion); if (fs_1.default.existsSync(versionDir) && !allowVersionOverwrite) { throw new Error(`Container version already exists`); } ern_core_1.shell.mkdir('-p', versionDir); yield ern_core_1.mustacheUtils.mustacheRenderToOutputFileUsingTemplateFile(path_1.default.join(__dirname, 'ElectrodeContainer.podspec.mustache'), { containerVersion, url: extra.sourceRepoUrl }, path_1.default.join(versionDir, '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 = CocoaPodSpecPublisher; //# sourceMappingURL=index.js.map