react-native-keys
Version:
🔐 Make protected .ENVs variables
85 lines (84 loc) • 4.28 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.withPreActionScript = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const walk_sync_1 = __importDefault(require("walk-sync"));
const normalize_path_1 = __importDefault(require("normalize-path"));
const fs_1 = __importDefault(require("fs"));
const xml2js_1 = require("xml2js");
const normalizePath = process.platform === 'win32' ? normalize_path_1.default : (p) => p;
const iosXcodeproj = 'ios/*.xcodeproj/**/*.xcscheme';
const preAction = (BuildableReference, IS_EXAMPLE = false) => {
return {
PreActions: [
{
ExecutionAction: [
{
$: {
ActionType: 'Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction',
},
ActionContent: [
{
$: {
title: 'Run Script',
scriptText: `${IS_EXAMPLE
? 'exec > ${PROJECT_DIR}/prebuild.log 2>&1\nexport IS_EXAMPLE=TRUE\n'
: ''}${IS_EXAMPLE
? '"${SRCROOT}/../../keysIOS.js"'
: '"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"'}`,
},
EnvironmentBuildable: [
{
BuildableReference: BuildableReference,
},
],
},
],
},
],
},
],
};
};
const withPreActionScript = (config, props) => {
return (0, config_plugins_1.withDangerousMod)(config, [
'ios',
(dangerousConfig) => __awaiter(void 0, void 0, void 0, function* () {
const APP_PATH = process.cwd();
const paths = (0, walk_sync_1.default)(normalizePath(APP_PATH), {
globs: [iosXcodeproj],
});
if (paths.length > 0) {
const promises = paths.map((xcSchemePath) => __awaiter(void 0, void 0, void 0, function* () {
const xcSchemeContent = fs_1.default.readFileSync(xcSchemePath, {
encoding: 'utf-8',
});
const xcSchemeJson = yield (0, xml2js_1.parseStringPromise)(xcSchemeContent);
let BuildAction = xcSchemeJson.Scheme.BuildAction;
const BuildableReference = BuildAction[0].BuildActionEntries[0].BuildActionEntry[0]
.BuildableReference;
BuildAction[0] = Object.assign(Object.assign({}, BuildAction[0]), preAction(BuildableReference, props.IS_EXAMPLE));
xcSchemeJson.Scheme.BuildAction = BuildAction;
const builder = new xml2js_1.Builder();
const xcSchemeXml = builder.buildObject(xcSchemeJson);
fs_1.default.writeFileSync(xcSchemePath, xcSchemeXml);
}));
yield Promise.all(promises);
}
return dangerousConfig;
}),
]);
};
exports.withPreActionScript = withPreActionScript;
;