Skip to content

Commit

Permalink
feat: Setup publishing for the first set of packages
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Dec 4, 2023
1 parent 1c2602b commit e35be71
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
34 changes: 34 additions & 0 deletions bin/jsonToJs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node
import fs from 'node:fs'

/**
* This is used to workaround the fact that many applications such as
* webpack does not natively know how to import / bundle JSON files
* And we also don't want to use something ugly heavy handed like a roll up
* So simpliest solution is to rewrite the JSON file as a JS file
*/
const jsonFileName = process.argv[2]

if (!jsonFileName) {
console.error('Please provide a JSON file name as a command line argument.')
process.exit(1)
}

try {
const jsonData = fs.readFileSync(jsonFileName, 'utf8')
const jsFileName = `${jsonFileName}.js`
const jsContent = `module.exports = \n${jsonData}`

fs.writeFileSync(jsFileName, jsContent, 'utf8')
fs.rmSync(jsonFileName)

console.log(`Successfully generated ${jsFileName} with JSON content.`)
} catch (err) {
console.error('An error occurred while generating the JavaScript file:', err)
process.exit(1)
}


// TODO: There is additional problem where tsc does not copy .d.ts files to build, and therefore we
// need to do it manully
// https://stackoverflow.com/questions/56018167/typescript-does-not-copy-d-ts-files-to-build
1 change: 0 additions & 1 deletion packages/core/.npmignore

This file was deleted.

5 changes: 3 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["src/*", "../util-zod/defineSdk.ts"]
"include": ["./src/*"]
}
7 changes: 6 additions & 1 deletion sdks/sdk-github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"version": "0.0.0",
"scripts": {
"download": "curl --fail https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.json | prettier --parser json > ./github.oas.json",
"generate": "openapi-typescript ./github.oas.json --output github.oas.d.ts"
"generate": "openapi-typescript ./github.oas.json --output github.oas.d.ts",
"build": "tsc -p ./tsconfig.json && run-s build:json build:dts",
"build:dts": "cp ./github.oas.d.ts ./dist/github.oas.d.ts",
"build:json": "npx tsx ../../bin/jsonToJs.ts ./dist/github.oas.json",
"clean": "rm -rf ./dist",
"pub": "pnpm publish --no-git-checks --access public"
},
"dependencies": {},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions sdks/sdk-github/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["./index.ts"]
}
7 changes: 6 additions & 1 deletion sdks/sdk-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"module": "./index.ts",
"scripts": {
"download": "curl --fail https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml -o ./openai.oas.yaml",
"generate": "cat openai.oas.yaml | node ./yaml2json.js -o openai.oas && openapi-typescript ./openai.oas.json --output ./openai.oas.d.ts "
"generate": "cat openai.oas.yaml | node ./yaml2json.js -o openai.oas && openapi-typescript ./openai.oas.json --output ./openai.oas.d.ts",
"build": "tsc -p ./tsconfig.json && run-s build:json build:dts",
"build:dts": "cp ./openai.oas.d.ts ./dist/openai.oas.d.ts",
"build:json": "npx tsx ../../bin/jsonToJs.ts ./dist/openai.oas.json",
"clean": "rm -rf ./dist",
"pub": "pnpm publish --no-git-checks --access public"
},
"dependencies": {},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions sdks/sdk-openai/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["./index.ts"]
}

1 comment on commit e35be71

@vercel
Copy link

@vercel vercel bot commented on e35be71 Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

opensdks – ./

opensdks-venice.vercel.app
opensdks.org
opensdks.vercel.app
opensdks-git-main-venice.vercel.app

Please sign in to comment.