Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli issue 1234 #212

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import { MacroVar } from './'

export enum ConfigTypes {
Build = 'buildConfig',
Service = 'serviceConfig',
Job = 'jobConfig',
Test = 'testConfig',
Doc = 'docConfig',
Deploy = 'deployConfig',
Stream = 'streamConfig',
Auth = 'authConfig'
}

export interface Config {
macroVars: MacroVar
initProgram: string
termProgram: string
}

export interface BuildConfig extends Config {
buildOutputFileName: string
buildOutputFolder?: string
buildResultsFolder?: string
}

export interface ServiceConfig extends Config {
serviceFolders: string[]
}

export interface JobConfig extends Config {
jobFolders: string[]
}

export interface TestConfig extends Config {
testSetUp: string
testTearDown: string
}

export interface DocConfig {
displayMacroCore?: boolean
enableLineage?: boolean
Expand All @@ -36,10 +52,12 @@ export interface DocConfig {
path?: string
}
}

export interface DeployConfig {
deployServicePack: boolean
deployScripts: string[]
}

export interface StreamConfig {
assetPaths: string[]
streamWeb: boolean
Expand All @@ -48,6 +66,7 @@ export interface StreamConfig {
streamServiceName: string
streamLogo?: string
}

export interface AuthConfig {
access_token: string
refresh_token: string
Expand Down
123 changes: 123 additions & 0 deletions src/types/target.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,127 @@ describe('Target', () => {
expect(json.serverName).toEqual(target.serverName)
expect(json.repositoryName).toEqual(target.repositoryName)
})

it('should combine configuration and target configs', () => {
const defaultConfig = { initProgram: '', macroVars: {}, termProgram: '' }

const configurationBuildConfig = {
buildOutputFileName: 'test',
...defaultConfig
}
const targetBuildConfig = {
buildOutputFolder: 'test',
buildResultsFolder: 'test'
}

const targetServiceConfig = {
serviceFolders: []
}

const configurationJobConfig = { ...defaultConfig, jobFolders: [] }

const configurationTestConfig = {
...defaultConfig,
testSetUp: 'confTest',
testTearDown: 'confTest'
}
const targetTestConfig = {
testSetUp: 'targetTest'
}

const targetDocConfig = {
displayMacroCore: true,
enableLineage: false,
outDirectory: 'test',
dataControllerUrl: 'https://test',
doxyContent: {
favIcon: 'test',
footer: 'test',
header: 'test',
layout: 'test',
logo: 'test',
readMe: 'test',
stylesheet: 'test',
path: 'test'
}
}

const configurationDeployConfig = {
deployServicePack: true,
deployScripts: []
}

const configurationStreamConfig = {
assetPaths: [],
streamLogo: 'assets/angular-logo.png',
streamServiceName: 'Angular',
streamWeb: false,
streamWebFolder: 'web',
webSourcePath: 'dist'
}
const targetStreamConfig = {
streamWeb: true
}

const configurationAuthConfig = {
access_token: 'confTest',
refresh_token: 'confTest',
client: 'confTest',
secret: 'confTest'
}
const targetAuthConfig = {
access_token: 'targetTest',
refresh_token: 'targetTest',
client: 'targetTest',
secret: 'targetTest'
}

const target = new Target(
{
name: 'test',
serverUrl: '',
serverType: ServerType.Sas9,
appLoc: '/test',
serverName: 'Test Server',
repositoryName: 'Test Repository',
streamConfig: targetStreamConfig,
buildConfig: targetBuildConfig,
serviceConfig: targetServiceConfig,
testConfig: targetTestConfig,
docConfig: targetDocConfig,
authConfig: targetAuthConfig
},
{
streamConfig: configurationStreamConfig,
buildConfig: configurationBuildConfig,
jobConfig: configurationJobConfig,
testConfig: configurationTestConfig,
deployConfig: configurationDeployConfig,
authConfig: configurationAuthConfig
}
)

const json = target.toJson()

expect(json.streamConfig).toEqual({
...configurationStreamConfig,
...targetStreamConfig
})
expect(json.buildConfig).toEqual({
...configurationBuildConfig,
...targetBuildConfig
})
expect(json.serviceConfig).toEqual({
...defaultConfig,
...targetServiceConfig
})
expect(json.jobConfig).toEqual(configurationJobConfig)
expect(json.testConfig).toEqual({
...configurationTestConfig,
...targetTestConfig
})
expect(json.docConfig).toEqual(targetDocConfig)
expect(json.deployConfig).toEqual(configurationDeployConfig)
expect(json.authConfig).toEqual(targetAuthConfig)
})
})
51 changes: 41 additions & 10 deletions src/types/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
JobConfig,
StreamConfig,
TestConfig,
SyncDirectoryMap
SyncDirectoryMap,
ConfigTypes
} from './config'
import { ServerType } from './serverType'
import { HttpsAgentOptions } from './httpsAgentOptions'
Expand All @@ -33,6 +34,7 @@ import {
validateSyncFolder,
validateSyncDirectories
} from './targetValidators'
import { Configuration } from '../types/configuration'

