From 4c996f40ab1442b7e66d327ce2b8565fb3d29c24 Mon Sep 17 00:00:00 2001 From: Mijail Rondon Date: Fri, 14 Aug 2020 09:27:17 -0500 Subject: [PATCH] refactor(core): refactor types and main class name - Moves types into root src - Rename main class to TerraformCloud --- .releaserc.json | 6 +++--- src/api/{TerraformCloudApi.ts => TerraformCloud.ts} | 4 ++-- src/index.ts | 5 +++-- src/{api => }/types/Account.ts | 2 +- src/{api => }/types/Plan.ts | 0 src/{api => }/types/Run.ts | 4 ++-- src/{api => }/types/TerraformCloudData.ts | 0 src/{api => }/types/index.ts | 0 test/api/TerraformCloudApi.test.ts | 7 +++---- test/mocks/index.ts | 4 ++++ 10 files changed, 18 insertions(+), 14 deletions(-) rename src/api/{TerraformCloudApi.ts => TerraformCloud.ts} (89%) rename src/{api => }/types/Account.ts (89%) rename src/{api => }/types/Plan.ts (100%) rename src/{api => }/types/Run.ts (87%) rename src/{api => }/types/TerraformCloudData.ts (100%) rename src/{api => }/types/index.ts (100%) create mode 100644 test/mocks/index.ts diff --git a/.releaserc.json b/.releaserc.json index dd2917e..041ce0a 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -7,10 +7,10 @@ "preset": "angular", "releaseRules": [ { "type": "docs", "scope": "README", "release": "patch" }, - { "type": "ref", "release": "patch" }, + { "type": "refactor", "release": "patch" }, + { "type": "fix", "release": "patch" }, { "type": "build", "release": "minor" }, - { "type": "feat", "release": "minor" }, - { "type": "fix", "release": "patch" } + { "type": "feat", "release": "minor" } ], "parserOpts": { "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"] diff --git a/src/api/TerraformCloudApi.ts b/src/api/TerraformCloud.ts similarity index 89% rename from src/api/TerraformCloudApi.ts rename to src/api/TerraformCloud.ts index 5d41db9..0a8cae0 100644 --- a/src/api/TerraformCloudApi.ts +++ b/src/api/TerraformCloud.ts @@ -1,9 +1,9 @@ import { AxiosInstance } from 'axios' import { EventEmitter } from 'events' import terraformCloudApiClient from './terraformCloudApiClient' -import { Account, Plan, Run } from './types' +import { Account, Plan, Run } from '../types' -export default class TerraformCloudApi extends EventEmitter { +export default class TerraformCloud extends EventEmitter { private readonly client: AxiosInstance constructor(apiKey: string) { diff --git a/src/index.ts b/src/index.ts index 481bb70..bd43889 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ -import TerraformCloudApi from './api/TerraformCloudApi' +import TerraformCloud from './api/TerraformCloud' +import { Account, Plan, Run } from './types' -export { TerraformCloudApi } +export { TerraformCloud, Account, Plan, Run } diff --git a/src/api/types/Account.ts b/src/types/Account.ts similarity index 89% rename from src/api/types/Account.ts rename to src/types/Account.ts index 7b69e93..67910f8 100644 --- a/src/api/types/Account.ts +++ b/src/types/Account.ts @@ -1,4 +1,4 @@ -import { TerraformCloudData, Links } from '../types/TerraformCloudData' +import { TerraformCloudData, Links } from './TerraformCloudData' export type Account = TerraformCloudData & { relationships: AccountRelationships diff --git a/src/api/types/Plan.ts b/src/types/Plan.ts similarity index 100% rename from src/api/types/Plan.ts rename to src/types/Plan.ts diff --git a/src/api/types/Run.ts b/src/types/Run.ts similarity index 87% rename from src/api/types/Run.ts rename to src/types/Run.ts index bcbd7a7..f8834f3 100644 --- a/src/api/types/Run.ts +++ b/src/types/Run.ts @@ -4,13 +4,13 @@ export type Run = TerraformCloudData & { relationships: RunRelationship } -export interface RunRelationship { +interface RunRelationship { plan: Relationship 'created-by': Relationship 'confirmed-by': Relationship } -export interface RunAttributes { +interface RunAttributes { 'auto-apply': boolean 'error-text': null | string 'is-destroy': boolean diff --git a/src/api/types/TerraformCloudData.ts b/src/types/TerraformCloudData.ts similarity index 100% rename from src/api/types/TerraformCloudData.ts rename to src/types/TerraformCloudData.ts diff --git a/src/api/types/index.ts b/src/types/index.ts similarity index 100% rename from src/api/types/index.ts rename to src/types/index.ts diff --git a/test/api/TerraformCloudApi.test.ts b/test/api/TerraformCloudApi.test.ts index eeb443a..a12edbb 100644 --- a/test/api/TerraformCloudApi.test.ts +++ b/test/api/TerraformCloudApi.test.ts @@ -1,9 +1,8 @@ import nock from 'nock' -import TerraformCloudApi from '../../src/api/TerraformCloudApi' -import AccountMock from '../mocks/AccountMock' -import RunMock from '../mocks/RunMock' +import TerraformCloud from '../../src/api/TerraformCloud' +import { AccountMock, RunMock } from '../mocks' -const client = new TerraformCloudApi('any-key') +const client = new TerraformCloud('any-key') describe('Api requests', () => { describe('Account', () => { diff --git a/test/mocks/index.ts b/test/mocks/index.ts new file mode 100644 index 0000000..b92c101 --- /dev/null +++ b/test/mocks/index.ts @@ -0,0 +1,4 @@ +import AccountMock from './AccountMock' +import RunMock from './RunMock' + +export { AccountMock, RunMock }