From b0e6b372140c1a80a7b2401504e03020b470562a Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Mon, 15 Jan 2018 19:31:27 -0800 Subject: [PATCH] fix: add isIConfig checker --- src/config.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/config.ts b/src/config.ts index a5f38ebb..7cf65e9c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -17,20 +17,21 @@ export interface IConfigBase { arch: string bin: string cacheDir: string + commandsDir: string | undefined configDir: string dataDir: string dirname: string errlog: string home: string + hooks: {[k: string]: string[]} name: string pjson: IPluginPJSON | ICLIPJSON platform: string shell: string - windows: boolean - commandsDir: string | undefined - userAgent: string tsconfig: TSConfig | undefined - hooks: {[k: string]: string[]} + userAgent: string + version: string + windows: boolean } export interface IPluginConfig extends IConfigBase { @@ -54,6 +55,11 @@ export interface TSConfig { } } +export interface ConfigOptions { + name?: string + root?: string +} + const debug = require('debug')('@dxcli/config') export abstract class ConfigBase implements IConfigBase { @@ -227,7 +233,7 @@ export abstract class ConfigBase implements IConfigBase { } export class PluginConfig extends ConfigBase implements IPluginConfig { - static async create({name, root = __dirname}: {name?: string, root?: string}) { + static async create({name, root = __dirname}: ConfigOptions) { const config = new this() await config.load({root, name}) return config @@ -238,7 +244,7 @@ export class PluginConfig extends ConfigBase implements IPluginConfig { } export class CLIConfig extends ConfigBase implements ICLIConfig { - static async create({engine, name, root = __dirname}: {engine: IEngine, name?: string, root?: string}) { + static async create({engine, name, root = __dirname}: ConfigOptions & {engine: IEngine}) { const config = new this(engine) await config.load({name, root}) return config @@ -286,3 +292,7 @@ async function findRootByName(name: string | undefined, root: string) { } return root } + +export function isIConfig(o: any): o is IConfig { + return !!o._base +}