ecus-cli
Version:
A Command line interface of ECUS
58 lines (57 loc) • 2.62 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 });
exports.writeExpoPlistAsync = exports.readExpoPlistAsync = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const zx_1 = require("zx");
const plist_1 = __importDefault(require("@expo/plist"));
function readExpoPlistAsync(projectDir) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const expoPlistPath = config_plugins_1.IOSConfig.Paths.getExpoPlistPath(projectDir);
return ((_a = (yield readPlistAsync(expoPlistPath))) !== null && _a !== void 0 ? _a : {});
});
}
exports.readExpoPlistAsync = readExpoPlistAsync;
function writeExpoPlistAsync(projectDir, expoPlist) {
return __awaiter(this, void 0, void 0, function* () {
const expoPlistPath = config_plugins_1.IOSConfig.Paths.getExpoPlistPath(projectDir);
yield writePlistAsync(expoPlistPath, expoPlist);
});
}
exports.writeExpoPlistAsync = writeExpoPlistAsync;
function readPlistAsync(plistPath) {
return __awaiter(this, void 0, void 0, function* () {
if (yield zx_1.fs.pathExists(plistPath)) {
const expoPlistContent = yield zx_1.fs.readFile(plistPath, "utf8");
try {
return plist_1.default.parse(expoPlistContent);
}
catch (err) {
err.message = `Failed to parse ${plistPath}. ${err.message}`;
throw err;
}
}
else {
return null;
}
});
}
function writePlistAsync(plistPath, plistObject) {
return __awaiter(this, void 0, void 0, function* () {
const contents = plist_1.default.build(plistObject);
yield zx_1.fs.mkdirp(zx_1.path.dirname(plistPath));
yield zx_1.fs.writeFile(plistPath, contents);
});
}