-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
476 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
setupFilesAfterEnv: ['./test/setupTests.ts'], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { generateContractsForm } from '../utils/generate-contracts-form'; | ||
import { CliArguments } from '../utils/define-args'; | ||
import { readPacts } from '../utils/read-pacts'; | ||
import { buildUrl } from '../utils/build-url'; | ||
import { postPacts } from '../utils/post-pacts'; | ||
|
||
export async function publish(argv: CliArguments) { | ||
const { pactsDir, serviceName, url, serviceVersion } = argv; | ||
|
||
const pacts = readPacts(pactsDir); | ||
const contractsForm = generateContractsForm(pacts); | ||
const judgeDUrl = buildUrl(url, serviceName, serviceVersion); | ||
|
||
await postPacts(judgeDUrl, contractsForm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import { defineArgs } from './utils/define-args'; | ||
import { publish } from './commands/publish'; | ||
|
||
export function run(process: NodeJS.Process) { | ||
export async function run(process: NodeJS.Process) { | ||
const argv = defineArgs(process.argv.slice(2)); | ||
console.log(argv); | ||
|
||
if (argv._.includes('publish')) { | ||
try { | ||
await publish(argv); | ||
} catch (e) { | ||
process.exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function buildUrl( | ||
url: string, | ||
serviceName: string, | ||
serviceVersion: string | ||
) { | ||
return `${url}/contracts/services/${serviceName}/versions/${serviceVersion}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Pact } from './read-pacts'; | ||
|
||
export function generateContractsForm(pactFiles: Pact[]): ServiceContractsForm { | ||
return pactFiles.reduce<ServiceContractsForm>( | ||
(serviceContractsForm, fileContent) => { | ||
if (fileContent.provider?.name) { | ||
return { | ||
...serviceContractsForm, | ||
expectations: { | ||
...serviceContractsForm.expectations, | ||
[fileContent.provider.name]: { | ||
rest: { | ||
value: JSON.stringify(fileContent), | ||
mimeType: 'application-json', | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
return serviceContractsForm; | ||
}, | ||
{ | ||
capabilities: {}, | ||
expectations: {}, | ||
} | ||
); | ||
} | ||
|
||
export interface ServiceContractsForm { | ||
capabilities: Record<string, RestContract>; | ||
expectations: Record<string, RestContract>; | ||
} | ||
|
||
interface RestContract { | ||
rest: { | ||
value: string; | ||
mimeType: 'application-json'; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ServiceContractsForm } from './generate-contracts-form'; | ||
import axios from 'axios'; | ||
|
||
export function postPacts(url: string, pacts: ServiceContractsForm) { | ||
return axios.post(url, pacts); | ||
} |
Oops, something went wrong.