Skip to content

Commit

Permalink
feat: Adding jsonToJs bin
Browse files Browse the repository at this point in the history
that we will need in bunch of places so maybe better than echo
  • Loading branch information
tonyxiao committed Nov 26, 2023
1 parent aee5094 commit aa4e56f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kits/connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@usevenice/connect",
"version": "0.1.4",
"version": "0.1.5",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
29 changes: 29 additions & 0 deletions kits/sdk/bin/jsonToJs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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)
}
6 changes: 4 additions & 2 deletions kits/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "@usevenice/sdk",
"version": "0.0.3",
"version": "0.0.4",
"private": false,
"sideEffects": false,
"module": "./index.ts",
"scripts": {
"build": "tsc -p ./tsconfig.json",
"build": "tsc -p ./tsconfig.json && pnpm build:json",
"build:json": "node --loader tsx ./bin/jsonToJs.ts ./dist/venice.oas.json",
"clean": "rm -rf ./dist",
"generate": "pnpm generate:schema && pnpm generate:types",
"generate:schema": "NEXT_PUBLIC_SERVER_URL=https://app.venice.is node --loader tsx ../../apps/web/lib-server/appRouter.ts > ./venice.oas.json",
"generate:types": "openapi-typescript ./venice.oas.json --output ./venice.oas.d.ts",
Expand Down

0 comments on commit aa4e56f

Please sign in to comment.