Skip to content

Commit

Permalink
fix: 去除ctx设置能力统一采用cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Feb 24, 2021
1 parent 2b776d1 commit e5714e0
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 23 deletions.
1 change: 0 additions & 1 deletion packages/cli/src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CliService } from '@xus/core'
import presetBuiltIn from '@xus/preset-built-in'

type IXUSCliServiceOps = {
ctxPath: string
mode: string
}

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/xus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const rawArgs = process.argv.slice(2)
const args = minimist(rawArgs)
const commandName = args._[0]
const ops = {
ctxPath: process.env.XUS_CLI_CONTEXT || process.cwd(),
mode: args?.mode || 'development'
}
const cli = new XUSCliService(ops)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cli/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CliService {
logger.debug(ops)
// 1. init manager
this.setStage(CliServiceStage.initManager)
this.PathManager = new PathManager(ops.ctxPath)
this.PathManager = new PathManager()
this.EnvManager = new EnvManager({
service: this,
mode: ops.mode
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createSchema, validateSchema } from '@xus/cli-shared'

export const ProjectConfigSchema = createSchema<IProjectConfig>((joi) => {
return joi.object({
ctxPath: joi.string(),
mode: joi.string(),
plugins: joi.array(),
presets: joi.array()
Expand All @@ -23,7 +22,6 @@ export function defaultProjectConfig(
): IProjectConfig {
return {
...ops,
ctxPath: ops?.ctxPath || process.cwd(),
mode: ops?.mode || 'development'
}
}
3 changes: 1 addition & 2 deletions packages/core/src/manager/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class ConfigManager {

this.finalConfig = deepmerge(
defaultProjectConfig({
ctxPath: this.service.PathManager.cwd,
mode: this.service.EnvManager.mode
}),
this.loadUserConfig()
Expand Down Expand Up @@ -89,7 +88,7 @@ export class ConfigManager {
// valid plugin config
for (const [pluginName, pluginValidator] of this.pluginValidators) {
if (pluginName in this.finalConfig) {
pluginValidator!(this.finalConfig, (msg) => {
pluginValidator!(this.finalConfig[pluginName], (msg) => {
logger.error(`project config invalid ${msg}`)
process.exit(1)
})
Expand Down
13 changes: 4 additions & 9 deletions packages/core/src/manager/PathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import { statSync, readdirSync } from 'fs'
import { getFileMeta, isLernaPkg } from '@xus/cli-shared'

export class PathManager {
private ctxPath: string
constructor(ctx: string) {
this.ctxPath = ctx
}

get cwd(): string {
return this.ctxPath || process.cwd()
return process.cwd()
}

get cwdPkg() {
Expand All @@ -18,18 +13,18 @@ export class PathManager {

get userConfigPath() {
const fileMeta = getFileMeta({
base: this.ctxPath,
base: this.cwd,
filenameWithoutExt: 'xus.config'
})
return fileMeta && fileMeta.path
}

// for plugins
getPathBasedOnCtx(basedOnRoot: string): string {
return join(this.ctxPath, basedOnRoot)
return join(this.cwd, basedOnRoot)
}

getLernaPkgs({ root = this.ctxPath, isRelativeCwd = false } = {}): string[] {
getLernaPkgs({ root = this.cwd, isRelativeCwd = false } = {}): string[] {
const pkgRoot = join(root, 'packages')
if (isLernaPkg(root) && statSync(pkgRoot).isDirectory()) {
return (readdirSync(pkgRoot) || []).reduce<string[]>(
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { IPlugin, IPreset } from './plugin'

// cli server ops
export type ICliServerOps = {
ctxPath: string
mode: string
presets?: IPreset[]
plugins?: IPlugin[]
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { IPlugin, IPreset } from '.'

export interface IProjectConfig {
/**
* @description cwd or point path
*/
ctxPath: string
/**
* @description mode
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/types/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { IPluginAPI } from '../cli/PluginAPI'
import type { IConfigSchemaValidator } from '@xus/cli-shared'

// plugins / presets
// api type override in @xus/cli
export type IPluginApply = (api: IPluginAPI) => void
export type IPluginApply = (api: any) => void
type IEnforce = 'post' | 'pre'

export interface IPlugin<T extends (api: any) => void = IPluginApply> {
Expand Down

0 comments on commit e5714e0

Please sign in to comment.