@react-native/core-cli-utils
Version:
React Native CLI library for Frameworks to build on
180 lines (178 loc) • 5.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.tasks = void 0;
var _utils = require("./utils");
var _execa = _interopRequireDefault(require("execa"));
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
function checkPodfileInSyncWithManifest(lockfilePath, manifestLockfilePath) {
try {
const expected = _fs.default.readFileSync(lockfilePath, "utf8");
const found = _fs.default.readFileSync(manifestLockfilePath, "utf8");
if (expected !== found) {
throw new Error(
"Please run: yarn bootstrap ios, Podfile.lock and Pods/Manifest.lock are out of sync",
);
}
} catch (e) {
throw new Error("Please run: yarn run boostrap ios: " + e.message);
}
}
const FIRST = 1,
SECOND = 2,
THIRD = 3,
FOURTH = 4,
FIFTH = 5;
function getNodePackagePath(packageName) {
return require.resolve(packageName, {
cwd: [process.cwd(), ...module.paths],
});
}
const tasks = (exports.tasks = {
bootstrap: (options) => ({
cleanupBuildFolder: (0, _utils.task)(FIRST, "Cleanup build folder", () => {
_execa.default.sync("rm", ["-rf", "build"], {
cwd: options.cwd,
});
}),
runCodegen: (0, _utils.task)(SECOND, "Run codegen", () => {
const reactNativePath = _path.default.dirname(
getNodePackagePath("react-native"),
);
const codegenScript = _path.default.join(
reactNativePath,
"scripts",
"generate-codegen-artifacts.js",
);
_execa.default.sync("node", [
codegenScript,
"-p",
process.cwd(),
"-o",
options.cwd,
"-t",
"ios",
]);
}),
validate: (0, _utils.task)(
THIRD,
"Check Cocoapods and bundle are available",
() => {
(0, _utils.assertDependencies)(
(0, _utils.isOnPath)("pod", "CocoaPods"),
(0, _utils.isOnPath)("bundle", "Bundler to manage Ruby's gems"),
);
},
),
installRubyGems: (0, _utils.task)(FOURTH, "Install Ruby Gems", () =>
(0, _execa.default)("bundle", ["install"], {
cwd: options.cwd,
}),
),
installDependencies: (0, _utils.task)(
FIFTH,
"Install CocoaPods dependencies",
() => {
const env = {
RCT_NEW_ARCH_ENABLED: options.newArchitecture ? "1" : "0",
USE_FRAMEWORKS: options.frameworks,
USE_HERMES: options.hermes ? "1" : "0",
RCT_IGNORE_PODS_DEPRECATION: "1",
};
if (options.frameworks == null) {
delete env.USE_FRAMEWORKS;
}
return (0, _execa.default)("bundle", ["exec", "pod", "install"], {
cwd: options.cwd,
env,
});
},
),
}),
build: (options, ...args) => ({
validate: (0, _utils.task)(
FIRST,
"Check you've run xcode-select --install for xcodebuild",
() => {
(0, _utils.assertDependencies)(
(0, _utils.isOnPath)("xcodebuild", "Xcode Commandline Tools"),
);
},
),
hasPodsInstalled: (0, _utils.task)(
FIRST,
"Check Pods are installed",
() => {
for (const file of ["Podfile.lock", "Pods"]) {
try {
_fs.default.accessSync(
_path.default.join(options.cwd, file),
_fs.default.constants.F_OK | _fs.default.constants.R_OK,
);
} catch (e) {
throw new Error("Please run: yarn run boostrap ios: " + e.message);
}
}
checkPodfileInSyncWithManifest(
_path.default.join(options.cwd, "Podfile.lock"),
_path.default.join(options.cwd, "Pods/Manifest.lock"),
);
},
),
build: (0, _utils.task)(SECOND, "build an app artifact", () => {
const _args = [
options.isWorkspace ? "-workspace" : "-project",
options.name,
"-configuration",
options.mode,
];
if (options.scheme != null) {
_args.push("-scheme", options.scheme);
}
if (options.destination != null) {
switch (options.destination) {
case "simulator":
_args.push("-sdk", "iphonesimulator");
break;
case "device":
default:
_args.push("-destination", options.destination);
break;
}
}
_args.push(...args);
return (0, _execa.default)("xcodebuild", _args, {
cwd: options.cwd,
env: options.env,
});
}),
}),
ios: {
install: (options) => ({
validate: (0, _utils.task)(
FIRST,
"Check you've run xcode-select --install for xcrun",
() => {
(0, _utils.assertDependencies)(
(0, _utils.isOnPath)("xcrun", "An Xcode Commandline tool: xcrun"),
);
},
),
install: (0, _utils.task)(SECOND, "Install the app on a simulator", () =>
(0, _execa.default)(
"xcrun",
["simctl", "install", options.device, options.appPath],
{
cwd: options.cwd,
env: options.env,
},
),
),
}),
},
});