@applicaster/zapplicaster-cli
Version:
CLI Tool for the zapp app and Quick Brick project
135 lines (122 loc) • 3.47 kB
JavaScript
const R = require("ramda");
const inquirer = require("inquirer");
const logger = require("../../logger");
const { runInShellAsync } = require("../../shell");
const { writeJsonToFile } = require("../../file");
async function setUpVars() {
const answers = await inquirer.prompt([
{
type: "input",
message: "Enter your Zapp Token",
name: "zappToken",
validate: R.compose(R.not, R.isEmpty),
},
{
type: "confirm",
message: "Do you want to clone ZappAppleBuilder repository ?",
name: "cloneZappAppleBuilder",
},
{
when: R.propEq("cloneZappAppleBuilder", false),
type: "input",
message: "Enter the path for zapp Apple Builder",
name: "_zappApplePath",
validate: R.compose(R.not, R.isEmpty),
},
{
when: R.propEq("cloneZappAppleBuilder", true),
validate: R.compose(R.not, R.isEmpty),
type: "input",
message: "Where do you want to clone the ZappAppleBuilder repository ?",
name: "cloneZappAppleBuilderPath",
},
{
type: "confirm",
message: "Do you want to clone Zapp-Android repository ?",
name: "cloneZappAndroid",
validate: R.compose(R.not, R.isEmpty),
},
{
when: R.propEq("cloneZappAndroid", false),
type: "input",
message: "Enter the path for the zapp android repository",
name: "_zappAndroidPath",
validate: R.compose(R.not, R.isEmpty),
},
{
when: R.propEq("cloneZappAndroid", true),
validate: R.compose(R.not, R.isEmpty),
type: "input",
message: "Where do you want to clone the Zapp Android repository ?",
name: "cloneZappAndroidPath",
},
{
type: "input",
message: "Enter the name of your Android TV Emulator",
name: "androidTVEmulator",
validate: R.compose(R.not, R.isEmpty),
},
{
type: "input",
message: "Enter the name of your Android Mobile Emulator",
name: "androidMobileEmulator",
validate: R.compose(R.not, R.isEmpty),
},
{
type: "input",
message: "Enter the name of your Apple TV Emulator",
default: "Apple TV",
name: "tvOSEmulator",
validate: R.compose(R.not, R.isEmpty),
},
]);
const {
cloneZappAppleBuilder,
cloneZappAndroid,
cloneZappAppleBuilderPath,
cloneZappAndroidPath,
zappToken,
androidTVEmulator,
androidMobileEmulator,
tvOSEmulator,
_zappApplePath,
_zappAndroidPath,
} = answers;
let zappApplePath = _zappApplePath;
let zappAndroidPath = _zappAndroidPath;
if (cloneZappAppleBuilder) {
await runInShellAsync(
"git clone git@github.com:applicaster/ZappAppleBuilder.git",
{ cwd: cloneZappAppleBuilderPath }
);
zappApplePath = `${cloneZappAppleBuilder}/zappAppleBuilder`;
}
if (cloneZappAndroid) {
await runInShellAsync(
"git clone git@github.com:applicaster/zapp-platform-android.git",
{
cwd: cloneZappAndroidPath,
}
);
zappAndroidPath = `${cloneZappAndroid}/Zapp-Android`;
}
const applicasterConfig = {
zappToken,
zappApplePath,
zappAndroidPath,
androidMobileEmulator,
androidTVEmulator,
tvOSEmulator,
};
try {
await writeJsonToFile(
`${process.env.HOME}/.applicaster.json`,
applicasterConfig
);
} catch (e) {
logger.error("could not save configuration file");
throw e;
}
return true;
}
module.exports = { setUpVars };