Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"bugs": "https://github.com/heroku/cli-engine-config/issues",
"dependencies": {},
"devDependencies": {
"@cli-engine/util": "^1.0.9",
"@heroku-cli/tslint": "^1.0.3",
"@types/jest": "22.0.0",
"@cli-engine/util": "^1.1.5",
"@heroku-cli/tslint": "^1.1.4",
"@types/jest": "22.0.1",
"@types/mock-fs": "^3.6.30",
"@types/node": "8.5.2",
"@types/node": "9.3.0",
"@types/read-pkg": "^3.0.0",
"@types/semver": "^5.4.0",
"ajv-cli": "^2.1.0",
"cli-flags": "2.0.7",
Expand All @@ -19,7 +20,8 @@
"jest": "^22.0.4",
"mock-fs": "^4.4.2",
"prettier": "^1.9.2",
"ts-jest": "22.0.0",
"rxjs": "^5.5.6",
"ts-jest": "22.0.1",
"tslib": "^1.8.1",
"tslint": "^5.8.0",
"typescript": "2.6.2"
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import * as os from 'os'
import * as path from 'path'
import {deprecate, inspect} from 'util'

import {IEngine} from './engine'
import * as Types from './types'

export * from './types'

export class Config {
readonly engine: IEngine
_version = require('../package.json').version

constructor (protected opts: Types.ConfigOptions = {}) {
Expand Down Expand Up @@ -57,7 +59,7 @@ export class Config {
name: 'cli-engine',
version: '0.0.0',
...(this.opts.pjson || {}),
}
} as Types.ICLIPJSON
}

@memoize()
Expand Down
39 changes: 39 additions & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Observable } from 'rxjs/Observable'

import { Hooks } from './hooks'
import { ICommand, IPlugin, ITopic } from './types'

export interface IUserPluginInstallOpts {
type: 'user'
name: string
tag?: string
}
export interface ILinkPluginInstallOpts {
type: 'link'
root: string
}

export interface IPluginManager {
readonly plugins: Observable<IPlugin>

install(opts: IUserPluginInstallOpts | ILinkPluginInstallOpts): Promise<void>
uninstall(name: string): Promise<boolean>
update(): Promise<void>
}

export interface IEngine extends ICommand {
readonly hooks: Hooks
readonly plugins: IPluginManager

readonly topics: Promise<ITopic[]>
readonly commands: Promise<ICommand[]>
readonly commandIDs: Promise<string[]>
readonly rootTopics: Promise<ITopic[]>
readonly rootCommands: Promise<ICommand[]>

findCommand(id: string, must: true): Promise<ICommand>
findCommand(id: string, must?: boolean): Promise<ICommand | undefined>

findTopic(id: string, must: true): Promise<ITopic>
findTopic(id: string, must?: boolean): Promise<ITopic | undefined>
}
25 changes: 25 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Config from './config'
import { ICommand, IPluginModule, IPluginPJSON } from './types'

export interface IHooks {
init: {}
update: {}
'plugins:parse': {
module: IPluginModule
pjson: IPluginPJSON
}
prerun: {
Command: ICommand
argv: string[]
}
}

export abstract class Hook<T extends keyof IHooks> {
protected readonly debug = require('debug')(`cli:hook:${this.options.event}`)
constructor(protected config: Config, protected options: IHooks[T] & { event: T }) {}
public abstract run(): Promise<void>
}

export interface Hooks {
run<T extends keyof IHooks>(event: T, options?: IHooks[T]): Promise<void>
}
42 changes: 29 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import { args, flags } from 'cli-flags'
import { Package } from 'read-pkg'

import { Config } from './config'

export * from './hooks'
export * from './engine'

export interface IPluginModuleTopic {
name: string
description?: string
subtopics?: { [k: string]: IPluginModuleTopic }
hidden?: boolean
}
export interface IPluginModule {
commands: ICommand[]
topic?: IPluginModuleTopic
topics: IPluginModuleTopic[]
}
export interface IPluginPJSON extends Package {
name: string
version: string
'cli-engine': {
commands?: string
topics?: { [k: string]: ITopic }
}
}
export interface ITopics {
[name: string]: ITopic
}
export interface ITopic {
name: string
description?: string
hidden?: boolean
subtopics?: ITopics
Expand All @@ -30,7 +54,7 @@ export interface ICLI {
userPluginsEnabled?: boolean
}

export interface ICLIPJSON {
export interface ICLIPJSON extends Package {
name: string
version: string
dependencies: { [name: string]: string }
Expand Down Expand Up @@ -60,21 +84,13 @@ export interface IPlugin {
}

export interface ICommand {
topic?: string
command?: string
description?: string
id?: string
hidden: boolean
usage?: string
help?: string
_version: string
id: string
base: '@cli-engine/command@1.0.0'
aliases: string[]
buildHelp: (config: Config) => string
buildHelpLine: (config: Config) => [string, string | undefined]
args?: args.IArg[]
flags?: flags.Input
help: (config: Config) => string
helpLine: (config: Config) => [string, string | undefined]
run: (argv: string[], config: Config) => Promise<any>
plugin?: IPlugin
}

export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos'
Expand Down
Loading