@applicaster/zapplicaster-cli
Version:
CLI Tool for the zapp app and Quick Brick project
87 lines (77 loc) • 3.01 kB
JavaScript
/* eslint-disable max-len */
/* eslint-disable no-template-curly-in-string */
const fs = require("fs");
const R = require("ramda");
const { getApplicasterConfig } = require("../../settings");
const { runInShellAsync } = require("../../shell");
async function runAndroid({ emulator, apkPath, zappAndroidPath, sleep }) {
const env = R.compose(
R.fromPairs,
R.map(R.split("=")),
R.split("\n")
)(fs.readFileSync(`${zappAndroidPath}/.env`).toString());
const { bundle_identifier: bundleIdentifier } = env;
await runInShellAsync(
`\${ANDROID_SDK}/emulator/emulator -avd ${emulator} -netdelay none -netspeed full -wipe-data & sleep ${sleep} \\
&& adb install ${apkPath} \\
&& adb reverse tcp:8081 tcp:8081 \\
&& adb reverse tcp:8097 tcp:8097 \\
&& adb shell am start -n ${bundleIdentifier}/com.applicaster.ui.activities.MainActivity \\
&& adb logcat *:S ReactNative:V ReactNativeJS:V`
);
}
const runPlatform = {
async ios({ zappApplePath, iPhoneEmulator }) {
const simulator = iPhoneEmulator ? `--simulator "${iPhoneEmulator}"` : "";
await runInShellAsync(
`node_modules/.bin/react-native run-ios --project-path ${zappApplePath}/ZappiOS --scheme ZappiOS --configuration Debug ${simulator}`
);
},
async iPad({ zappApplePath, iPadEmulator }) {
await runInShellAsync(
`node_modules/.bin/react-native run-ios --project-path ${zappApplePath}/ZappiOS --scheme ZappiOS --configuration Debug --simulator "${iPadEmulator}"`
);
},
async tvos({ zappApplePath, tvOSEmulator }) {
await runInShellAsync(
`node_modules/.bin/react-native run-ios --project-path ${zappApplePath}/ZappTvOS --scheme ZappTvOS --configuration Debug --simulator "${tvOSEmulator}"`
);
},
async android({ zappAndroidPath, androidMobileEmulator }) {
await runAndroid({
zappAndroidPath,
emulator: androidMobileEmulator,
sleep: 30,
apkPath: `${zappAndroidPath}/app/build/outputs/apk/mobileGoogle/debug/app-mobile-google-debug.apk`,
});
},
async androidTablet({ zappAndroidPath, androidTabletEmulator }) {
await runAndroid({
zappAndroidPath,
emulator: androidTabletEmulator,
sleep: 45,
apkPath: `${zappAndroidPath}/app/build/outputs/apk/mobileGoogle/debug/app-mobile-google-debug.apk`,
});
},
async androidTv({ zappAndroidPath, androidTVEmulator }) {
await runAndroid({
zappAndroidPath,
emulator: androidTVEmulator,
sleep: 30,
apkPath: `${zappAndroidPath}/app/build/outputs/apk/tvGoogle/debug/app-tv-google-debug.apk`,
});
},
async amazon({ zappAndroidPath, androidTVEmulator }) {
await runAndroid({
zappAndroidPath,
emulator: androidTVEmulator,
sleep: 30,
apkPath: `${zappAndroidPath}/app/build/outputs/apk/tvAmazon/debug/app-tv-amazon-debug.apk`,
});
},
};
async function runApp({ platform }) {
await runPlatform[platform](getApplicasterConfig());
return true;
}
module.exports = { runApp };