ern-container-publisher-fs
Version:
Electrode Native File System Container Publisher
59 lines • 2.95 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(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 fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
class FsPublisher {
get name() {
return 'fs';
}
get platforms() {
return ['android', 'ios'];
}
publish({ containerPath, containerVersion, url, platform }) {
return __awaiter(this, void 0, void 0, function* () {
if (!url) {
throw new Error('url parameter is required');
}
if (url && fs_1.default.existsSync(url)) {
if (fs_1.default.readdirSync(url).length > 0) {
throw new Error(`${url} directory exists and is not empty.
Publication directory should either not exist (it will be created) or should be empty.`);
}
}
ern_core_1.shell.mkdir('-p', url);
ern_core_1.shell.cp('-Rf', path_1.default.join(containerPath, '{.*,*}'), url);
if (platform === 'ios') {
this.patchContainerInfoPlistWithVersion({ containerPath: url, containerVersion });
}
ern_core_1.log.info('[=== Completed publication of the Container ===]');
ern_core_1.log.info(`[Path : ${url}]`);
});
}
/**
* [iOS Specific]
* Patch ElectrodeContainer Info.plist to update CFBundleShortVersionString
* with the Container version being published
*/
patchContainerInfoPlistWithVersion({ containerPath, containerVersion }) {
const infoPlistPath = path_1.default.join(containerPath, 'ElectrodeContainer', 'Info.plist');
if (fs_1.default.existsSync(infoPlistPath)) {
const infoPlist = fs_1.default.readFileSync(infoPlistPath).toString();
const patchedInfoPlist = infoPlist.replace(new RegExp('<key>CFBundleShortVersionString<\/key>\\n\\t<string>.+<\/string>'), `<key>CFBundleShortVersionString</key>\n\t<string>${containerVersion.replace('-raw', '')}</string>`);
fs_1.default.writeFileSync(infoPlistPath, patchedInfoPlist);
}
}
}
exports.default = FsPublisher;
//# sourceMappingURL=index.js.map