UNPKG

@applicaster/zapplicaster-cli

Version:

CLI Tool for the zapp app and Quick Brick project

84 lines (63 loc) 1.99 kB
const logger = require("../../logger"); const { runInShellAsync } = require("../../shell"); const BREW = "brew"; const ZAPPIFEST = "zappifest"; const ZAPPTOOL = "zapptool"; const YARN = "yarn"; const NODE = "node"; const LIBS = [BREW, ZAPPIFEST, ZAPPTOOL, YARN, NODE]; const NODE_VERSION = "12.16.1"; const YARN_VERSION = "1.21.1"; const INSTALL_SCRIPTS = { async [BREW]() { await runInShellAsync( // eslint-disable-next-line quotes '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' ); await runInShellAsync("brew tap applicaster/tap"); }, async [ZAPPIFEST]() { await runInShellAsync("brew install zappifest"); }, async [ZAPPTOOL]() { await runInShellAsync("brew install zapptool"); }, async [YARN]() { await runInShellAsync( `curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version ${YARN_VERSION}` ); }, async [NODE]() { await runInShellAsync(`nvm install ${NODE_VERSION}`); await runInShellAsync(`nvm alias default ${NODE_VERSION}`); }, }; async function libraryExists(library) { try { const command = library === "nvm" ? "echo $NVM_DIR" : `which ${library}`; const stdout = await runInShellAsync(command, { silent: true }); if (stdout) { logger.log(`${library} found at ${stdout} - skipping install`); } return !!stdout; } catch (e) { logger.warn(`couldn't find ${library} - we will try to install`); return false; } } async function installLibraryIfMissing(library) { const libExists = await libraryExists(library); if (!libExists) { logger.warn(`${library} not found - installing...`); await INSTALL_SCRIPTS[library](); } return true; } async function setUpEnvironment() { LIBS.reduce(async (previous, current) => { await previous; return await installLibraryIfMissing(current); }, Promise.resolve(true)); return true; } module.exports = { setUpEnvironment };