Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export Config, Plugin at root & namespace interfaces #40

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
drop I naming
  • Loading branch information
RasPhilCo committed Sep 15, 2020
commit 4f2f942450eff7bdb78c5039b983507641e5658a
4 changes: 2 additions & 2 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default abstract class Command {
/** An order-dependent array of arguments for the command */
static args?: Parser.args.Input

static plugin: Interfaces.IPlugin | undefined
static plugin: Interfaces.Plugin | undefined

/** An array of example strings to show at the end of the command's help */
static examples: string[] | undefined
Expand All @@ -87,7 +87,7 @@ export default abstract class Command {

protected debug: (...args: any[]) => void

constructor(public argv: string[], public config: Interfaces.IConfig) {
constructor(public argv: string[], public config: Interfaces.Config) {
this.id = this.ctor.id
try {
this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin)
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as path from 'path'
import {URL} from 'url'
import {format} from 'util'

import {Options, IPlugin} from './interfaces/plugin'
import {IConfig, ArchTypes, PlatformTypes, LoadOptions} from './interfaces/config'
import {Options, Plugin as IPlugin} from './interfaces/plugin'
import {Config as IConfig, ArchTypes, PlatformTypes, LoadOptions} from './interfaces/config'
import {Command} from './interfaces/command'
import {Debug, mapValues} from './util'
import {Hook} from './interfaces/hooks'
Expand Down
7 changes: 0 additions & 7 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ try {
require('fs-extra-debug')
} catch {}

// export {IConfig, Config, Options, load, LoadOptions, PlatformTypes, ArchTypes} from './config'
export {Config, toCached} from './config'
// export {Command} from './interfaces/command'
// export {Hook, Hooks} from './interfaces/hooks'
// export {Manifest} from './interfaces/manifest'
// export {PJSON} from './interfaces/pjson'
export {Plugin} from './plugin'
// export {Topic} from './interfaces/topic'
export {tsPath} from './ts-node'

import * as Interfaces from './interfaces'
export {Interfaces}
// (a: Interfaces.HookKeyOrOptions) => {}
9 changes: 4 additions & 5 deletions src/config/interfaces/command.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as Parser from '../../parser'

import {IConfig, LoadOptions} from './config'
import {IPlugin} from './plugin'
// import {mapValues} from './util'
import {Config, LoadOptions} from './config'
import {Plugin} from './plugin'

export interface Command {
id: string;
Expand Down Expand Up @@ -66,10 +65,10 @@ export namespace Command {
}

export interface Class extends Base {
plugin?: IPlugin;
plugin?: Plugin;
flags?: Parser.flags.Input<any>;
args?: Parser.args.Input;
new(argv: string[], config: IConfig): Instance;
new(argv: string[], config: Config): Instance;
run(argv?: string[], config?: LoadOptions): PromiseLike<any>;
}

Expand Down
15 changes: 7 additions & 8 deletions src/config/interfaces/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {PJSON} from './pjson'
import {Hooks} from './hooks'
import {Command} from './command'
import {IPlugin, Options} from './plugin'
import {Plugin, Options} from './plugin'
import {Topic} from './topic'

export type LoadOptions = Options | string | IConfig | undefined
export type LoadOptions = Options | string | Config | undefined
export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' | 'wsl'
export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86'

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IConfig {
export interface Config {
name: string;
version: string;
channel: string;
Expand Down Expand Up @@ -86,7 +85,7 @@ export interface IConfig {
*/
npmRegistry?: string;
userPJSON?: PJSON.User;
plugins: IPlugin[];
plugins: Plugin[];
binPath?: string;
valid: boolean;
readonly commands: Command.Plugin[];
Expand All @@ -103,11 +102,11 @@ export interface IConfig {
scopedEnvVarKey(key: string): string;
scopedEnvVarTrue(key: string): boolean;
s3Url(key: string): string;
s3Key(type: 'versioned' | 'unversioned', ext: '.tar.gz' | '.tar.xz', options?: IConfig.s3Key.Options): string;
s3Key(type: keyof PJSON.S3.Templates, options?: IConfig.s3Key.Options): string;
s3Key(type: 'versioned' | 'unversioned', ext: '.tar.gz' | '.tar.xz', options?: Config.s3Key.Options): string;
s3Key(type: keyof PJSON.S3.Templates, options?: Config.s3Key.Options): string;
}

export namespace IConfig {
export namespace Config {
export namespace s3Key {
export interface Options {
platform?: PlatformTypes;
Expand Down
6 changes: 3 additions & 3 deletions src/config/interfaces/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Command} from './command'
import {IConfig} from './config'
import {Config} from './config'

export interface Hooks {
[event: string]: object;
Expand Down Expand Up @@ -32,7 +32,7 @@ export interface Hooks {
}

export type HookKeyOrOptions<K> = K extends (keyof Hooks) ? Hooks[K] : K
export type Hook<T> = (this: Hook.Context, options: HookKeyOrOptions<T> & {config: IConfig}) => any
export type Hook<T> = (this: Hook.Context, options: HookKeyOrOptions<T> & {config: Config}) => any

export namespace Hook {
export type Init = Hook<Hooks['init']>
Expand All @@ -44,7 +44,7 @@ export namespace Hook {
export type CommandNotFound = Hook<Hooks['command_not_found']>

export interface Context {
config: IConfig;
config: Config;
exit(code?: number): void;
error(message: string | Error, options?: {code?: string; exit?: number}): void;
warn(message: string): void;
Expand Down
4 changes: 2 additions & 2 deletions src/config/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {IConfig, ArchTypes, PlatformTypes, LoadOptions} from './config'
export {Config, ArchTypes, PlatformTypes, LoadOptions} from './config'
export {Command} from './command'
export {Hook, HookKeyOrOptions, Hooks} from './hooks'
export {Manifest} from './manifest'
export {PJSON} from './pjson'
export {IPlugin, PluginOptions, Options} from './plugin'
export {Plugin, PluginOptions, Options} from './plugin'
export {Topic} from './topic'
2 changes: 1 addition & 1 deletion src/config/interfaces/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Options extends PluginOptions {
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IPlugin {
export interface Plugin {
/**
* ../config version
*/
Expand Down
2 changes: 1 addition & 1 deletion src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Globby from 'globby'
import * as path from 'path'
import {inspect} from 'util'

import {IPlugin, PluginOptions} from './interfaces/plugin'
import {Plugin as IPlugin, PluginOptions} from './interfaces/plugin'
import {Command} from './interfaces/command'
import {toCached} from './config'
import {Debug} from './util'
Expand Down
4 changes: 2 additions & 2 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {IConfig} from './config/interfaces/config'
import {Config} from './config/interfaces/config'
import * as Parser from './parser'
import Command from './command'

export type ICompletionContext = {
args?: { [name: string]: string };
flags?: { [name: string]: string };
argv?: string[];
config: IConfig;
config: Config;
}

export type ICompletion = {
Expand Down
2 changes: 1 addition & 1 deletion src/help/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const wrap = require('wrap-ansi')
export default class CommandHelp {
render: (input: string) => string

constructor(public command: Config.Command, public config: Config.IConfig, public opts: HelpOptions) {
constructor(public command: Config.Command, public config: Config.Config, public opts: HelpOptions) {
this.render = template(this)
}

Expand Down
6 changes: 3 additions & 3 deletions src/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ function getHelpSubject(args: string[]): string | undefined {
}

export abstract class HelpBase {
constructor(config: Config.IConfig, opts: Partial<HelpOptions> = {}) {
constructor(config: Config.Config, opts: Partial<HelpOptions> = {}) {
this.config = config
this.opts = {maxWidth: stdtermwidth, ...opts}
}

protected config: Config.IConfig
protected config: Config.Config

protected opts: HelpOptions

Expand Down Expand Up @@ -95,7 +95,7 @@ export class Help extends HelpBase {
return topics
}

constructor(config: Config.IConfig, opts: Partial<HelpOptions> = {}) {
constructor(config: Config.Config, opts: Partial<HelpOptions> = {}) {
super(config, opts)
this.render = template(this)
}
Expand Down
2 changes: 1 addition & 1 deletion src/help/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
export default class RootHelp {
render: (input: string) => string

constructor(public config: Config.IConfig, public opts: HelpOptions) {
constructor(public config: Config.Config, public opts: HelpOptions) {
this.render = template(this)
}

Expand Down
2 changes: 1 addition & 1 deletion src/help/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashTemplate = require('lodash.template')

import {IConfig} from '../config/interfaces/config'
import {Config as IConfig} from '../config/interfaces/config'
import {Help, HelpBase, HelpOptions} from '.'
import * as Config from '../config'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {spy, SinonSpy} from 'sinon'
import {Interfaces, HelpBase} from '../../../../../src'

export type TestHelpClassConfig = Interfaces.IConfig & { showCommandHelpSpy?: SinonSpy; showHelpSpy?: SinonSpy }
export type TestHelpClassConfig = Interfaces.Config & { showCommandHelpSpy?: SinonSpy; showHelpSpy?: SinonSpy }

export default class extends HelpBase {
constructor(config: any, opts: any) {
Expand Down
4 changes: 2 additions & 2 deletions test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ describe('Config', () => {
expect(o).to.equal(expected)
})
},
hasProperty<K extends keyof Interfaces.IConfig>(k: K | undefined, v: Interfaces.IConfig[K] | undefined) {
hasProperty<K extends keyof Interfaces.Config>(k: K | undefined, v: Interfaces.Config[K] | undefined) {
return this
.it(`has ${k}=${v}`, config => expect(config).to.have.property(k!, v))
},
it(expectation: string, fn: (config: Interfaces.IConfig) => any) {
it(expectation: string, fn: (config: Interfaces.Config) => any) {
test
.do(({config}) => fn(config))
.it(expectation)
Expand Down
2 changes: 1 addition & 1 deletion test/config/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Interfaces} from '../../src/config'

export const fancy = base
.register('resetConfig', () => ({
run(ctx: {config: Interfaces.IConfig}) {
run(ctx: {config: Interfaces.Config}) {
delete ctx.config
},
}))
Expand Down
7 changes: 4 additions & 3 deletions test/help/format-root.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {expect, test as base, Config} from '@oclif/test'
import {expect, test as base} from '@oclif/test'
import stripAnsi = require('strip-ansi')

const g: any = global
g.columns = 80
import {Help} from '../../src/help'
import {Interfaces} from '../../src'

const VERSION = require('../../package.json').version
const UA = `@oclif/core/${VERSION} ${process.platform}-${process.arch} node-${process.version}`
Expand All @@ -17,8 +18,8 @@ class TestHelp extends Help {

const test = base
.loadConfig()
.register('rootHelp', (ctxOverride?: (config: Config.IConfig) => Config.IConfig) => ({
run(ctx: {config: Config.IConfig; help: Help; commandHelp: string; expectation: string}) {
.register('rootHelp', (ctxOverride?: (config: Interfaces.Config) => Interfaces.Config) => ({
run(ctx: { config: Interfaces.Config; help: Help; commandHelp: string; expectation: string}) {
const config = ctxOverride ? ctxOverride(ctx.config) : ctx.config

const help = new TestHelp(config as any)
Expand Down
2 changes: 1 addition & 1 deletion test/help/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {getHelpClass} from '../../src/help'
import configuredHelpClass from '../../src/help/_test-help-class'

describe('util', () => {
let config: Interfaces.IConfig
let config: Interfaces.Config

beforeEach(async () => {
config = await Config.load()
Expand Down