Skip to content

Commit

Permalink
refactor: rename GardenContext to Garden
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Apr 13, 2018
1 parent 1eb143d commit 64bce4f
Show file tree
Hide file tree
Showing 41 changed files with 106 additions and 106 deletions.
8 changes: 4 additions & 4 deletions src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import * as Rsync from "rsync"
import { GARDEN_DIR_NAME } from "./constants"
import { execRsyncCmd } from "./util"
import { Module } from "./types/module"
import { GardenContext } from "./context"
import { Garden } from "./garden"

// Lazily construct a directory of modules inside which all build steps are performed.

const buildDirRelPath = join(GARDEN_DIR_NAME, "build")

export class BuildDir {
buildDirPath: string
private ctx: GardenContext
private ctx: Garden

constructor(ctx: GardenContext) {
constructor(ctx: Garden) {
this.ctx = ctx
this.buildDirPath = join(ctx.projectRoot, buildDirRelPath)
}

// Synchronous, so it can run in GardenContext's constructor.
// Synchronous, so it can run in Garden's constructor.
init() {
ensureDirSync(this.buildDirPath)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "./commands/base"
import { ValidateCommand } from "./commands/validate"
import { InternalError, PluginError } from "./exceptions"
import { GardenContext } from "./context"
import { Garden } from "./garden"
import { FileWriter } from "./logger/writers"
import { getLogger, RootLogNode } from "./logger"
import { resolve } from "path"
Expand Down Expand Up @@ -277,7 +277,7 @@ export class GardenCli {
)
}

const ctx = await GardenContext.factory(root, { logger, plugins: defaultPlugins })
const ctx = await Garden.factory(root, { logger, plugins: defaultPlugins })
return command.action(ctx, argsForAction, optsForAction)
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { GardenContext } from "../context"
import { Garden } from "../garden"

export class ValidationError extends Error { }

Expand Down Expand Up @@ -132,5 +132,5 @@ export abstract class Command<T extends Parameters = {}, U extends Parameters =
// subclass implementations need to explicitly set the types in the implemented function signature. So for now we
// can't enforce the types of `args` and `opts` automatically at the abstract class level and have to specify
// the types explicitly on the subclassed methods.
abstract async action(ctx: GardenContext, args: ParameterValues<T>, opts: ParameterValues<U>): Promise<any>
abstract async action(ctx: Garden, args: ParameterValues<T>, opts: ParameterValues<U>): Promise<any>
}
4 changes: 2 additions & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { BooleanParameter, Command, ParameterValues, StringParameter } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { BuildTask } from "../tasks/build"
import { values } from "lodash"
import { TaskResults } from "../task-graph"
Expand All @@ -32,7 +32,7 @@ export class BuildCommand extends Command<typeof buildArguments, typeof buildOpt
arguments = buildArguments
options = buildOptions

async action(ctx: GardenContext, args: BuildArguments, opts: BuildOptions): Promise<TaskResults> {
async action(ctx: Garden, args: BuildArguments, opts: BuildOptions): Promise<TaskResults> {
await ctx.buildDir.clear()
const names = args.module ? args.module.split(",") : undefined
const modules = await ctx.getModules(names)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { resolve } from "url"
import Axios from "axios"
import chalk from "chalk"
import { Command, EnvironmentOption, ParameterValues, StringParameter } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { splitFirst } from "../util"
import { ParameterError, RuntimeError } from "../exceptions"
import { EntryStyle } from "../logger/types"
Expand Down Expand Up @@ -39,7 +39,7 @@ export class CallCommand extends Command<typeof callArgs> {
arguments = callArgs
options = options

async action(ctx: GardenContext, args: Args, opts: Opts) {
async action(ctx: Garden, args: Args, opts: Opts) {
opts.env && ctx.setEnvironment(opts.env)

let [serviceName, path] = splitFirst(args.serviceAndPath, "/")
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Command, EnvironmentOption, ParameterValues, StringParameter } from "../base"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"
import { NotFoundError } from "../../exceptions"

export const configDeleteArgs = {
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ConfigDeleteCommand extends Command<typeof configDeleteArgs, typeof
arguments = configDeleteArgs
options = configDeleteOpts

async action(ctx: GardenContext, args: DeleteArgs, opts: DeleteOpts) {
async action(ctx: Garden, args: DeleteArgs, opts: DeleteOpts) {
opts.env && ctx.setEnvironment(opts.env)
const res = await ctx.deleteConfig(args.key.split("."))

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Command, EnvironmentOption, ParameterValues, StringParameter } from "../base"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"

export const configGetArgs = {
key: new StringParameter({
Expand All @@ -34,7 +34,7 @@ export class ConfigGetCommand extends Command<typeof configGetArgs, typeof confi
arguments = configGetArgs
options = configGetOpts

async action(ctx: GardenContext, args: GetArgs, opts: GetOpts) {
async action(ctx: Garden, args: GetArgs, opts: GetOpts) {
opts.env && ctx.setEnvironment(opts.env)
const res = await ctx.getConfig(args.key.split("."))

Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Command, EnvironmentOption, ParameterValues, StringParameter } from "../base"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"

export const configSetArgs = {
key: new StringParameter({
Expand Down Expand Up @@ -38,7 +38,7 @@ export class ConfigSetCommand extends Command<typeof configSetArgs, typeof confi
arguments = configSetArgs
options = configSetOpts

async action(ctx: GardenContext, args: SetArgs, opts: SetOpts) {
async action(ctx: Garden, args: SetArgs, opts: SetOpts) {
opts.env && ctx.setEnvironment(opts.env)
await ctx.setConfig(args.key.split("."), args.value)
ctx.log.info(`Set config key ${args.key}`)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { BooleanParameter, Command, EnvironmentOption, ParameterValues, StringParameter } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { DeployTask } from "../tasks/deploy"
import { values } from "lodash"
import { Service } from "../types/service"
Expand Down Expand Up @@ -39,7 +39,7 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>
arguments = deployArgs
options = deployOpts

async action(ctx: GardenContext, args: Args, opts: Opts): Promise<TaskResults> {
async action(ctx: Garden, args: Args, opts: Opts): Promise<TaskResults> {
ctx.log.header({ emoji: "rocket", command: "Deploy" })

opts.env && ctx.setEnvironment(opts.env)
Expand All @@ -56,7 +56,7 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>
}

export async function deployServices(
ctx: GardenContext,
ctx: Garden,
services: Service<any>[],
force: boolean,
forceBuild: boolean,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Command, EnvironmentOption, ParameterValues } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { join } from "path"
import { STATIC_DIR } from "../constants"
import { spawnSync } from "child_process"
Expand All @@ -31,7 +31,7 @@ export class DevCommand extends Command<Opts> {

options = options

async action(ctx: GardenContext, _args, opts: Opts) {
async action(ctx: Garden, _args, opts: Opts) {
try {
spawnSync(imgcatPath, [bannerPath], {
stdio: "inherit",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/environment/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Command, EnvironmentOption, ParameterValues } from "../base"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"

export const options = {
env: new EnvironmentOption({
Expand All @@ -24,7 +24,7 @@ export class EnvironmentConfigureCommand extends Command<typeof options> {

options = options

async action(ctx: GardenContext, _args, opts: Opts) {
async action(ctx: Garden, _args, opts: Opts) {
opts.env && ctx.setEnvironment(opts.env)
const { name } = ctx.getEnvironment()
ctx.log.header({ emoji: "gear", command: `Configuring ${name} environment` })
Expand Down
6 changes: 3 additions & 3 deletions src/commands/environment/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { every, reduce } from "lodash"
import { Command, EnvironmentOption, ParameterValues } from "../base"
import { EntryStyle } from "../../logger/types"
import { EnvironmentStatus, EnvironmentStatusMap } from "../../types/plugin"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"
import { LogEntry } from "../../logger"
import { sleep } from "../../util"
import { TimeoutError } from "../../exceptions"
Expand All @@ -34,7 +34,7 @@ export class EnvironmentDestroyCommand extends Command {
alias = "d"
help = "Destroy environment"

async action(ctx: GardenContext, _args, opts: Opts) {
async action(ctx: Garden, _args, opts: Opts) {
opts.env && ctx.setEnvironment(opts.env)
const { name } = ctx.getEnvironment()
ctx.log.header({ emoji: "skull_and_crossbones", command: `Destroying ${name} environment` })
Expand Down Expand Up @@ -65,7 +65,7 @@ export class EnvironmentDestroyCommand extends Command {
return result
}

async waitForShutdown(ctx: GardenContext, name: string, logEntries: LogEntryMap) {
async waitForShutdown(ctx: Garden, name: string, logEntries: LogEntryMap) {
const startTime = new Date().getTime()
let result: EnvironmentStatusMap

Expand Down
4 changes: 2 additions & 2 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { BooleanParameter, Command, EnvironmentOption, ParameterValues, StringParameter } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import chalk from "chalk"
import { GetServiceLogsParams, ServiceLogEntry } from "../types/plugin"
import Bluebird = require("bluebird")
Expand Down Expand Up @@ -39,7 +39,7 @@ export class LogsCommand extends Command<typeof logsArgs, typeof logsOpts> {
arguments = logsArgs
options = logsOpts

async action(ctx: GardenContext, args: Args, opts: Opts) {
async action(ctx: Garden, args: Args, opts: Opts) {
opts.env && ctx.setEnvironment(opts.env)
const env = ctx.getEnvironment()
const names = args.service ? args.service.split(",") : undefined
Expand Down
4 changes: 2 additions & 2 deletions src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Bluebird = require("bluebird")
import { mapValues } from "lodash"
import * as yaml from "js-yaml"
import { Command, EnvironmentOption, ParameterValues } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { Service } from "../types/service"
import { highlightYaml } from "../util"

Expand All @@ -29,7 +29,7 @@ export class StatusCommand extends Command<typeof options> {

options = options

async action(ctx: GardenContext, _args, opts: Opts) {
async action(ctx: Garden, _args, opts: Opts) {
opts.env && ctx.setEnvironment(opts.env)

const envStatus = await ctx.getEnvironmentStatus()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { BooleanParameter, Command, EnvironmentOption, ParameterValues, StringParameter } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { values, padEnd } from "lodash"
import { TestTask } from "../tasks/test"
import { splitFirst } from "../util"
Expand Down Expand Up @@ -41,7 +41,7 @@ export class TestCommand extends Command<typeof testArgs, typeof testOpts> {
arguments = testArgs
options = testOpts

async action(ctx: GardenContext, args: Args, opts: Opts): Promise<TaskResults> {
async action(ctx: Garden, args: Args, opts: Opts): Promise<TaskResults> {
const names = args.module ? args.module.split(",") : undefined
const modules = await ctx.getModules(names)

Expand Down
4 changes: 2 additions & 2 deletions src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import { Command } from "./base"
import { GardenContext } from "../context"
import { Garden } from "../garden"

export class ValidateCommand extends Command {
name = "validate"
help = "Check your garden configuration for errors"

async action(ctx: GardenContext) {
async action(ctx: Garden) {

ctx.log.header({ emoji: "heavy_check_mark", command: "validate" })

Expand Down
4 changes: 2 additions & 2 deletions src/context.ts → src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const builtinPlugins: PluginFactory[] = [
() => new GenericModuleHandler(),
]

export class GardenContext {
export class Garden {
public buildDir: BuildDir
public readonly log: RootLogNode
public readonly actionHandlers: PluginActionMap
Expand Down Expand Up @@ -115,7 +115,7 @@ export class GardenContext {
})
}

const ctx = new GardenContext(projectRoot, projectConfig, logger)
const ctx = new Garden(projectRoot, projectConfig, logger)

// Load configured plugins
plugins = builtinPlugins.concat(plugins)
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { existsSync } from "fs"
import { join } from "path"
import { ConfigurationError } from "../exceptions"
import { BuildModuleParams, GetModuleBuildStatusParams, Plugin } from "../types/plugin"
import { GardenContext } from "../context"
import { Garden } from "../garden"
import { Service } from "../types/service"
import { DEFAULT_PORT_PROTOCOL } from "../constants"

Expand Down Expand Up @@ -121,7 +121,7 @@ export class ContainerService extends Service<ContainerModule> { }
export class ContainerModule<T extends ContainerModuleConfig = ContainerModuleConfig> extends Module<T> {
image?: string

constructor(ctx: GardenContext, config: T) {
constructor(ctx: Garden, config: T) {
super(ctx, config)

this.image = config.image
Expand All @@ -131,7 +131,7 @@ export class ContainerModule<T extends ContainerModuleConfig = ContainerModuleCo
return this.image || `${this.name}:${await this.getVersion()}`
}

async pullImage(ctx: GardenContext) {
async pullImage(ctx: Garden) {
const identifier = await this.getImageId()

if (!await this.imageExistsLocally()) {
Expand All @@ -156,7 +156,7 @@ export class ContainerModuleHandler implements Plugin<ContainerModule> {
name = "container-module"
supportedModuleTypes = ["container"]

async parseModule({ ctx, config }: { ctx: GardenContext, config: ContainerModuleConfig }) {
async parseModule({ ctx, config }: { ctx: Garden, config: ContainerModuleConfig }) {
config = validate(config, containerSchema, `module ${config.name}`)

const module = new ContainerModule(ctx, config)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/google/google-cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { identifierRegex, validate } from "../../types/common"
import { baseServiceSchema, Module, ModuleConfig } from "../../types/module"
import { GardenContext } from "../../context"
import { Garden } from "../../garden"
import { ServiceConfig, ServiceState, ServiceStatus } from "../../types/service"
import { resolve } from "path"
import * as Joi from "joi"
Expand Down Expand Up @@ -39,7 +39,7 @@ export class GoogleCloudFunctionsProvider extends GoogleCloudProviderBase<Google
name = "google-cloud-functions"
supportedModuleTypes = ["google-cloud-function"]

async parseModule({ ctx, config }: { ctx: GardenContext, config: GoogleCloudFunctionsModuleConfig }) {
async parseModule({ ctx, config }: { ctx: Garden, config: GoogleCloudFunctionsModuleConfig }) {
const module = new GoogleCloudFunctionsModule(ctx, config)

// TODO: check that each function exists at the specified path
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/kubernetes/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { GardenContext } from "../../context"
import { Garden } from "../../garden"
import { ContainerService } from "../container"

export async function createIngress(service: ContainerService, externalHostname: string) {
Expand Down Expand Up @@ -59,6 +59,6 @@ export function getProjectHostname() {
return "local.app.garden"
}

export function getServiceHostname(ctx: GardenContext, service: ContainerService) {
export function getServiceHostname(ctx: Garden, service: ContainerService) {
return `${service.name}.${ctx.projectName}.${getProjectHostname()}`
}
Loading

0 comments on commit 64bce4f

Please sign in to comment.