"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = require("fs-extra"); const glob_1 = require("glob"); const path = __importStar(require("path")); const errors_1 = require("../utils/errors"); const WarningAggregator = __importStar(require("../utils/warnings")); const ignoredPaths = ['**/@(Carthage|Pods|node_modules)/**']; function getAppDelegate(projectRoot) { const [using, ...extra] = glob_1.sync('ios/*/AppDelegate.@(m|swift)', { absolute: true, cwd: projectRoot, ignore: ignoredPaths, }); if (!using) { throw new errors_1.UnexpectedError(`Could not locate a valid AppDelegate at root: "${projectRoot}"`); } if (extra.length) { warnMultipleFiles({ tag: 'app-delegate', fileName: 'AppDelegate', projectRoot, using, extra, }); } const isSwift = using.match(/^.*\.(swift)$/); return { path: using, contents: fs_extra_1.readFileSync(using, 'utf8'), language: isSwift ? 'swift' : 'objc', }; } exports.getAppDelegate = getAppDelegate; function getSourceRoot(projectRoot) { const appDelegate = getAppDelegate(projectRoot); return path.dirname(appDelegate.path); } exports.getSourceRoot = getSourceRoot; function findSchemePaths(projectRoot) { return glob_1.sync('ios/*.xcodeproj/xcshareddata/xcschemes/*.xcscheme', { absolute: true, cwd: projectRoot, ignore: ignoredPaths, }); } exports.findSchemePaths = findSchemePaths; function findSchemeNames(projectRoot) { const schemePaths = findSchemePaths(projectRoot); return schemePaths.map(schemePath => path.basename(schemePath).split('.')[0]); } exports.findSchemeNames = findSchemeNames; function getAllXcodeProjectPaths(projectRoot) { const iosFolder = 'ios'; const pbxprojPaths = glob_1.sync('**/*.xcodeproj', { cwd: projectRoot, ignore: ignoredPaths }) .filter(project => !/test|example|sample/i.test(project) || path.dirname(project) === iosFolder) .sort(project => (path.dirname(project) === iosFolder ? -1 : 1)) // sort alphabetically to ensure this works the same across different devices (Fail in CI (linux) without this) .sort(); if (!pbxprojPaths.length) { throw new errors_1.UnexpectedError(`Failed to locate the ios/*.xcodeproj files relative to path "${projectRoot}".`); } return pbxprojPaths.map(value => path.join(projectRoot, value)); } exports.getAllXcodeProjectPaths = getAllXcodeProjectPaths; /** * Get the pbxproj for the given path */ function getXcodeProjectPath(projectRoot) { const [using, ...extra] = getAllXcodeProjectPaths(projectRoot); if (extra.length) { warnMultipleFiles({ tag: 'xcodeproj', fileName: '*.xcodeproj', projectRoot, using, extra, }); } return using; } exports.getXcodeProjectPath = getXcodeProjectPath; function getAllPBXProjectPaths(projectRoot) { const projectPaths = getAllXcodeProjectPaths(projectRoot); const paths = projectPaths .map(value => path.join(value, 'project.pbxproj')) .filter(value => fs_extra_1.pathExistsSync(value)); if (!paths.length) { throw new errors_1.UnexpectedError(`Failed to locate the ios/*.xcodeproj/project.pbxproj files relative to path "${projectRoot}".`); } return paths; } exports.getAllPBXProjectPaths = getAllPBXProjectPaths; function getPBXProjectPath(projectRoot) { const [using, ...extra] = getAllPBXProjectPaths(projectRoot); if (extra.length) { warnMultipleFiles({ tag: 'project-pbxproj', fileName: 'project.pbxproj', projectRoot, using, extra, }); } return using; } exports.getPBXProjectPath = getPBXProjectPath; function getAllInfoPlistPaths(projectRoot) { const paths = glob_1.sync('ios/*/Info.plist', { absolute: true, cwd: projectRoot, ignore: ignoredPaths, }).sort( // longer name means more suffixes, we want the shortest possible one to be first. (a, b) => a.length - b.length); if (!paths.length) { throw new errors_1.UnexpectedError(`Failed to locate Info.plist files relative to path "${projectRoot}".`); } return paths; } exports.getAllInfoPlistPaths = getAllInfoPlistPaths; function getInfoPlistPath(projectRoot) { const [using, ...extra] = getAllInfoPlistPaths(projectRoot); if (extra.length) { warnMultipleFiles({ tag: 'info-plist', fileName: 'Info.plist', projectRoot, using, extra, }); } return using; } exports.getInfoPlistPath = getInfoPlistPath; function getAllEntitlementsPaths(projectRoot) { const paths = glob_1.sync('ios/*/*.entitlements', { absolute: true, cwd: projectRoot, ignore: ignoredPaths, }); return paths; } exports.getAllEntitlementsPaths = getAllEntitlementsPaths; /** * Get the entitlements file path if it exists. * * @param projectRoot */ function getEntitlementsPath(projectRoot) { const [using, ...extra] = getAllEntitlementsPaths(projectRoot); if (extra.length) { warnMultipleFiles({ tag: 'entitlements', fileName: '*.entitlements', projectRoot, using, extra, }); } return using !== null && using !== void 0 ? using : null; } exports.getEntitlementsPath = getEntitlementsPath; function getSupportingPath(projectRoot) { return path.resolve(projectRoot, 'ios', path.basename(getSourceRoot(projectRoot)), 'Supporting'); } exports.getSupportingPath = getSupportingPath; function getExpoPlistPath(projectRoot) { const supportingPath = getSupportingPath(projectRoot); return path.join(supportingPath, 'Expo.plist'); } exports.getExpoPlistPath = getExpoPlistPath; function warnMultipleFiles({ tag, fileName, projectRoot, using, extra, }) { const usingPath = projectRoot ? path.relative(projectRoot, using) : using; const extraPaths = projectRoot ? extra.map(v => path.relative(projectRoot, v)) : extra; WarningAggregator.addWarningIOS(`paths-${tag}`, `Found multiple ${fileName} file paths, using "${usingPath}". Ignored paths: ${JSON.stringify(extraPaths)}`); } //# sourceMappingURL=Paths.js.map