diff --git a/src/modules/apps/uninstall.ts b/src/modules/apps/uninstall.ts index 0823e3f71..238d1a047 100644 --- a/src/modules/apps/uninstall.ts +++ b/src/modules/apps/uninstall.ts @@ -48,7 +48,7 @@ const uninstallApps = (apps: string[], preConfirm: boolean): Bluebird => { if (!err.toolbeltWarning) { log.warn(`The following apps were not unlinked: ${apps.join(', ')}`) // the warn message is only displayed the first time the err occurs. - err.toolbeltWarning = true; + err.toolbeltWarning = true } throw err }) diff --git a/src/modules/io/index.ts b/src/modules/io/index.ts index 953e4bc6b..bcd4bd987 100644 --- a/src/modules/io/index.ts +++ b/src/modules/io/index.ts @@ -9,6 +9,6 @@ export default { install: { alias: 'i', module: dirnameJoin('modules/io/install'), - } + }, }, } diff --git a/src/modules/io/install.ts b/src/modules/io/install.ts index 5ebfc7874..11cc16db2 100644 --- a/src/modules/io/install.ts +++ b/src/modules/io/install.ts @@ -10,7 +10,6 @@ import {router} from '../../clients' const {listAvailableIoVersions, installIo, listInstalledServices} = router - const promptInstall = (version: IoVersions): Bluebird => Promise.resolve( inquirer.prompt({ @@ -22,33 +21,32 @@ const promptInstall = (version: IoVersions): Bluebird => ) const installVersion = (version: string): Bluebird => { - const spinner = ora('Getting versions').start() - return Promise.all([listAvailableIoVersions(), listInstalledServices()]) - .tap(() => spinner.stop()) - .spread<[IoVersions, InfraInstalledResources[]]>((availableIoVersions: IoVersions[], installedResouces: InfraInstalledResources[]) => { - const foundVersion = find(propEq('version', version))(availableIoVersions); - - return [foundVersion, installedResouces] - }) - .spread((version: IoVersions, installedResouces: InfraInstalledResources[]) => { - if(version) { - if(logVersionMap(version, installedResouces)) { - return promptInstall(version) + const spinner = ora('Getting versions').start() + return Promise.all([listAvailableIoVersions(), listInstalledServices()]) + .tap(() => spinner.stop()) + .spread<[IoVersions, InfraInstalledResources[]]>((availableIoVersions: IoVersions[], installedResouces: InfraInstalledResources[]) => { + const foundVersion = find(propEq('version', version))(availableIoVersions) + return [foundVersion, installedResouces] + }) + .spread((ioVersion: IoVersions, installedResources: InfraInstalledResources[]) => { + if (ioVersion) { + if (logVersionMap(ioVersion, installedResources)) { + return promptInstall(ioVersion) .then(confirm => { - if(confirm) { - return installIo(version.version) + if (confirm) { + return installIo(ioVersion.version) .then(() => log.info('Installation complete')) } }) - } - } else{ - log.error(`No suitable version`) - return null; } - }) - .catch(err => { - spinner.stop() - throw err + } else { + log.error(`No suitable version`) + return null + } + }) + .catch(err => { + spinner.stop() + throw err }) } @@ -58,58 +56,53 @@ const hasTag = (version: string, tag: string): boolean => { } const logVersionMap = (ioVersion: IoVersions, installedResouces: InfraInstalledResources[]): boolean => { + let shouldUpdate = false const ioVersionServices = Object.keys(ioVersion.services).sort() - var shouldUpdate = false; - ioVersionServices.forEach((service) => { - - var actualVersion = find(propEq('name', service))(installedResouces); - if(actualVersion) { - if(actualVersion.version === ioVersion.services[service]) { + ioVersionServices.forEach(service => { + const actualVersion = find(propEq('name', service))(installedResouces) + if (actualVersion) { + if (actualVersion.version === ioVersion.services[service]) { console.log(`${pad(service, 15)} ${chalk.yellow(actualVersion.version)}`) } else { - shouldUpdate = true; + shouldUpdate = true console.log(`${pad(service, 15)} ${actualVersion.version} ${chalk.gray('->')} ${chalk.green(ioVersion.services[service])}`) } } else { - shouldUpdate = true; + shouldUpdate = true console.log(`${pad(service, 15)} NA ${chalk.gray('->')} ${chalk.green(ioVersion.services[service])}`) } }) - - console.log("") - return shouldUpdate; + console.log('') + return shouldUpdate } const installVersionByTag = (tag: string): Bluebird<{}> => { const spinner = ora('Getting versions').start() return Promise.all([listAvailableIoVersions(), listInstalledServices()]) .tap(() => spinner.stop()) - .spread((availableIoVersions : IoVersions[], installedResouces: InfraInstalledResources[]) => { + .spread((availableIoVersions: IoVersions[], installedResouces: InfraInstalledResources[]) => { const versionsByTag = availableIoVersions - .filter(v => !tag || hasTag(v.version, tag)) - .sort((a, b) => semver.compare(b.version, a.version)) + .filter(v => !tag || hasTag(v.version, tag)) + .sort((a, b) => semver.compare(b.version, a.version)) - if(versionsByTag.length == 0) { + if (versionsByTag.length === 0) { log.error(`No suitable version`) - return null; + return null } - const versionToInstall = versionsByTag[0]; - - if(logVersionMap(versionToInstall, installedResouces)) { + const versionToInstall = versionsByTag[0] + if (logVersionMap(versionToInstall, installedResouces)) { return promptInstall(versionToInstall) .then(confirm => { - if(confirm) { + if (confirm) { return installIo(versionToInstall.version) .then(() => log.info('Installation complete')) } }) } - - }); + }) } - export default { optionalArgs: 'version', description: 'Install Io Version', @@ -119,7 +112,7 @@ export default { long: 'tag', description: 'Install last version by Tag', type: 'string', - } + }, ], handler: (version: string, options) => { const tag = options.t || options.tag diff --git a/src/modules/io/list.ts b/src/modules/io/list.ts index c361305a9..7b77814e7 100644 --- a/src/modules/io/list.ts +++ b/src/modules/io/list.ts @@ -23,8 +23,8 @@ const listAllAvailableIoVersions = (tag: string): Bluebird => .filter(v => !tag || hasTag(v.version, tag)) .sort((a, b) => semver.compare(b.version, a.version)) .slice(0, 10) - .forEach(({version, tested, services}) => { - const validVersion = semver.valid(version) + .forEach(({version: ioVersion, tested, services}) => { + const validVersion = semver.valid(ioVersion) const styledVersion = tested ? chalk.green(validVersion) : chalk.bold.yellow(validVersion) const serviceKeys = Object.keys(services) const row = [styledVersion] @@ -52,22 +52,22 @@ const listAllAvailableIoVersions = (tag: string): Bluebird => const printInstalledIoVersion = (): Bluebird => getInstalledIoVersion() .then((installed: IoVersions) => { - - const allServicesKeys = ['Version'] - const validVersion = semver.valid(installed.version) - const styledVersion = installed.tested ? chalk.green(validVersion) : chalk.bold.yellow(validVersion) - const serviceKeys = Object.keys(installed.services) - const row = [styledVersion] - serviceKeys.forEach(serviceKey => { - if (!contains(serviceKey, allServicesKeys)) - allServicesKeys.push(serviceKey) - const index = allServicesKeys.indexOf(serviceKey) - const version = installed.services[serviceKey] - row[index] = version - }) - const table = new Table({head: allServicesKeys}) - table.push(row) - return table + const allServicesKeys = ['Version'] + const validVersion = semver.valid(installed.version) + const styledVersion = installed.tested ? chalk.green(validVersion) : chalk.bold.yellow(validVersion) + const serviceKeys = Object.keys(installed.services) + const row = [styledVersion] + serviceKeys.forEach(serviceKey => { + if (!contains(serviceKey, allServicesKeys)) { + allServicesKeys.push(serviceKey) + } + const index = allServicesKeys.indexOf(serviceKey) + const version = installed.services[serviceKey] + row[index] = version + }) + const table = new Table({head: allServicesKeys}) + table.push(row) + return table }) .then(table => { log.info(`io versions available to install`)