export interface TargetJson {
name: string
Expand Down Expand Up @@ -60,6 +62,8 @@ export interface TargetJson {
}

export class Target implements TargetJson {
private _config

get name(): string {
return this._name
}
Expand Down Expand Up @@ -170,12 +174,13 @@ export class Target implements TargetJson {
}
private _syncDirectories: SyncDirectoryMap[] | undefined

constructor(json: any) {
constructor(json: any, config: Configuration = {}) {
try {
if (!json) {
throw new Error('Invalid target: Input JSON is null or undefined.')
}

this._config = config
this._name = validateTargetName(json.name)
this._serverUrl = validateServerUrl(json.serverUrl)
this._serverType = validateServerType(json.serverType)
Expand All @@ -195,23 +200,32 @@ export class Target implements TargetJson {
)

if (json.docConfig) {
this._docConfig = validateDocConfig(json.docConfig)
this._docConfig = validateDocConfig(
this.getConfig(ConfigTypes.Doc, json)
)
}

if (json.authConfig) {
this._authConfig = validateAuthConfig(json.authConfig)
this._authConfig = validateAuthConfig(
this.getConfig(ConfigTypes.Auth, json)
)
}

if (json.authConfigSas9) {
this._authConfigSas9 = validateAuthConfigSas9(json.authConfigSas9)
}

if (json.buildConfig) {
this._buildConfig = validateBuildConfig(json.buildConfig, this._name)
this._buildConfig = validateBuildConfig(
this.getConfig(ConfigTypes.Build, json),
this._name
)
}

if (json.deployConfig) {
this._deployConfig = validateDeployConfig(json.deployConfig)
this._deployConfig = validateDeployConfig(
this.getConfig(ConfigTypes.Deploy, json)
)
} else {
this._deployConfig = validateDeployConfig({
deployServicePack: true,
Expand All @@ -220,19 +234,27 @@ export class Target implements TargetJson {
}

if (json.serviceConfig) {
this._serviceConfig = validateServiceConfig(json.serviceConfig)
this._serviceConfig = validateServiceConfig(
this.getConfig(ConfigTypes.Service, json)
)
}

if (json.jobConfig) {
this._jobConfig = validateJobConfig(json.jobConfig)
this._jobConfig = validateJobConfig(
this.getConfig(ConfigTypes.Job, json)
)
}

if (json.streamConfig) {
this._streamConfig = validateStreamConfig(json.streamConfig)
this._streamConfig = validateStreamConfig(
this.getConfig(ConfigTypes.Stream, json)
)
}

if (json.testConfig) {
this._testConfig = validateTestConfig(json.testConfig)
this._testConfig = validateTestConfig(
this.getConfig(ConfigTypes.Test, json)
)
}

if (json.macroFolders && json.macroFolders.length) {
Expand All @@ -255,6 +277,15 @@ export class Target implements TargetJson {
}
}

private getConfig = (key: ConfigTypes, json: { [key: string]: any }) => {
const config = this._config[key] || {}

return {
...config,
...json[key]
}
}

toJson(withDefaults: boolean = true): TargetJson {
const json: TargetJson = {
name: this.name,
Expand Down