Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-02 22:36:25 -05:00
parent 82e7a1f299
commit 1d5056b753
149 changed files with 6104 additions and 3114 deletions

View File

@@ -1,8 +1,8 @@
import {Directive} from "../Directive"
import {CommandLineApplication} from "../service"
import {Injectable} from "../../di"
import {ErrorWithContext} from "../../util"
import {Unit} from "../../lifecycle/Unit";
import {Directive} from '../Directive'
import {CommandLineApplication} from '../service'
import {Injectable} from '../../di'
import {ErrorWithContext} from '../../util'
import {Unit} from '../../lifecycle/Unit'
/**
* A directive that starts the framework's final target normally.

View File

@@ -1,7 +1,7 @@
import {Directive} from "../Directive"
import * as colors from "colors/safe"
import {Directive} from '../Directive'
import * as colors from 'colors/safe'
import * as repl from 'repl'
import {DependencyKey} from "../../di";
import {DependencyKey} from '../../di'
/**
* Launch an interactive REPL shell from within the application.
@@ -9,7 +9,7 @@ import {DependencyKey} from "../../di";
*/
export class ShellDirective extends Directive {
protected options: any = {
welcome: `powered by Extollo, © ${(new Date).getFullYear()} Garrett Mills\nAccess your application using the "app" global.`,
welcome: `powered by Extollo, © ${(new Date()).getFullYear()} Garrett Mills\nAccess your application using the "app" global.`,
prompt: `${colors.blue('(')}extollo${colors.blue(') ➤ ')}`,
}
@@ -38,7 +38,7 @@ export class ShellDirective extends Directive {
}
await new Promise<void>(res => {
console.log(this.options.welcome)
this.nativeOutput(this.options.welcome)
this.repl = repl.start(this.options.prompt)
Object.assign(this.repl.context, state)
this.repl.on('exit', () => res())

View File

@@ -1,8 +1,8 @@
import {Directive, OptionDefinition} from "../Directive"
import {PositionalOption} from "./options/PositionalOption"
import {CommandLine} from "../service"
import {Inject, Injectable} from "../../di";
import {ErrorWithContext} from "../../util";
import {Directive, OptionDefinition} from '../Directive'
import {PositionalOption} from './options/PositionalOption'
import {CommandLine} from '../service'
import {Inject, Injectable} from '../../di'
import {ErrorWithContext} from '../../util'
/**
* Create a new file based on a template registered with the CommandLine service.
@@ -46,11 +46,11 @@ export class TemplateDirective extends Directive {
'',
...(registeredTemplates.map(template => {
return ` - ${template.name}: ${template.description}`
}).all())
}).all()),
].join('\n')
}
async handle(argv: string[]) {
async handle(): Promise<void> {
const templateName: string = this.option('template_name')
const destinationName: string = this.option('file_name')

View File

@@ -1,7 +1,7 @@
import {Directive} from "../Directive"
import {Injectable, Inject} from "../../di"
import {padRight} from "../../util"
import {CommandLine} from "../service"
import {Directive} from '../Directive'
import {Injectable, Inject} from '../../di'
import {padRight} from '../../util'
import {CommandLine} from '../service'
/**
* Directive that prints the help message and usage information about
@@ -20,7 +20,7 @@ export class UsageDirective extends Directive {
return 'print information about available commands'
}
public handle(argv: string[]): void | Promise<void> {
public handle(): void | Promise<void> {
const directiveStrings = this.cli.getDirectives()
.map(cls => this.make<Directive>(cls))
.map<[string, string]>(dir => {
@@ -30,15 +30,15 @@ export class UsageDirective extends Directive {
const maxLen = directiveStrings.max<number>(x => x[0].length)
const printStrings = directiveStrings.map(grp => {
return [padRight(grp[0], maxLen + 1), grp[1]]
})
return [padRight(grp[0], maxLen + 1), grp[1]]
})
.map(grp => {
return ` ${grp[0]}: ${grp[1]}`
})
.toArray()
console.log(this.cli.getASCIILogo())
console.log([
this.nativeOutput(this.cli.getASCIILogo())
this.nativeOutput([
'',
'Welcome to Extollo! Specify a command to get started.',
'',
@@ -48,7 +48,7 @@ export class UsageDirective extends Directive {
'',
'For usage information about a particular command, pass the --help flag.',
'-------------------------------------------',
`powered by Extollo, © ${(new Date).getFullYear()} Garrett Mills`,
`powered by Extollo, © ${(new Date()).getFullYear()} Garrett Mills`,
].join('\n'))
}
}

View File

@@ -9,200 +9,207 @@ export abstract class CLIOption<T> {
* @type {boolean}
* @private
*/
protected _useWhitelist: boolean = false
protected useWhitelist = false
/**
* Do we use the blacklist?
* @type {boolean}
* @private
*/
protected _useBlacklist: boolean = false
protected useBlacklist = false
/**
* Do we use the less-than comparison?
* @type {boolean}
* @private
*/
protected _useLessThan: boolean = false
protected useLessThan = false
/**
* Do we use the greater-than comparison?
* @type {boolean}
* @private
*/
protected _useGreaterThan: boolean = false
protected useGreaterThan = false
/**
* Do we use the equality operator?
* @type {boolean}
* @private
*/
protected _useEquality: boolean = false
protected useEquality = false
/**
* Is this option optional?
* @type {boolean}
* @private
*/
protected _optional: boolean = false
protected isOptional = false
/**
* Whitelisted values.
* @type {Array<*>}
* @private
*/
protected _whitelist: T[] = []
protected whitelistItems: T[] = []
/**
* Blacklisted values.
* @type {Array<*>}
* @private
*/
protected _blacklist: T[] = []
protected blacklistItems: T[] = []
/**
* Value to be compared in less than.
* @type {*}
* @private
*/
protected _lessThanValue?: T
protected lessThanValue?: T
/**
* If true, the less than will be less than or equal to.
* @type {boolean}
* @private
*/
protected _lessThanBit: boolean = false
protected lessThanBit = false
/**
* Value to be compared in greater than.
* @type {*}
* @private
*/
protected _greaterThanValue?: T
protected greaterThanValue?: T
/**
* If true, the greater than will be greater than or equal to.
* @type {boolean}
* @private
*/
protected _greateerThanBit: boolean = false
protected greaterThanBit = false
/**
* The value to be used to check equality.
* @type {*}
* @private
*/
protected _equalityValue?: T
protected equalityValue?: T
/**
* Whitelist the specified item or items and enable the whitelist.
* @param {...*} items - the items to whitelist
*/
whitelist(...items: T[]) {
this._useWhitelist = true
items.forEach(item => this._whitelist.push(item))
whitelist(...items: T[]): this {
this.useWhitelist = true
items.forEach(item => this.whitelistItems.push(item))
return this
}
/**
* Blacklist the specified item or items and enable the blacklist.
* @param {...*} items - the items to blacklist
*/
blacklist(...items: T[]) {
this._useBlacklist = true
items.forEach(item => this._blacklist.push(item))
blacklist(...items: T[]): this {
this.useBlacklist = true
items.forEach(item => this.blacklistItems.push(item))
return this
}
/**
* Specifies the value to be used in less-than comparison and enables less-than comparison.
* @param {*} value
*/
lessThan(value: T) {
this._useLessThan = true
this._lessThanValue = value
lessThan(value: T): this {
this.useLessThan = true
this.lessThanValue = value
return this
}
/**
* Specifies the value to be used in less-than or equal-to comparison and enables that comparison.
* @param {*} value
*/
lessThanOrEqualTo(value: T) {
this._lessThanBit = true
lessThanOrEqualTo(value: T): this {
this.lessThanBit = true
this.lessThan(value)
return this
}
/**
* Specifies the value to be used in greater-than comparison and enables that comparison.
* @param {*} value
*/
greaterThan(value: T) {
this._useGreaterThan = true
this._greaterThanValue = value
greaterThan(value: T): this {
this.useGreaterThan = true
this.greaterThanValue = value
return this
}
/**
* Specifies the value to be used in greater-than or equal-to comparison and enables that comparison.
* @param {*} value
*/
greaterThanOrEqualTo(value: T) {
this._greateerThanBit = true
greaterThanOrEqualTo(value: T): this {
this.greaterThanBit = true
this.greaterThan(value)
return this
}
/**
* Specifies the value to be used in equality comparison and enables that comparison.
* @param {*} value
*/
equals(value: T) {
this._useEquality = true
this._equalityValue = value
equals(value: T): this {
this.useEquality = true
this.equalityValue = value
return this
}
/**
* Checks if the specified value passes the configured comparisons.
* @param {*} value
* @param value
* @returns {boolean}
*/
validate(value: any) {
let is_valid = true
if ( this._useEquality ) {
is_valid = is_valid && (this._equalityValue === value)
validate(value: T): boolean {
let isValid = true
if ( this.useEquality ) {
isValid = isValid && (this.equalityValue === value)
}
if ( this._useLessThan && typeof this._lessThanValue !== 'undefined' ) {
if ( this._lessThanBit ) {
is_valid = is_valid && (value <= this._lessThanValue)
if ( this.useLessThan && typeof this.lessThanValue !== 'undefined' ) {
if ( this.lessThanBit ) {
isValid = isValid && (value <= this.lessThanValue)
} else {
is_valid = is_valid && (value < this._lessThanValue)
isValid = isValid && (value < this.lessThanValue)
}
}
if ( this._useGreaterThan && typeof this._greaterThanValue !== 'undefined' ) {
if ( this._greateerThanBit ) {
is_valid = is_valid && (value >= this._greaterThanValue)
if ( this.useGreaterThan && typeof this.greaterThanValue !== 'undefined' ) {
if ( this.greaterThanBit ) {
isValid = isValid && (value >= this.greaterThanValue)
} else {
is_valid = is_valid && (value > this._greaterThanValue)
isValid = isValid && (value > this.greaterThanValue)
}
}
if ( this._useWhitelist ) {
is_valid = is_valid && this._whitelist.some(x => {
if ( this.useWhitelist ) {
isValid = isValid && this.whitelistItems.some(x => {
return x === value
})
}
if ( this._useBlacklist ) {
is_valid = is_valid && !(this._blacklist.some(x => x === value))
if ( this.useBlacklist ) {
isValid = isValid && !(this.blacklistItems.some(x => x === value))
}
return is_valid
return isValid
}
/**
* Sets the Option as optional.
*/
optional() {
this._optional = true
optional(): this {
this.isOptional = true
return this
}
@@ -216,27 +223,27 @@ export abstract class CLIOption<T> {
* Get an array of strings denoting the human-readable requirements for this option to be valid.
* @returns {Array<string>}
*/
getRequirementDisplays() {
getRequirementDisplays(): string[] {
const clauses = []
if ( this._useBlacklist ) {
clauses.push(`must not be one of: ${this._blacklist.map(x => String(x)).join(', ')}`)
if ( this.useBlacklist ) {
clauses.push(`must not be one of: ${this.blacklistItems.map(x => String(x)).join(', ')}`)
}
if ( this._useWhitelist ) {
clauses.push(`must be one of: ${this._whitelist.map(x => String(x)).join(', ')}`)
if ( this.useWhitelist ) {
clauses.push(`must be one of: ${this.whitelistItems.map(x => String(x)).join(', ')}`)
}
if ( this._useGreaterThan ) {
clauses.push(`must be greater than${this._greateerThanBit ? ' or equal to' : ''}: ${String(this._greaterThanValue)}`)
if ( this.useGreaterThan ) {
clauses.push(`must be greater than${this.greaterThanBit ? ' or equal to' : ''}: ${String(this.greaterThanValue)}`)
}
if ( this._useLessThan ) {
clauses.push(`must be less than${this._lessThanBit ? ' or equal to' : ''}: ${String(this._lessThanValue)}`)
if ( this.useLessThan ) {
clauses.push(`must be less than${this.lessThanBit ? ' or equal to' : ''}: ${String(this.lessThanValue)}`)
}
if ( this._useEquality ) {
clauses.push(`must be equal to: ${String(this._equalityValue)}`)
if ( this.useEquality ) {
clauses.push(`must be equal to: ${String(this.equalityValue)}`)
}
return clauses

View File

@@ -1,4 +1,4 @@
import {CLIOption} from "./CLIOption"
import {CLIOption} from './CLIOption'
/**
* Non-positional, flag-based CLI option.
@@ -24,8 +24,10 @@ export class FlagOption<T> extends CLIOption<T> {
* Description of the argument required by this flag.
* If this is set, the flag will expect a positional argument to follow as a param.
*/
public readonly argumentDescription?: string
) { super() }
public readonly argumentDescription?: string,
) {
super()
}
/**
* Get the referential name for this option.
@@ -33,7 +35,7 @@ export class FlagOption<T> extends CLIOption<T> {
* be found, the short flag (without the '-') is used.
* @returns {string}
*/
getArgumentName() {
getArgumentName(): string {
if ( this.longFlag ) {
return this.longFlag.replace('--', '')
} else if ( this.shortFlag ) {

View File

@@ -1,4 +1,4 @@
import {CLIOption} from "./CLIOption"
import {CLIOption} from './CLIOption'
/**
* A positional CLI option. Defined without a flag.
@@ -19,14 +19,16 @@ export class PositionalOption<T> extends CLIOption<T> {
/**
* A usage message describing this parameter.
*/
public readonly message: string = ''
) { super() }
public readonly message: string = '',
) {
super()
}
/**
* Gets the name of the option.
* @returns {string}
*/
getArgumentName () {
getArgumentName(): string {
return this.name
}
}