Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
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
3 changes: 2 additions & 1 deletion workspaces/cli-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
"@useoptic/domain-types": "8.3.1",
"@useoptic/domain-utilities": "8.3.1",
"avsc": "^5.4.21",
"proper-lockfile": "^4.1.1",
"bottleneck": "^2.19.5",
"colors": "^1.4.0",
"fs-extra": "^9.0.0",
"mockttp": "^0.19.2",
"oboe": "^2.1.5",
"ora": "^4.0.4",
"proper-lockfile": "^4.1.1",
"tree-kill": "^1.2.2",
"uuid": "^8.0.0",
"shape-hash": "^1.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import fs from 'fs-extra';
import path from 'path';
import { IHttpInteraction } from '@useoptic/domain-types';
//@ts-ignore
import oboe from 'oboe';
import { CaptureSaver } from './capture-saver';

async function main(inputFilePath: string, outputBaseDirectory: string) {
console.log({ inputFilePath });
const input = fs.createReadStream(inputFilePath);
const events: any[] = [];
const captureId = 'ccc';
const captureBaseDirectory = path.join(
outputBaseDirectory,
'.optic',
'captures'
);
const captureSaver = new CaptureSaver({
captureBaseDirectory,
captureId,
});
await captureSaver.init();
await new Promise((resolve, reject) => {
oboe(input)
.on('node', {
// @ts-ignore
'events.*': function (event: any) {
console.count('event');
//console.log({ event });
events.push(event);
},
'session.samples.*': function (sample: IHttpInteraction) {
console.count('sample');
//console.log({ sample });
captureSaver.save(sample);
},
})
.on('done', function () {
console.log('done');
resolve();
})
.on('fail', function (e: any) {
console.error(e);
reject(e);
});
});

const files = [
{
location: path.join(outputBaseDirectory, 'optic.yml'),
contents: `name: ${JSON.stringify(path.basename(inputFilePath))}`,
},
{
location: path.join(
outputBaseDirectory,
'.optic',
'api',
'specification.json'
),
contents: JSON.stringify(events),
},
{
location: path.join(
outputBaseDirectory,
'.optic',
'captures',
captureId,
'optic-capture-state.json'
),
contents: JSON.stringify({
captureId,
status: 'completed',
metadata: {
startedAt: new Date().toISOString(),
taskConfig: null,
lastInteraction: null,
},
}),
},
];

await Promise.all(
files.map(async (x) => {
const { location, contents } = x;
await fs.ensureDir(path.dirname(location));
return fs.writeFile(location, contents);
})
);
}

const [, , inputFilePath, outputBaseDirectory] = process.argv;
main(inputFilePath, outputBaseDirectory);
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8298,6 +8298,11 @@ http-errors@~1.7.2:
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"

http-https@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/http-https/-/http-https-1.0.0.tgz#2f908dd5f1db4068c058cd6e6d4ce392c913389b"
integrity sha1-L5CN1fHbQGjAWM1ubUzjkskTOJs=

http-parser-js@>=0.5.1:
version "0.5.2"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.2.tgz#da2e31d237b393aae72ace43882dd7e270a8ff77"
Expand Down Expand Up @@ -11213,6 +11218,13 @@ object.values@^1.1.0:
function-bind "^1.1.1"
has "^1.0.3"

oboe@^2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/oboe/-/oboe-2.1.5.tgz#5554284c543a2266d7a38f17e073821fbde393cd"
integrity sha1-VVQoTFQ6ImbXo48X4HOCH73jk80=
dependencies:
http-https "^1.0.0"

obuf@^1.0.0, obuf@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
Expand Down