Skip to content

Commit

Permalink
Merge pull request #303 from vtex/fix/code-style
Browse files Browse the repository at this point in the history
Fix lint issues across project
  • Loading branch information
drawveloper authored May 16, 2017
2 parents 81a98b8 + 15e2475 commit dc4f2e0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/modules/apps/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const uninstallApps = (apps: string[], preConfirm: boolean): Bluebird<void | nev
if (!err.toolbeltWarning) {
log.warn(`The following apps were not uninstalled: ${apps.join(', ')}`)
// the warn message is only displayed the first time the err occurs.
err.toolbeltWarning = true;
err.toolbeltWarning = true
}
throw err
})
Expand Down
2 changes: 1 addition & 1 deletion src/modules/apps/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const unlinkApps = (apps: string[]): Bluebird<void | never> => {
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
})
Expand Down
2 changes: 1 addition & 1 deletion src/modules/io/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
install: {
alias: 'i',
module: dirnameJoin('modules/io/install'),
}
},
},
}
87 changes: 40 additions & 47 deletions src/modules/io/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {router} from '../../clients'

const {listAvailableIoVersions, installIo, listInstalledServices} = router


const promptInstall = (version: IoVersions): Bluebird<boolean> =>
Promise.resolve(
inquirer.prompt({
Expand All @@ -22,33 +21,32 @@ const promptInstall = (version: IoVersions): Bluebird<boolean> =>
)

const installVersion = (version: string): Bluebird<any> => {
const spinner = ora('Getting versions').start()
return Promise.all([listAvailableIoVersions(), listInstalledServices()])
.tap(() => spinner.stop())
.spread<[IoVersions, InfraInstalledResources[]]>((availableIoVersions: IoVersions[], installedResouces: InfraInstalledResources[]) => {
const foundVersion = find<IoVersions>(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<IoVersions>(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
})
}

Expand All @@ -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<InfraInstalledResources>(propEq('name', service))(installedResouces);
if(actualVersion) {
if(actualVersion.version === ioVersion.services[service]) {
ioVersionServices.forEach(service => {
const actualVersion = find<InfraInstalledResources>(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',
Expand All @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/modules/io/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const listAllAvailableIoVersions = (tag: string): Bluebird<void> =>
.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]
Expand Down Expand Up @@ -52,22 +52,22 @@ const listAllAvailableIoVersions = (tag: string): Bluebird<void> =>
const printInstalledIoVersion = (): Bluebird<void> =>
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`)
Expand Down

0 comments on commit dc4f2e0

Please sign in to comment.