Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: add isIConfig checker
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 16, 2018
1 parent 22480a8 commit b0e6b37
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit b0e6b37

Please sign in to comment.