Skip to content

Commit

Permalink
refactor: interfaces dir (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Sep 16, 2020
1 parent 9b1d2a8 commit 10d3de9
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 56 deletions.
3 changes: 2 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {format, inspect} from 'util'

import {Interfaces, Config, toCached} from './config'
import {Config, toCached} from './config'
import * as Interfaces from './interfaces'
import * as Errors from './errors'
import {PrettyPrintableError} from './errors'
import * as Parser from './parser'
Expand Down
12 changes: 6 additions & 6 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import * as path from 'path'
import {URL} from 'url'
import {format} from 'util'

import {Options, Plugin as IPlugin} from './interfaces/plugin'
import {Config as IConfig, ArchTypes, PlatformTypes, LoadOptions} from './interfaces/config'
import {Command} from './interfaces/command'
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'
import {PJSON} from './interfaces/pjson'
import {Hook} from '../interfaces/hooks'
import {PJSON} from '../interfaces/pjson'
import * as Plugin from './plugin'
import {Topic} from './interfaces/topic'
import {Topic} from '../interfaces/topic'
import {tsPath} from './ts-node'
import {compact, flatMap, loadJSON, uniq} from './util'

Expand Down
2 changes: 0 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ export {Config, toCached} from './config'
export {Plugin} from './plugin'
export {tsPath} from './ts-node'

import * as Interfaces from './interfaces'
export {Interfaces}
10 changes: 5 additions & 5 deletions src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as Globby from 'globby'
import * as path from 'path'
import {inspect} from 'util'

import {Plugin as IPlugin, PluginOptions} from './interfaces/plugin'
import {Command} from './interfaces/command'
import {Plugin as IPlugin, PluginOptions} from '../interfaces/plugin'
import {Command} from '../interfaces/command'
import {toCached} from './config'
import {Debug} from './util'
import {Manifest} from './interfaces/manifest'
import {PJSON} from './interfaces/pjson'
import {Topic} from './interfaces/topic'
import {Manifest} from '../interfaces/manifest'
import {PJSON} from '../interfaces/pjson'
import {Topic} from '../interfaces/topic'
import {tsPath} from './ts-node'
import {compact, exists, flatMap, loadJSON, mapValues} from './util'

Expand Down
2 changes: 1 addition & 1 deletion src/flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Config} from './config/interfaces/config'
import {Config} from './interfaces/config'
import * as Parser from './parser'
import Command from './command'

Expand Down
14 changes: 7 additions & 7 deletions src/help/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Interfaces as Config} from '../config'
import * as Chalk from 'chalk'
import indent = require('indent-string')
import stripAnsi = require('strip-ansi')
Expand All @@ -7,6 +6,7 @@ import {HelpOptions} from '.'
import {renderList} from './list'
import {castArray, compact, sortBy} from '../util'
import {template} from './util'
import * as Interfaces from '../interfaces'

