Skip to content

Commit

Permalink
refactor: changed build dependency copy specs config format
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Apr 22, 2018
1 parent 0fc60bd commit 608f963
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
import * as Rsync from "rsync"
import { GARDEN_DIR_NAME } from "./constants"
import { execRsyncCmd } from "./util"
import { Module } from "./types/module"
import {
BuildCopySpec,
Module,
} from "./types/module"

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

Expand Down Expand Up @@ -56,11 +59,9 @@ export class BuildDir {
}

// Sync to the module's top-level dir by default.
const destinationDir = depConfig.copyDestination || ""

return bluebirdMap(depConfig.copy, (relSourcePath) => {
const sourcePath = resolve(this.buildDirPath, depConfig.name, relSourcePath)
const destinationPath = dirname(resolve(buildPath, destinationDir, relSourcePath)) + sep
return bluebirdMap(depConfig.copy, (copy: BuildCopySpec) => {
const sourcePath = resolve(this.buildDirPath, depConfig.name, copy.source)
const destinationPath = dirname(resolve(buildPath, copy.target, copy.source)) + sep
return this.sync(sourcePath, destinationPath)
})
})
Expand Down
20 changes: 15 additions & 5 deletions src/types/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ import { resolveTemplateStrings, TemplateStringContext } from "../template-strin
import { Memoize } from "typescript-memoize"
import { TreeVersion } from "../vcs/base"

export interface BuildCopySpec {
source: string
target: string
}

// TODO: allow : delimited string (e.g. some.file:some-dir/)
const copySchema = Joi.object().keys({
// TODO: allow array of strings here
source: Joi.string().required(),
target: Joi.string().default(""),
})

export interface BuildDependencyConfig {
name: string,
copy?: string[],
copyDestination?: string // TODO: if we stick with this format, make mandatory if copy is provided
name: string
copy: BuildCopySpec[]
}

export interface BuildConfig {
Expand Down Expand Up @@ -151,8 +162,7 @@ export const baseTestSpecSchema = Joi.object().keys({

export const baseDependencySchema = Joi.object().keys({
name: joiIdentifier().required(),
copy: Joi.array(),
copyDestination: Joi.string(),
copy: Joi.array().items(copySchema).default(() => [], "[]"),
})

export const baseModuleSchema = Joi.object().keys({
Expand Down
11 changes: 6 additions & 5 deletions test/data/test-project-build-products/module-d/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ module:
dependencies:
- name: module-a
copy:
- a.txt
copyDestination: a
- source: a.txt
target: a
- name: module-b
copy:
- build/b1.txt
- build/build_subdir
copyDestination: b
- source: build/b1.txt
target: b
- source: build/build_subdir
target: b
4 changes: 2 additions & 2 deletions test/data/test-project-build-products/module-e/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module:
dependencies:
- name: module-d
copy:
- "build/d.txt"
copyDestination: d
- source: build/d.txt
target: d

0 comments on commit 608f963

Please sign in to comment.