Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

feat: bundle #11

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
chore: code style
hanspagel committed Jan 31, 2024
commit 8c9c2f77c5837d8040764585e5bd26c98eaf4367
32 changes: 18 additions & 14 deletions packages/cli/src/commands/bundle/BundleCommand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs'
import { Command } from 'commander'
import kleur from 'kleur'
import { useGivenFileOrConfiguration, loadOpenApiFile } from '../../utils'
import type { OpenAPI } from 'openapi-types'
import type { OpenAPI } from 'openapi-types'
import { loadOpenApiFile, useGivenFileOrConfiguration } from '../../utils'

export function BundleCommand() {
const cmd = new Command('bundle')
@@ -17,22 +17,26 @@ export function BundleCommand() {

const file = useGivenFileOrConfiguration(fileArgument)

let newContent = (await loadOpenApiFile(file))
const newContent = (await loadOpenApiFile(file))
.specification as OpenAPI.Document

// Replace file content with newContent
let cache = []
const json = JSON.stringify(newContent, function(key, value) {
if (typeof value === "object" && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
const cache = []
const json = JSON.stringify(
newContent,
(key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return
}
// Store value in our collection
cache.push(value)
}
// Store value in our collection
cache.push(value);
}
return value;
}, 2)
return value
},
2,
)

fs.writeFileSync(output ?? file, json, 'utf8')