'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBlankAsync = exports.cleanBackupAsync = exports.modifyAsync = undefined; /** * @param plistName base filename of property list. if no extension, assumes .plist */ let modifyAsync = (() => { var _ref = _asyncToGenerator(function* (plistPath, plistName, transform) { let plistFilename = _getNormalizedPlistFilename(plistName); let configPlistName = _path.default.join(plistPath, plistFilename); let configFilename = _path.default.join(plistPath, `${plistName}.json`); // grab original plist as json object let config; if (process.platform === 'darwin') { yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('plutil', ['-convert', 'json', configPlistName, '-o', configFilename]); let configContents = yield (_fsExtra || _load_fsExtra()).default.readFile(configFilename, 'utf8'); try { config = JSON.parse(configContents); } catch (e) { console.log(`Error parsing ${configFilename}`, e); console.log('The erroneous file contents was:', configContents); config = {}; } } else { config = (_plist || _load_plist()).default.parse((_fsExtra || _load_fsExtra()).default.readFileSync(configPlistName, 'utf8')); } // apply transformation config = transform(config); // back up old plist and swap in modified one yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/cp', [configPlistName, `${configPlistName}.bak`]); yield (_fsExtra || _load_fsExtra()).default.writeFile(configFilename, JSON.stringify(config)); if (process.platform === 'darwin') { yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('plutil', ['-convert', 'xml1', configFilename, '-o', configPlistName]); } else { yield (_fsExtra || _load_fsExtra()).default.writeFile(configPlistName, (_plist || _load_plist()).default.build(config)); } return config; }); return function modifyAsync(_x, _x2, _x3) { return _ref.apply(this, arguments); }; })(); let createBlankAsync = (() => { var _ref2 = _asyncToGenerator(function* (plistPath, plistName) { // write empty json file const emptyConfig = {}; const tmpConfigFile = _path.default.join(plistPath, `${plistName}.json`); yield (_fsExtra || _load_fsExtra()).default.writeFile(tmpConfigFile, JSON.stringify(emptyConfig)); // convert to plist let plistFilename = _getNormalizedPlistFilename(plistName); let configPlistName = _path.default.join(plistPath, plistFilename); if (process.platform === 'darwin') { yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('plutil', ['-convert', 'xml1', tmpConfigFile, '-o', configPlistName]); } else { yield (_fsExtra || _load_fsExtra()).default.writeFile(configPlistName, JSON.stringify((_plist || _load_plist()).default.build(emptyConfig))); } // remove tmp json file yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/rm', [tmpConfigFile]); }); return function createBlankAsync(_x4, _x5) { return _ref2.apply(this, arguments); }; })(); let cleanBackupAsync = (() => { var _ref3 = _asyncToGenerator(function* (plistPath, plistName, restoreOriginal = true) { let plistFilename = _getNormalizedPlistFilename(plistName); let configPlistName = _path.default.join(plistPath, plistFilename); let configFilename = _path.default.join(plistPath, `${plistName}.json`); if (restoreOriginal) { yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/cp', [`${configPlistName}.bak`, configPlistName]); } yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/rm', [`${configPlistName}.bak`]); yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/rm', [configFilename]); }); return function cleanBackupAsync(_x6, _x7) { return _ref3.apply(this, arguments); }; })(); var _fsExtra; function _load_fsExtra() { return _fsExtra = _interopRequireDefault(require('fs-extra')); } var _path = _interopRequireDefault(require('path')); var _plist; function _load_plist() { return _plist = _interopRequireDefault(require('plist')); } var _ExponentTools; function _load_ExponentTools() { return _ExponentTools = require('./ExponentTools'); } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } function _getNormalizedPlistFilename(plistName) { let plistFilename; if (plistName.indexOf('.') !== -1) { plistFilename = plistName; } else { plistFilename = `${plistName}.plist`; } return plistFilename; }exports.modifyAsync = modifyAsync; exports.cleanBackupAsync = cleanBackupAsync; exports.createBlankAsync = createBlankAsync; //# sourceMappingURL=../__sourcemaps__/detach/IosPlist.js.map