Skip to content

Commit

Permalink
fix: 将内部方法增加$前缀
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Jan 29, 2021
1 parent 2066bc8 commit adad67a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class Cli {
// 0. load plugin
this.plugins = await this.resolvePlugins()
// 1. load project config and validate
await this.ConfigManager.loadUserConfig()
await this.ConfigManager.$loadUserConfig()
// 2. apply plugins
this.plugins.forEach(({ id, apply }) => {
// some skip plugins ??
apply(new PluginAPI(id, this), this.ConfigManager.projectConfig)
})
// 3. valid plugin config
// should after plugins apply because plugin can register config validator
this.ConfigManager.validatePluginConfig()
this.ConfigManager.$validatePluginConfig()
}

async resolvePlugins(): Promise<Plugin[]> {
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/PluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IConfigManager } from './manager/ConfigManager'
import type { IEnvManager } from './manager/EnvManager'
import type { IPathManager } from './manager/PathManager'
import type { CliInstance } from './Cli'
import type { ObjectSchema } from 'joi'

class PluginAPI {
id: string
Expand Down Expand Up @@ -43,6 +44,13 @@ class PluginAPI {
ops
}
}

registerConfigValidator<T = Record<string, any>>(
pluginConfigName: string,
schema: ObjectSchema<T>
): void {
this.ConfigManager.$addConfigValidator<T>(pluginConfigName, schema)
}
}

export type IPluginAPI = InstanceType<typeof PluginAPI>
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/src/manager/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class ConfigManager {
private PathManager: IPathManager

private finalConfig: ProjectConfig = {}
private userConfigIsLoaded = false

private configValidator: ConfigValidator = {}

registerConfigValidator<T = Record<string, any>>(
$addConfigValidator<T = Record<string, any>>(
name: string,
validator: ObjectSchema<T>
schema: ObjectSchema<T>
): void {
this.configValidator[name] = validator
this.configValidator[name] = schema
}

get projectConfig(): ProjectConfig {
Expand All @@ -27,7 +28,8 @@ class ConfigManager {
this.PathManager = pathManager
}

async loadUserConfig(): Promise<void> {
async $loadUserConfig(): Promise<void> {
if (this.userConfigIsLoaded) return
// 1. load userConfig
let userConfig: ProjectConfig
const [err, configContent] = await loadModule<ProjectConfig>(
Expand All @@ -49,9 +51,10 @@ class ConfigManager {
})

this.finalConfig = userConfig
this.userConfigIsLoaded = true
}

validatePluginConfig(): void {
$validatePluginConfig(): void {
// valid plugin config
const { pluginOps = null } = this.projectConfig
if (!pluginOps) return
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/manager/EnvManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createEnvName } from '../utils'
import { IPathManager } from './PathManager'

class EnvManager {
// path for load env file ??
private PathManager: IPathManager

constructor(pathManager: IPathManager) {
Expand Down

0 comments on commit adad67a

Please sign in to comment.