Skip to content

Commit

Permalink
Upgrade dependencies, refactor code for most recent versions and appl…
Browse files Browse the repository at this point in the history
…y linter
  • Loading branch information
elribonazo committed Dec 13, 2024
1 parent 66a3be5 commit 4c0ade6
Show file tree
Hide file tree
Showing 13 changed files with 2,253 additions and 5,777 deletions.
7,825 changes: 2,150 additions & 5,675 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 25 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tslint": "tslint -c tslint.json -p tsconfig.json",
"formatter": "prettier --check ./src/**/*.ts",
"formatter-write": "prettier --write ./src/**/*.ts",
"build": "npm run tslint && rm -rf ./built && npx tsc && chmod +x ./built -R"
"build": "npm run tslint && rm -rf ./built && npx tsc && chmod -R +x ./built "
},
"bin": {
"caprover": "./built/commands/caprover.js",
Expand All @@ -34,6 +34,9 @@
"Server",
"Container"
],
"engines": {
"node": ">=20"
},
"author": "Kasra Bigdeli",
"license": "Apache-2.0",
"lint-staged": {
Expand All @@ -44,36 +47,31 @@
]
},
"dependencies": {
"chalk": "^2.4.2",
"command-exists": "^1.2.8",
"commander": "^2.20.0",
"configstore": "^5.0.0",
"fs-extra": "^8.1.0",
"chalk": "^5.3.0",
"command-exists": "^1.2.9",
"commander": "^12.1.0",
"configstore": "^7.0.0",
"fs-extra": "^11.2.0",
"inquirer": "^6.5.0",
"js-yaml": "^3.13.1",
"ora": "^3.4.0",
"js-yaml": "^4.1.0",
"ora": "^8.1.1",
"progress": "^2.0.3",
"request": "^2.88.0",
"request-promise": "^4.2.5",
"typescript": "^3.5.3",
"update-notifier": "^3.0.1"
"request": "^2.88.2",
"request-promise": "^4.2.6",
"update-notifier": "^7.3.1"
},
"devDependencies": {
"@types/command-exists": "^1.2.0",
"@types/configstore": "^4.0.0",
"@types/fs-extra": "^8.0.0",
"@types/inquirer": "6.5.0",
"@types/js-yaml": "^3.12.1",
"@types/node": "^12.7.2",
"@types/ora": "^3.2.0",
"@types/progress": "^2.0.3",
"@types/request-promise": "^4.1.45",
"@types/update-notifier": "^2.5.0",
"eslint": "^6.2.2",
"eslint-plugin-jest": "^22.15.2",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"@types/command-exists": "^1.2.3",
"@types/configstore": "^6.0.2",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^6.5.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.1.0",
"@types/progress": "^2.0.7",
"@types/request-promise": "^4.1.51",
"@types/update-notifier": "^6.0.8",
"prettier": "^3.4.2",
"tslint": "^5.20.1",
"typescript": "^3.5.3"
"typescript": "^5.7.2"
}
}
5 changes: 2 additions & 3 deletions src/api/ApiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ export default class ApiManager {
appName +
(detached ? '?detached=1' : ''),
{
captainDefinitionContent: JSON.stringify(
captainDefinition
),
captainDefinitionContent:
JSON.stringify(captainDefinition),
gitHash
}
)
Expand Down
44 changes: 23 additions & 21 deletions src/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isAbsolute, join } from 'path'
import { pathExistsSync } from 'fs-extra'
import { readFileSync } from 'fs'
import * as yaml from 'js-yaml'
import { CommanderStatic } from 'commander'
import { Command as CommanderStatic } from 'commander'
import * as inquirer from 'inquirer'
import Constants from '../utils/Constants'
import StdOutUtil from '../utils/StdOutUtil'
Expand Down Expand Up @@ -149,7 +149,7 @@ export default abstract class Command {

const cmd = this.program.command(this.command)
if (this.aliases && this.aliases.length) {
this.aliases.forEach(alias => alias && cmd.alias(alias))
this.aliases.forEach((alias) => alias && cmd.alias(alias))
}
if (this.description) {
cmd.description(this.description)
Expand All @@ -159,7 +159,7 @@ export default abstract class Command {
}

const options = this.getOptions().filter(
opt => opt && opt.name && !opt.hide
(opt) => opt && opt.name && !opt.hide
)
const spaces = ' '.repeat(
options.reduce(
Expand All @@ -168,7 +168,9 @@ export default abstract class Command {
max,
this.getCmdLineFlags(opt, opt.type).length,
(opt.aliases || [])
.filter(alias => alias && alias.name && !alias.hide)
.filter(
(alias) => alias && alias.name && !alias.hide
)
.reduce(
(amax, a) =>
Math.max(
Expand All @@ -181,16 +183,16 @@ export default abstract class Command {
0
) + 4
)
options.forEach(opt => {
options.forEach((opt) => {
cmd.option(
this.getCmdLineFlags(opt, opt.type),
this.getCmdLineDescription(opt, spaces),
getValue(opt.default)
)
if (opt.aliases) {
opt.aliases
.filter(alias => alias && alias.name && !alias.hide)
.forEach(alias =>
.filter((alias) => alias && alias.name && !alias.hide)
.forEach((alias) =>
cmd.option(
this.getCmdLineFlags(alias, opt.type),
this.getCmdLineDescription(opt, spaces, alias)
Expand All @@ -209,14 +211,14 @@ export default abstract class Command {

const cmdLineOptions = await this.preAction(allParams[0])
const optionAliases: IOptionAliasWithDetails[] = this.getOptions()
.filter(opt => opt && opt.name)
.filter((opt) => opt && opt.name)
.reduce(
(acc, opt) => [
...acc,
{ ...opt, aliasTo: opt.name },
...(opt.aliases || [])
.filter(alias => alias && alias.name)
.map(alias => ({ ...alias, aliasTo: opt.name }))
.filter((alias) => alias && alias.name)
.map((alias) => ({ ...alias, aliasTo: opt.name }))
],
[]
)
Expand Down Expand Up @@ -244,9 +246,9 @@ export default abstract class Command {

// Read params from env variables
optionAliases
.filter(opta => opta.env && opta.env in process.env)
.filter((opta) => opta.env && opta.env in process.env)
.forEach(
opta =>
(opta) =>
(params[opta.aliasTo] = {
value: process.env[opta.env!],
from: ParamType.Env
Expand All @@ -256,7 +258,7 @@ export default abstract class Command {
// Get config file name from env variables or command line options
let file: string | null = optionAliases
.filter(
opta =>
(opta) =>
cmdLineOptions &&
opta.aliasTo === CONFIG_FILE_NAME &&
opta.name in cmdLineOptions
Expand All @@ -269,7 +271,7 @@ export default abstract class Command {
delete params[CONFIG_FILE_NAME]
}
optionAliases = optionAliases.filter(
opta => opta.aliasTo !== CONFIG_FILE_NAME
(opta) => opta.aliasTo !== CONFIG_FILE_NAME
)

if (file) {
Expand All @@ -289,7 +291,7 @@ export default abstract class Command {
) {
config = JSON.parse(fileContent)
} else {
config = yaml.safeLoad(fileContent)
config = yaml.load(fileContent)
}
}

Expand All @@ -305,9 +307,9 @@ export default abstract class Command {

this.configFileProvided = true
optionAliases
.filter(opta => opta.name in config)
.filter((opta) => opta.name in config)
.forEach(
opta =>
(opta) =>
(params[opta.aliasTo] = {
value: config[opta.name],
from: ParamType.Config
Expand All @@ -318,17 +320,17 @@ export default abstract class Command {
if (cmdLineOptions) {
// Overwrite params from command line options
optionAliases
.filter(opta => opta.name in cmdLineOptions)
.filter((opta) => opta.name in cmdLineOptions)
.forEach(
opta =>
(opta) =>
(params[opta.aliasTo] = {
value: cmdLineOptions[opta.name],
from: ParamType.CommandLine
})
)
}

const options = this.getOptions(params).filter(opt => opt && opt.name)
const options = this.getOptions(params).filter((opt) => opt && opt.name)
let q = false
for (const option of options) {
const name = option.name!
Expand Down Expand Up @@ -378,5 +380,5 @@ export default abstract class Command {
*
* @param params
*/
protected abstract async action(params: IParams): Promise<void>
protected abstract action(params: IParams): Promise<void>
}
4 changes: 2 additions & 2 deletions src/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class Api extends Command {
? ''
: ' (or also JSON object from config file), for "GET" method they are interpreted as querystring values to be appended to the path'),
type: 'input',
filter: data => {
filter: (data) => {
if (data && typeof data === 'string') {
try {
return JSON.parse(data)
Expand All @@ -158,7 +158,7 @@ export default class Api extends Command {
}
return data
},
validate: data => {
validate: (data) => {
if (data && typeof data === 'string') {
try {
JSON.parse(data)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/caprover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// tslint:disable-next-line: no-var-requires
const packagejson = require('../../package.json')
import * as updateNotifier from 'update-notifier'
import updateNotifier from 'update-notifier'

const versionOfNode = Number(process.version.split('.')[0])

Expand All @@ -16,7 +16,7 @@ if (versionOfNode < 8) {
updateNotifier({ pkg: packagejson }).notify({ isGlobal: true })

import StdOutUtil from '../utils/StdOutUtil'
import * as program from 'commander'
import { program } from 'commander'

// Command actions
import Command from './Command'
Expand All @@ -42,7 +42,7 @@ const commands: Command[] = [
new Deploy(program),
new Api(program)
]
commands.forEach(c => c.build())
commands.forEach((c) => c.build())

// Error on unknown commands
program.on('command:*', () => {
Expand Down
16 changes: 7 additions & 9 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,22 @@ export default class Deploy extends Command {
}
if (possibleApp.deploySource.branchToPush) {
params[K.branch] = {
value:
possibleApp.deploySource
.branchToPush,
value: possibleApp.deploySource
.branchToPush,
from: ParamType.Default
}
} else if (
possibleApp.deploySource.tarFilePath
) {
params[K.tar] = {
value:
possibleApp.deploySource
.tarFilePath,
value: possibleApp.deploySource
.tarFilePath,
from: ParamType.Default
}
} else {
params[K.img] = {
value:
possibleApp.deploySource.imageName,
value: possibleApp.deploySource
.imageName,
from: ParamType.Default
}
}
Expand Down Expand Up @@ -366,7 +364,7 @@ export default class Deploy extends Command {
appName: this.paramValue(params, K.app)
},
this.apps.find(
app => app.appName === this.paramValue(params, K.app)
(app) => app.appName === this.paramValue(params, K.app)
)
)
}
Expand Down
23 changes: 12 additions & 11 deletions src/utils/CliHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class CliHelper {
value: '',
short: ''
},
...apps.map(app => ({
...apps.map((app) => ({
name: `${app.appName}`,
value: `${app.appName}`,
short: `${app.appName}`
Expand All @@ -46,7 +46,7 @@ export default class CliHelper {
},
...StorageHelper.get()
.getMachines()
.map(machine => ({
.map((machine) => ({
name: `${StdOutUtil.getColoredMachine(machine)}`,
value: `${machine.name}`,
short: `${machine.name}`
Expand All @@ -61,7 +61,7 @@ export default class CliHelper {
value: '',
short: ''
},
...Constants.API_METHODS.map(method => ({
...Constants.API_METHODS.map((method) => ({
name: `${method}`,
value: `${method}`,
short: `${method}`
Expand All @@ -78,9 +78,8 @@ export default class CliHelper {

async loginMachine(machine: IMachine, password: string) {
try {
const tokenToIgnore = await CliApiManager.get(machine).getAuthToken(
password
)
const tokenToIgnore =
await CliApiManager.get(machine).getAuthToken(password)
StdOutUtil.printGreenMessage(`Logged in successfully.`)
StdOutUtil.printMessage(
`Authorization token is now saved as ${StdOutUtil.getColoredMachine(
Expand Down Expand Up @@ -118,7 +117,7 @@ export default class CliHelper {
let currentSuffix = 1
const machines = StorageHelper.get()
.getMachines()
.map(machine => machine.name)
.map((machine) => machine.name)
while (machines.includes(this.getCaptainFullName(currentSuffix))) {
currentSuffix++
}
Expand All @@ -143,16 +142,18 @@ export default class CliHelper {
if (err !== true) {
// Error for domain: can't store credentials
StdOutUtil.printWarning(
`\nCan't store store login credentials: ${err ||
'error!'}\n`
`\nCan't store store login credentials: ${
err || 'error!'
}\n`
)
} else {
err = getErrorForMachineName(machineName)
if (err !== true) {
// Error for machine name: can't store credentials
StdOutUtil.printWarning(
`\nCan't store store login credentials: ${err ||
'error!'}\n`
`\nCan't store store login credentials: ${
err || 'error!'
}\n`
)
} else {
machine.name = machineName
Expand Down
Loading

0 comments on commit 4c0ade6

Please sign in to comment.