const {
underline,
Expand All @@ -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.Config, public opts: HelpOptions) {
constructor(public command: Interfaces.Command, public config: Interfaces.Config, public opts: HelpOptions) {
this.render = template(this)
}

Expand All @@ -50,7 +50,7 @@ export default class CommandHelp {
return output
}

protected usage(flags: Config.Command.Flag[]): string {
protected usage(flags: Interfaces.Command.Flag[]): string {
const usage = this.command.usage
const body = (usage ? castArray(usage) : [this.defaultUsage(flags)])
.map(u => `$ ${this.config.bin} ${u}`.trim())
Expand All @@ -61,7 +61,7 @@ export default class CommandHelp {
].join('\n')
}

protected defaultUsage(_: Config.Command.Flag[]): string {
protected defaultUsage(_: Interfaces.Command.Flag[]): string {
return compact([
this.command.id,
this.command.args.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
Expand Down Expand Up @@ -96,7 +96,7 @@ export default class CommandHelp {
].join('\n')
}

protected args(args: Config.Command['args']): string | undefined {
protected args(args: Interfaces.Command['args']): string | undefined {
if (args.filter(a => a.description).length === 0) return
const body = renderList(args.map(a => {
const name = a.name.toUpperCase()
Expand All @@ -111,13 +111,13 @@ export default class CommandHelp {
].join('\n')
}

protected arg(arg: Config.Command['args'][0]): string {
protected arg(arg: Interfaces.Command['args'][0]): string {
const name = arg.name.toUpperCase()
if (arg.required) return `${name}`
return `[${name}]`
}

protected flags(flags: Config.Command.Flag[]): string | undefined {
protected flags(flags: Interfaces.Command.Flag[]): string | undefined {
if (flags.length === 0) return
const body = renderList(flags.map(flag => {
let left = flag.helpLabel
Expand Down
30 changes: 15 additions & 15 deletions src/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Chalk from 'chalk'
import indent = require('indent-string')
import stripAnsi = require('strip-ansi')

import {Interfaces as Config} from '../config'
import * as Interfaces from '../interfaces'
import {error} from '../errors'
import CommandHelp from './command'
import {renderList} from './list'
Expand Down Expand Up @@ -36,12 +36,12 @@ function getHelpSubject(args: string[]): string | undefined {
}

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

protected config: Config.Config
protected config: Interfaces.Config

protected opts: HelpOptions

Expand All @@ -56,20 +56,20 @@ export abstract class HelpBase {
* @param command
* @param topics
*/
public abstract showCommandHelp(command: Config.Command, topics: Config.Topic[]): void;
public abstract showCommandHelp(command: Interfaces.Command, topics: Interfaces.Topic[]): void;
}

export class Help extends HelpBase {
render: (input: string) => string

/*
* _topics is to work around Config.topics mistakenly including commands that do
* _topics is to work around Interfaces.topics mistakenly including commands that do
* not have children, as well as topics. A topic has children, either commands or other topics. When
* this is fixed upstream config.topics should return *only* topics with children,
* and this can be removed.
*/
private get _topics(): Config.Topic[] {
return this.config.topics.filter((topic: Config.Topic) => {
private get _topics(): Interfaces.Topic[] {
return this.config.topics.filter((topic: Interfaces.Topic) => {
// it is assumed a topic has a child if it has children
const hasChild = this.config.topics.some(subTopic => subTopic.name.includes(`${topic.name}:`))
return hasChild
Expand All @@ -95,7 +95,7 @@ export class Help extends HelpBase {
return topics
}

constructor(config: Config.Config, opts: Partial<HelpOptions> = {}) {
constructor(config: Interfaces.Config, opts: Partial<HelpOptions> = {}) {
super(config, opts)
this.render = template(this)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export class Help extends HelpBase {
error(`command ${subject} not found`)
}

public showCommandHelp(command: Config.Command) {
public showCommandHelp(command: Interfaces.Command) {
const name = command.id
const depth = name.split(':').length

Expand Down Expand Up @@ -171,7 +171,7 @@ export class Help extends HelpBase {
}
}

protected showTopicHelp(topic: Config.Topic) {
protected showTopicHelp(topic: Interfaces.Topic) {
const name = topic.name
const depth = name.split(':').length

Expand All @@ -196,12 +196,12 @@ export class Help extends HelpBase {
return help.root()
}

protected formatCommand(command: Config.Command): string {
protected formatCommand(command: Interfaces.Command): string {
const help = new CommandHelp(command, this.config, this.opts)
return help.generate()
}

protected formatCommands(commands: Config.Command[]): string {
protected formatCommands(commands: Interfaces.Command[]): string {
if (commands.length === 0) return ''

const body = renderList(commands.map(c => [
Expand All @@ -219,7 +219,7 @@ export class Help extends HelpBase {
].join('\n')
}

protected formatTopic(topic: Config.Topic): string {
protected formatTopic(topic: Interfaces.Topic): string {
let description = this.render(topic.description || '')
const title = description.split('\n')[0]
description = description.split('\n').slice(1).join('\n')
Expand All @@ -238,7 +238,7 @@ export class Help extends HelpBase {
return output + '\n'
}

protected formatTopics(topics: Config.Topic[]): string {
protected formatTopics(topics: Interfaces.Topic[]): string {
if (topics.length === 0) return ''
const body = renderList(topics.map(c => [
c.name,
Expand All @@ -259,7 +259,7 @@ export class Help extends HelpBase {
* @param {object} command The command to generate readme help for
* @return {string} the readme help string for the given command
*/
protected command(command: Config.Command) {
protected command(command: Interfaces.Command) {
return this.formatCommand(command)
}
}
4 changes: 2 additions & 2 deletions src/help/root.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Interfaces as Config} from '../config'
import * as Chalk from 'chalk'
import indent = require('indent-string')
import stripAnsi = require('strip-ansi')

import {HelpOptions} from '.'
import {compact} from '../util'
import {template} from './util'
import * as Interfaces from '../interfaces'

const wrap = require('wrap-ansi')
const {
Expand All @@ -15,7 +15,7 @@ const {
export default class RootHelp {
render: (input: string) => string

constructor(public config: Config.Config, public opts: HelpOptions) {
constructor(public config: Interfaces.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 {Config as IConfig} from '../config/interfaces/config'
import {Config as IConfig} from '../interfaces/config'
import {Help, HelpBase, HelpOptions} from '.'
import * as Config from '../config'

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as semver from 'semver'

import Command from './command'
import {run} from './main'
import {Config, Plugin, tsPath, toCached, Interfaces} from './config'
import {Config, Plugin, tsPath, toCached} from './config'
import * as Interfaces from './interfaces'
import * as Errors from './errors'
import * as Flags from './flags'
import {HelpBase, Help, getHelpClass} from './help'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Parser from '../../parser'
import * as Parser from '../parser'

import {Config, LoadOptions} from './config'
import {Plugin} from './plugin'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Interfaces as Config} from './config'
import * as Interfaces from './interfaces'
import {HelpBase, getHelpClass} from './help'
import Command from './command'

const ROOT_INDEX_CMD_ID = ''

export class Main extends Command {
static run(argv = process.argv.slice(2), options?: Config.LoadOptions) {
static run(argv = process.argv.slice(2), options?: Interfaces.LoadOptions) {
return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname)
}

Expand Down Expand Up @@ -48,6 +48,6 @@ export class Main extends Command {
}
}

export function run(argv = process.argv.slice(2), options?: Config.LoadOptions) {
export function run(argv = process.argv.slice(2), options?: Interfaces.LoadOptions) {
return Main.run(argv, options)
}
2 changes: 1 addition & 1 deletion test/config/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from 'os'
import * as path from 'path'

import {Config, Interfaces} from '../../src/config'
import {Config, Interfaces} from '../../src'
import * as util from '../../src/config/util'

import {expect, fancy} from './test'
Expand Down
2 changes: 1 addition & 1 deletion test/config/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, fancy as base, FancyTypes} from 'fancy-test'

import {Interfaces} from '../../src/config'
import {Interfaces} from '../../src'

export const fancy = base
.register('resetConfig', () => ({
Expand Down
5 changes: 3 additions & 2 deletions test/help/format-root.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 g: any = global
g.columns = 80

const VERSION = require('../../package.json').version
const UA = `@oclif/core/${VERSION} ${process.platform}-${process.arch} node-${process.version}`

Expand Down
5 changes: 3 additions & 2 deletions test/help/format-topic.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Interfaces} from '../../src/config'
import {expect, test as base} from '@oclif/test'
import stripAnsi = require('strip-ansi')

import {Help} from '../../src/help'
import {Interfaces} from '../../src'

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

// extensions to expose method as public for testing
class TestHelp extends Help {
Expand Down
5 changes: 3 additions & 2 deletions test/help/format-topics.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Interfaces} from '../../src/config'
import {expect, test as base} from '@oclif/test'
import stripAnsi = require('strip-ansi')

import {Help} from '../../src/help'
import {Interfaces} from '../../src'

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

// extensions to expose method as public for testing
class TestHelp extends Help {
Expand Down
7 changes: 4 additions & 3 deletions test/help/show-help.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Interfaces, Config} from '../../src/config'
import {expect, test as base} from '@oclif/test'
import {stub, SinonStub} from 'sinon'
import * as path from 'path'

const g: any = global
g.columns = 80
import {Help} from '../../src/help'
import {AppsIndex, AppsDestroy, AppsCreate, AppsTopic, AppsAdminTopic, AppsAdminAdd, AppsAdminIndex, DbCreate, DbTopic} from './fixtures/fixtures'
import {Interfaces, Config} from '../../src'

const g: any = global
g.columns = 80

// extension makes previously protected methods public
class TestHelp extends Help {
Expand Down

0 comments on commit 10d3de9

Please sign in to comment.