Skip to content

Commit

Permalink
added scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeexcel committed Aug 13, 2024
1 parent 0538f92 commit 95aeb2c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable import/no-extraneous-dependencies */

const esbuild = require('esbuild')

const makeAllPackagesExternalPlugin = {
name: 'make-all-packages-external',
setup(build) {
const filter = /^[^./]|^\.[^./]|^\.\.[^/]/ // Must not start with "/" or "./" or "../"
build.onResolve({ filter }, (args) => ({
path: args.path,
external: true,
}))
},
}

esbuild
.build({
bundle: true,
minify: true,
tsconfig: 'tsconfig.json',
platform: 'node',
target: 'node18',
sourcemap: 'both',
plugins: [makeAllPackagesExternalPlugin],
outdir: 'lib',
entryPoints: ['src/index.ts'],
})
.catch(() => process.exit(1))
75 changes: 75 additions & 0 deletions scripts/formatSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable import/no-extraneous-dependencies */

const yaml = require('js-yaml')
const fs = require('fs');

const spec = yaml.load(fs.readFileSync('openapi.yaml', 'utf8'))

function isObjEmpty (obj) {
return Object.keys(obj).length === 0;
}

const components = spec['components']

if (components) {
Object.keys(components).forEach((key) => {
// Delete empty component schemas
if (isObjEmpty(components[key])) {
delete components[key]
}
})

// Delete components if empty
if (isObjEmpty(components)) {
delete spec['components']
}
}

const paths = spec['paths']

if (paths) {
Object.keys(paths).forEach((key) => {
// Delete empty paths
if (isObjEmpty(paths[key])) {
delete paths[key]
}


Object.keys(paths[key]).forEach((method) => {
// Delete empty methods
if (isObjEmpty(paths[key][method])) {
delete paths[key][method]
}

// Delete security if empty
if (paths[key][method]['security']) {
if (paths[key][method]['security'].length === 0) {
delete paths[key][method]['security']
}
}

// Delete openai-conversation-id header if exists - this should not be in spec for the plugin, it is automatically added by openai
if (paths[key][method]['parameters']) {
const conversationIDParameterIdx = paths[key][method]['parameters'].findIndex((parameter) => parameter.name === 'openai-conversation-id' && parameter.in === 'header')
if (conversationIDParameterIdx !== -1) {
paths[key][method]['parameters'].splice(conversationIDParameterIdx, 1)
}
}
})
})
}

const info = spec['info']
if (info) {
// Delete old info - it is generated from package.json with excessive fields
delete spec['info']
}

// Add new info
spec['info'] = {
title: 'E2B Code Interpreter',
description: 'A plugin that allows writting and reading files and running processes in a cloud environment.',
version: 'v1',
}

fs.writeFileSync('openapi.yaml', yaml.dump(spec, { sortKeys: true, indent: 2, condenseFlow: true, noArrayIndent: true, noCompatMode: true, lineWidth: -1 }))

0 comments on commit 95aeb2c

Please sign in to comment.