diff --git a/.eslintrc.js b/.eslintrc.js index 0289b8c9..aceb7a1d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,16 +49,9 @@ module.exports = { ], }, ], - 'jsonc/sort-keys': [ - 'error', - 'asc', - { caseSensitive: true, minKeys: 2, natural: false }, - ], - 'sort-keys': [ - 'error', - 'asc', - { caseSensitive: true, minKeys: 2, natural: false }, - ], + 'jsonc/sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: 2, natural: false }], + 'max-len': ['error', { code: 120, ignoreStrings: true }], + 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: 2, natural: false }], 'spellcheck/spell-checker': [ 1, { diff --git a/.prettierrc b/.prettierrc index a20502b7..4b9a2d97 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { + "printWidth": 120, "singleQuote": true, "trailingComma": "all" } diff --git a/dictionary.dic b/dictionary.dic index 3495ebab..1a475346 100644 --- a/dictionary.dic +++ b/dictionary.dic @@ -8,6 +8,7 @@ dic eslintrc ispec jsonc +len nginx octo promisify diff --git a/src/v0/models/app/app.model.ts b/src/v0/models/app/app.model.ts index d81d2414..e318629a 100644 --- a/src/v0/models/app/app.model.ts +++ b/src/v0/models/app/app.model.ts @@ -66,18 +66,9 @@ export class App implements IModel { const diff: Diff[] = []; for (const region of this.regions) { - const regionInLatest = latest.regions.find( - (r) => r.regionId === region.regionId, - ); + const regionInLatest = latest.regions.find((r) => r.regionId === region.regionId); if (!regionInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'region', - region.regionId, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'region', region.regionId)); } else { const regionDiff = region.diff(regionInLatest); if (regionDiff.length !== 0) { @@ -88,14 +79,7 @@ export class App implements IModel { for (const region of latest.regions) { if (!this.regions.find((r) => r.regionId === region.regionId)) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'region', - region.regionId, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'region', region.regionId)); const regionDiff = region.diffAdd(); if (regionDiff.length !== 0) { @@ -105,18 +89,9 @@ export class App implements IModel { } for (const server of this.servers) { - const serverInLatest = latest.servers.find( - (s) => s.serverKey === server.serverKey, - ); + const serverInLatest = latest.servers.find((s) => s.serverKey === server.serverKey); if (!serverInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'server', - server.serverKey, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'server', server.serverKey)); } else { const serverDiff = server.diff(serverInLatest); if (serverDiff.length !== 0) { @@ -127,14 +102,7 @@ export class App implements IModel { for (const server of latest.servers) { if (!this.servers.find((s) => s.serverKey === server.serverKey)) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'server', - server.serverKey, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'server', server.serverKey)); const serverDiff = server.diffAdd(); if (serverDiff.length !== 0) { @@ -144,18 +112,9 @@ export class App implements IModel { } for (const support of this.supports) { - const supportInLatest = latest.supports.find( - (s) => s.serverKey === support.serverKey, - ); + const supportInLatest = latest.supports.find((s) => s.serverKey === support.serverKey); if (!supportInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'support', - support.serverKey, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'support', support.serverKey)); } else { const supportDiff = support.diff(supportInLatest); if (supportDiff.length !== 0) { @@ -166,14 +125,7 @@ export class App implements IModel { for (const support of latest.supports) { if (!this.supports.find((s) => s.serverKey === support.serverKey)) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'support', - support.serverKey, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'support', support.serverKey)); const supportDiff = support.diffAdd(); if (supportDiff.length !== 0) { diff --git a/src/v0/models/deployment/deployment.model.ts b/src/v0/models/deployment/deployment.model.ts index 71c09a78..5ebb9db9 100644 --- a/src/v0/models/deployment/deployment.model.ts +++ b/src/v0/models/deployment/deployment.model.ts @@ -29,8 +29,6 @@ export class Deployment implements IModel { } getContext(): string { - return [`deployment=${this.deploymentTag}`, this.context.getContext()].join( - ',', - ); + return [`deployment=${this.deploymentTag}`, this.context.getContext()].join(','); } } diff --git a/src/v0/models/environment/environment.model.spec.ts b/src/v0/models/environment/environment.model.spec.ts index 21e5ba07..24b197d9 100644 --- a/src/v0/models/environment/environment.model.spec.ts +++ b/src/v0/models/environment/environment.model.spec.ts @@ -5,17 +5,12 @@ import { Environment } from './environment.model'; describe('Environment UT', () => { describe('clone()', () => { it('should clone all fields', () => { - const environment = new Environment( - new AwsRegion(new App('test'), 'aws-us-east-1'), - 'qa', - ); + const environment = new Environment(new AwsRegion(new App('test'), 'aws-us-east-1'), 'qa'); environment.environmentVariables.set('key', 'value'); const duplicate = environment.clone(); - expect(duplicate.getContext()).toBe( - 'environment=qa,region=aws-us-east-1,app=test', - ); + expect(duplicate.getContext()).toBe('environment=qa,region=aws-us-east-1,app=test'); expect(duplicate.environmentName).toBe('qa'); expect(duplicate.environmentVariables.get('key')).toBe('value'); }); diff --git a/src/v0/models/environment/environment.model.ts b/src/v0/models/environment/environment.model.ts index ef4b8a05..bb73eed2 100644 --- a/src/v0/models/environment/environment.model.ts +++ b/src/v0/models/environment/environment.model.ts @@ -29,25 +29,13 @@ export class Environment implements IModel { for (const [key, value] of this.environmentVariables) { if (!latest.environmentVariables.has(key)) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'environmentVariables', - { key, value }, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'environmentVariables', { key, value })); } else if (latest.environmentVariables.get(key) !== value) { diff.push( - new Diff( - DiffAction.UPDATE, - this.getContext(), - 'environmentVariables', - { - key, - value: latest.environmentVariables.get(key), - }, - ), + new Diff(DiffAction.UPDATE, this.getContext(), 'environmentVariables', { + key, + value: latest.environmentVariables.get(key), + }), ); } } @@ -85,9 +73,6 @@ export class Environment implements IModel { } getContext(): string { - return [ - `environment=${this.environmentName}`, - this.context.getContext(), - ].join(','); + return [`environment=${this.environmentName}`, this.context.getContext()].join(','); } } diff --git a/src/v0/models/region/region.model.ts b/src/v0/models/region/region.model.ts index 349b2516..94d18a4c 100644 --- a/src/v0/models/region/region.model.ts +++ b/src/v0/models/region/region.model.ts @@ -20,11 +20,7 @@ export class Region implements IModel { addEnvironment(environment: Environment): void { // Check for duplicates. - if ( - this.environments.find( - (e) => e.environmentName === environment.environmentName, - ) - ) { + if (this.environments.find((e) => e.environmentName === environment.environmentName)) { throw new Error('Environment already exists!'); } @@ -45,18 +41,9 @@ export class Region implements IModel { const diff: Diff[] = []; for (const environment of this.environments) { - const environmentInLatest = latest.environments.find( - (e) => e.environmentName === environment.environmentName, - ); + const environmentInLatest = latest.environments.find((e) => e.environmentName === environment.environmentName); if (!environmentInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'environment', - environment.environmentName, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'environment', environment.environmentName)); } else { const environmentDiff = environment.diff(environmentInLatest); if (environmentDiff.length !== 0) { @@ -66,19 +53,8 @@ export class Region implements IModel { } for (const environment of latest.environments) { - if ( - !this.environments.find( - (e) => e.environmentName === environment.environmentName, - ) - ) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'environment', - environment.environmentName, - ), - ); + if (!this.environments.find((e) => e.environmentName === environment.environmentName)) { + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'environment', environment.environmentName)); const environmentDiff = environment.diffAdd(); if (environmentDiff.length !== 0) { @@ -97,14 +73,7 @@ export class Region implements IModel { const diff: Diff[] = []; for (const environment of this.environments) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'environment', - environment.environmentName, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'environment', environment.environmentName)); const environmentDiff = environment.diffAdd(); if (environmentDiff.length !== 0) { diff --git a/src/v0/models/server/server.model.ts b/src/v0/models/server/server.model.ts index 47177042..2ee618d6 100644 --- a/src/v0/models/server/server.model.ts +++ b/src/v0/models/server/server.model.ts @@ -17,9 +17,7 @@ export class Server implements IModel { addDeployment(deployment: Deployment): void { // Check for duplicates. - if ( - this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag) - ) { + if (this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) { throw new Error('Deployment already exists!'); } @@ -40,18 +38,9 @@ export class Server implements IModel { const diff: Diff[] = []; for (const deployment of this.deployments) { - const deploymentInLatest = latest.deployments.find( - (d) => d.deploymentTag === deployment.deploymentTag, - ); + const deploymentInLatest = latest.deployments.find((d) => d.deploymentTag === deployment.deploymentTag); if (!deploymentInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'deployment', deployment.deploymentTag)); } else { const deploymentDiff = deployment.diff(deploymentInLatest); if (deploymentDiff.length !== 0) { @@ -61,19 +50,8 @@ export class Server implements IModel { } for (const deployment of latest.deployments) { - if ( - !this.deployments.find( - (d) => d.deploymentTag === deployment.deploymentTag, - ) - ) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + if (!this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) { + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag)); const deploymentDiff = deployment.diffAdd(); if (deploymentDiff.length !== 0) { @@ -92,14 +70,7 @@ export class Server implements IModel { const diff: Diff[] = []; for (const deployment of this.deployments) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag)); const deploymentDiff = deployment.diffAdd(); if (deploymentDiff.length !== 0) { diff --git a/src/v0/models/support/support.model.ts b/src/v0/models/support/support.model.ts index a59beb3b..de5a860d 100644 --- a/src/v0/models/support/support.model.ts +++ b/src/v0/models/support/support.model.ts @@ -17,9 +17,7 @@ export class Support implements IModel { addDeployment(deployment: Deployment): void { // Check for duplicates. - if ( - this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag) - ) { + if (this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) { throw new Error('Deployment already exists!'); } @@ -40,18 +38,9 @@ export class Support implements IModel { const diff: Diff[] = []; for (const deployment of this.deployments) { - const deploymentInLatest = latest.deployments.find( - (d) => d.deploymentTag === deployment.deploymentTag, - ); + const deploymentInLatest = latest.deployments.find((d) => d.deploymentTag === deployment.deploymentTag); if (!deploymentInLatest) { - diff.push( - new Diff( - DiffAction.DELETE, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'deployment', deployment.deploymentTag)); } else { const deploymentDiff = deployment.diff(deploymentInLatest); if (deploymentDiff.length !== 0) { @@ -61,19 +50,8 @@ export class Support implements IModel { } for (const deployment of latest.deployments) { - if ( - !this.deployments.find( - (d) => d.deploymentTag === deployment.deploymentTag, - ) - ) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + if (!this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) { + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag)); const deploymentDiff = deployment.diffAdd(); if (deploymentDiff.length !== 0) { @@ -92,14 +70,7 @@ export class Support implements IModel { const diff: Diff[] = []; for (const deployment of this.deployments) { - diff.push( - new Diff( - DiffAction.ADD, - this.getContext(), - 'deployment', - deployment.deploymentTag, - ), - ); + diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag)); const deploymentDiff = deployment.diffAdd(); if (deploymentDiff.length !== 0) { diff --git a/src/v0/services/synth/synth.service.spec.ts b/src/v0/services/synth/synth.service.spec.ts index 92a8b545..8a6c0400 100644 --- a/src/v0/services/synth/synth.service.spec.ts +++ b/src/v0/services/synth/synth.service.spec.ts @@ -88,9 +88,7 @@ describe('Synth Service UT', () => { await new SynthService(app).synth(filePath); - const contents = await readFileAsync( - join(filePath, 'infrastructure.json'), - ); + const contents = await readFileAsync(join(filePath, 'infrastructure.json')); const output = JSON.parse(contents.toString()); expect(output).toMatchInlineSnapshot(` { diff --git a/src/v0/services/synth/synth.service.ts b/src/v0/services/synth/synth.service.ts index b32b0188..eb45f4a2 100644 --- a/src/v0/services/synth/synth.service.ts +++ b/src/v0/services/synth/synth.service.ts @@ -20,10 +20,7 @@ export class SynthService { async synth(filePath: string): Promise { const output = this.synthReadOnly(); - await writeFileAsync( - join(filePath, SYNTH_FILE_NAME), - JSON.stringify(output, null, 2), - ); + await writeFileAsync(join(filePath, SYNTH_FILE_NAME), JSON.stringify(output, null, 2)); } synthReadOnly(): IApp { @@ -44,9 +41,7 @@ export class SynthService { r.environments.forEach((e) => { region.environments.push({ environmentName: e.environmentName, - environmentVariables: Object.fromEntries( - e.environmentVariables || new Map(), - ), + environmentVariables: Object.fromEntries(e.environmentVariables || new Map()), }); }); diff --git a/src/v0/utility/diff.utility.ts b/src/v0/utility/diff.utility.ts index 53369be8..f4b68f3b 100644 --- a/src/v0/utility/diff.utility.ts +++ b/src/v0/utility/diff.utility.ts @@ -13,12 +13,7 @@ export class Diff { readonly value: unknown; - constructor( - action: DiffAction, - context: string, - field: string, - value: unknown, - ) { + constructor(action: DiffAction, context: string, field: string, value: unknown) { this.action = action; this.context = context; this.field = field; diff --git a/test/v0/app.e2e-spec.ts b/test/v0/app.e2e-spec.ts index 15e2cc95..5868e70c 100644 --- a/test/v0/app.e2e-spec.ts +++ b/test/v0/app.e2e-spec.ts @@ -1,11 +1,4 @@ -import { - App, - AwsRegion, - Deployment, - Environment, - Server, - Support, -} from '../../src/v0'; +import { App, AwsRegion, Deployment, Environment, Server, Support } from '../../src/v0'; describe('App E2E Test', () => { it('should generate app diff', () => { @@ -21,17 +14,11 @@ describe('App E2E Test', () => { app.addServer(new Server(app, 'backend')); const newApp = app.clone(); - const newAppRegion = newApp.regions.find( - (r) => r.regionId === 'aws-us-east-1', - ); - const newAppBackendServer = newApp.servers.find( - (s) => s.serverKey === 'backend', - ); + const newAppRegion = newApp.regions.find((r) => r.regionId === 'aws-us-east-1'); + const newAppBackendServer = newApp.servers.find((s) => s.serverKey === 'backend'); // Add a deployment to backend server. - newAppBackendServer.addDeployment( - new Deployment(newAppBackendServer, 'v0.0.1'), - ); + newAppBackendServer.addDeployment(new Deployment(newAppBackendServer, 'v0.0.1')); // Add a new staging environment. const stagingEnvironment = new Environment(newAppRegion, 'staging'); @@ -39,15 +26,11 @@ describe('App E2E Test', () => { newAppRegion.addEnvironment(stagingEnvironment); // Update the qa environment. - newAppRegion.environments - .find((e) => e.environmentName === 'qa') - .environmentVariables.set('env', 'qa'); + newAppRegion.environments.find((e) => e.environmentName === 'qa').environmentVariables.set('env', 'qa'); // Add new server. const newAppDatabaseServer = new Server(newApp, 'database'); - newAppDatabaseServer.addDeployment( - new Deployment(newAppDatabaseServer, 'v0.0.1'), - ); + newAppDatabaseServer.addDeployment(new Deployment(newAppDatabaseServer, 'v0.0.1')); newApp.addServer(newAppDatabaseServer); // Add new support.