Skip to content

Commit

Permalink
chore: upgrade oclif core
Browse files Browse the repository at this point in the history
  • Loading branch information
haricnugraha committed Oct 4, 2024
1 parent 0f0c492 commit 58d2eb1
Show file tree
Hide file tree
Showing 11 changed files with 3,951 additions and 4,086 deletions.
7,877 changes: 3,869 additions & 4,008 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@
"dependencies": {
"@faker-js/faker": "^7.4.0",
"@hyperjumptech/monika-notification": "^1.18.0",
"@inquirer/prompts": "6.0.1",
"@isaacs/ttlcache": "^1.4.1",
"@oclif/core": "^3.27.0",
"@oclif/plugin-help": "^6.2.5",
"@oclif/plugin-plugins": "^5.3.4",
"@oclif/core": "^4.0.27",
"@oclif/plugin-help": "^6.2.13",
"@oclif/plugin-plugins": "^5.4.10",
"@sendgrid/mail": "^7.4.2",
"@types/pg": "^8.10.9",
"ajv": "^8.11.0",
"axios": "^0.27.2",
"axios": "0.27.2",
"boxen": "^5.0.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.1",
Expand Down Expand Up @@ -129,7 +130,7 @@
"@types/js-yaml": "^4.0.2",
"@types/mocha": "^5.2.7",
"@types/mongodb-uri": "^0.9.1",
"@types/node": "^20.11.30",
"@types/node": "20.11.30",
"@types/node-cron": "^2.0.4",
"@types/sinon": "^10.0.2",
"@types/smtp-server": "^3.5.6",
Expand All @@ -142,16 +143,16 @@
"chai-spies": "^1.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.51.0",
"eslint-config-oclif": "^5.0.0",
"eslint-config-oclif-typescript": "^3.0.5",
"eslint-config-oclif": "^5.2.1",
"eslint-config-oclif-typescript": "^3.1.11",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-perfectionist": "^2.1.0",
"husky": "^4.3.8",
"lint-staged": "^10.5.4",
"mocha": "^9.1.2",
"msw": "^2.2.3",
"nyc": "^15.1.0",
"oclif": "^4.14.0",
"oclif": "^4.15.2",
"pkg": "^5.8.1",
"prettier": "2.5.1",
"sinon": "^15.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/commands/monika.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* SOFTWARE. *
**********************************************************************************/

import { Command, Errors } from '@oclif/core'
import { Command } from '@oclif/core/command'
import { ExitError, handle } from '@oclif/core/errors'
import pEvent from 'p-event'

import type { ValidatedConfig } from '../interfaces/config'
Expand Down Expand Up @@ -76,8 +77,8 @@ export default class Monika extends Command {
await symonClient.sendStatus({ isOnline: false })
}

if (error instanceof Errors.ExitError) {
return Errors.handle(error)
if (error instanceof ExitError) {
return handle(error)
}

if (error.message.includes('EEXIT: 0')) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/config/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync } from 'node:fs'
import { writeFile } from 'node:fs/promises'
import { type } from 'node:os'

import { ux } from '@oclif/core'
import { confirm } from '@inquirer/prompts'
import yml from 'js-yaml'

import { getContext } from '../../context'
Expand Down Expand Up @@ -33,11 +33,11 @@ export async function createConfig(): Promise<void> {
const { force, output } = flags

if (existsSync(output) && !force) {
const answer = await ux.ux.prompt(
`\n${output} file is already exists. Overwrite (Y/n)?`
)
const answer = await confirm({
message: `\n${output} file is already exists. Overwrite?`,
})

if (answer.toLowerCase() !== 'y') {
if (!answer) {
log.warn(
'Command cancelled. You can use the -o flag to specify an output file or --force to overwrite without prompting.'
)
Expand Down
10 changes: 5 additions & 5 deletions src/components/logger/flush.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ux } from '@oclif/core'
import { confirm } from '@inquirer/prompts'
import { getContext } from '../../context'
import { log } from '../../utils/pino'
import { flushAllLogs, openLogfile } from './history'

export async function flush(): Promise<void> {
if (!getContext().flags.force) {
const answer = await ux.ux.prompt(
'Are you sure you want to flush all logs in monika-logs.db (Y/n)?'
)
const answer = await confirm({
message: 'Are you sure you want to flush all logs in monika-logs.db?',
})

if (answer !== 'Y') {
if (!answer) {
log.info('Cancelled. Thank you.')

return
Expand Down
84 changes: 42 additions & 42 deletions src/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import fs from 'node:fs'
import path from 'node:path'

import { Flags } from '@oclif/core'
import { boolean, custom, help, integer, string } from '@oclif/core/flags'

export enum SYMON_API_VERSION {
'v1' = 'v1',
Expand Down Expand Up @@ -121,188 +121,188 @@ function getDefaultConfig(): Array<string> {
}

export const flags = {
'auto-update': Flags.string({
'auto-update': string({
description:
'Enable auto-update for Monika. Available options: major, minor, patch. This will make Monika terminate itself on successful update but does not restart',
}),
config: Flags.string({
config: string({
char: 'c',
default: monikaFlagsDefaultValue.config,
description:
'JSON configuration filename or URL. If none is supplied, will look for monika.yml in the current directory',
env: 'MONIKA_JSON_CONFIG',
multiple: true,
}),
'config-filename': Flags.string({
'config-filename': string({
default: monikaFlagsDefaultValue['config-filename'],
dependsOn: ['config'],
description:
'The configuration filename for config file created if there is no config file found ',
}),
'config-interval': Flags.integer({
'config-interval': integer({
default: monikaFlagsDefaultValue['config-interval'],
dependsOn: ['config'],
description:
'The interval (in seconds) for periodic config checking if url is used as config source',
}),
'create-config': Flags.boolean({
'create-config': boolean({
description:
'Create config from HAR (-H), postman (-p), insomnia (-I), sitemap (--sitemap), textfile (--text) export file, or open Monika Configuration Generator using default browser',
default: monikaFlagsDefaultValue['create-config'],
}),
flush: Flags.boolean({
flush: boolean({
description: 'Flush logs',
default: monikaFlagsDefaultValue.flush,
}),
'follow-redirects': Flags.integer({
'follow-redirects': integer({
default: monikaFlagsDefaultValue['follow-redirects'],
description:
'Monika will follow redirects as many times as the specified value here. By default, Monika will follow redirects once. To disable redirects following, set the value to zero.',
}),
force: Flags.boolean({
force: boolean({
default: monikaFlagsDefaultValue.force,
description: 'Force commands with a yes whenever Y/n is prompted.',
}),
har: Flags.string({
har: string({
char: 'H', // (H)ar file to
description: 'Run Monika using a HAR file',
exclusive: ['postman', 'insomnia', 'sitemap', 'text'],
}),
help: Flags.help({ char: 'h' }),
id: Flags.string({
help: help({ char: 'h' }),
id: string({
char: 'i', // (i)ds to run
description: 'Define specific probe ids to run',
}),
ignoreInvalidTLS: Flags.boolean({
ignoreInvalidTLS: boolean({
description:
'Configures whether HTTPS requests should ignore invalid certificates',
default: monikaFlagsDefaultValue.ignoreInvalidTLS,
}),
insomnia: Flags.string({
insomnia: string({
char: 'I', // (I)nsomnia file to
description: 'Run Monika using an Insomnia json/yaml file',
exclusive: ['har', 'postman', 'sitemap', 'text'],
}),
'keep-verbose-logs': Flags.boolean({
'keep-verbose-logs': boolean({
default: monikaFlagsDefaultValue['keep-verbose-logs'],
description: 'Store all requests logs to database',
}),
logs: Flags.boolean({
logs: boolean({
char: 'l', // prints the (l)ogs
description: 'Print all logs.',
default: monikaFlagsDefaultValue.logs,
}),
'native-fetch': Flags.boolean({
'native-fetch': boolean({
default: monikaFlagsDefaultValue['native-fetch'],
description:
'Use native fetch Node.js API instead of Axios for HTTP client',
}),
'one-probe': Flags.boolean({
'one-probe': boolean({
dependsOn: ['sitemap'],
description: 'One Probe',
}),
output: Flags.string({
output: string({
char: 'o', // (o)utput file to write config to
description: 'Write monika config file to this file',
default: monikaFlagsDefaultValue.output,
}),
postman: Flags.string({
postman: string({
char: 'p', // (p)ostman
description: 'Run Monika using a Postman json file.',
exclusive: ['har', 'insomnia', 'sitemap', 'text'],
}),
prometheus: Flags.integer({
prometheus: integer({
description:
'Specifies the port the Prometheus metric server is listening on. e.g., 3001. (EXPERIMENTAL)',
exclusive: ['r'],
}),
repeat: Flags.integer({
repeat: integer({
char: 'r', // (r)epeat
default: monikaFlagsDefaultValue.repeat,
description: 'Repeats the test run n times',
}),
retryInitialDelayMs: Flags.integer({
retryInitialDelayMs: integer({
default: monikaFlagsDefaultValue.retryInitialDelayMs,
description: `The initial, first delay of the backoff retry when probe request is failed, in milliseconds. Defaults to ${monikaFlagsDefaultValue.retryInitialDelayMs}ms`,
}),
retryMaxDelayMs: Flags.integer({
retryMaxDelayMs: integer({
default: monikaFlagsDefaultValue.retryMaxDelayMs,
description: `Maximum backoff retry delay, in milliseconds. Defaults to ${monikaFlagsDefaultValue.retryMaxDelayMs}ms.`,
}),
sitemap: Flags.string({
sitemap: string({
description: 'Run Monika using a Sitemap xml file.',
exclusive: ['har', 'insomnia', 'postman', 'text'],
}),
'status-notification': Flags.string({
'status-notification': string({
description: 'Cron syntax for status notification schedule',
}),
stun: Flags.integer({
stun: integer({
char: 's', // (s)stun
default: monikaFlagsDefaultValue.stun,
description: 'Interval in seconds to check STUN server',
}),
summary: Flags.boolean({
summary: boolean({
default: monikaFlagsDefaultValue.summary,
description: 'Display a summary of monika running stats',
}),
'symon-api-version': Flags.custom<SYMON_API_VERSION>({
'symon-api-version': custom<SYMON_API_VERSION>({
default: monikaFlagsDefaultValue['symon-api-version'],
description:
'Symon API version to use. Available options: v1, v2. Default: v1',
options: [SYMON_API_VERSION.v1, SYMON_API_VERSION.v2],
})(),
symonKey: Flags.string({
symonKey: string({
dependsOn: ['symonUrl'],
description: 'API Key for Symon',
}),
symonGetProbesIntervalMs: Flags.integer({
symonGetProbesIntervalMs: integer({
default: monikaFlagsDefaultValue.symonGetProbesIntervalMs,
description: `To determine how often Monika sends a request to Symon to get probe data, in milliseconds. Defaults to ${monikaFlagsDefaultValue.symonGetProbesIntervalMs}ms`,
}),
symonLocationId: Flags.string({
symonLocationId: string({
dependsOn: ['symonKey', 'symonUrl'],
description: 'Location ID for Symon (optional)',
}),
symonMonikaId: Flags.string({
symonMonikaId: string({
dependsOn: ['symonKey', 'symonUrl'],
description: 'Monika ID for Symon (optional)',
}),
symonReportInterval: Flags.integer({
symonReportInterval: integer({
dependsOn: ['symonKey', 'symonUrl'],
description: 'Interval for reporting to Symon in milliseconds (optional)',
}),
symonReportLimit: Flags.integer({
symonReportLimit: integer({
dependsOn: ['symonKey', 'symonUrl'],
description: 'Data limit to be reported to Symon (optional)',
}),
symonUrl: Flags.string({
symonUrl: string({
dependsOn: ['symonKey'],
description: 'URL of Symon',
hidden: false,
}),
text: Flags.string({
text: string({
description: 'Run Monika using a Simple text file',
exclusive: ['postman', 'insomnia', 'sitemap', 'har'],
}),
'ttl-cache': Flags.integer({
'ttl-cache': integer({
description:
'Enables time-to-live for in-memory (HTTP) cache entries in minutes',
default: monikaFlagsDefaultValue['ttl-cache'],
}),
'user-agent': Flags.string({
'user-agent': string({
default: monikaFlagsDefaultValue['user-agent'],
description:
'User agent to use for probing, defaults to monika/{current Monika version}',
}),
verbose: Flags.boolean({
verbose: boolean({
default: monikaFlagsDefaultValue.verbose,
description: 'Show verbose log messages',
}),
'verbose-cache': Flags.boolean({
'verbose-cache': boolean({
default: monikaFlagsDefaultValue.verbose,
description: 'Show cache hit / miss messages to log',
}),
version: Flags.boolean({ char: 'v', description: 'show CLI version' }),
version: boolean({ char: 'v', description: 'show CLI version' }),
}

export function sanitizeFlags(flags: Partial<MonikaFlags>): MonikaFlags {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { run } from '@oclif/core'
export { run } from '@oclif/core/run'
2 changes: 1 addition & 1 deletion src/loaders/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE. *
**********************************************************************************/

import type { Config } from '@oclif/core'
import type { Config } from '@oclif/core/config'
import { expect } from '@oclif/test'

import { sanitizeFlags } from '../flag'
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE. *
**********************************************************************************/

import type { Config } from '@oclif/core'
import type { Config } from '@oclif/core/config'
import { isSymonModeFrom } from '../components/config'
import { watchConfigChanges } from '../components/config/watcher'
import { openLogfile } from '../components/logger/history'
Expand Down
Loading

0 comments on commit 58d2eb1

Please sign in to comment.