cloudfunctions/ClearingRedundantFolders/node_modules/@cloudbase/manager-node/src/environmentManager.ts

(完整代码) 1KB

import { Environment } from './environment'
import { ERROR } from './constant'
import { CloudBaseContext } from './context'

export class EnvironmentManager {
    private cloudBaseContext: CloudBaseContext

    private envs: object = {}

    private currentEnv: Environment = null

    constructor(context: CloudBaseContext) {
        this.cloudBaseContext = context
    }

    public getCurrentEnv(): Environment {
        if (!this.currentEnv) {
            throw new Error(ERROR.CURRENT_ENVIRONMENT_IS_NULL)
        }
        return this.currentEnv
    }

    public add(envId: string): void {
        if (!this.envs[envId]) {
            this.envs[envId] = new Environment(this.cloudBaseContext, envId)
        }
        if (!this.currentEnv) {
            this.currentEnv = this.envs[envId]
        }
    }

    public remove(envId: string): void {
        this.envs[envId] = null
        delete this.envs[envId]
    }

    public get(envId: string): Environment | null {
        return this.envs[envId] || null
    }

    public switchEnv(envId: string): boolean {
        const env = this.envs[envId]
        if (env) {
            this.currentEnv = env
            return true
        } else {
            return false
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。