balda 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +72 -104
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +72 -104
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
package/lib/cli.js
CHANGED
|
@@ -126,7 +126,7 @@ export default class extends BaseQueue {
|
|
|
126
126
|
`);}catch(f){console.error("\x1B[31m\u274C Error generating SDK:\x1B[0m",f);}finally{try{await u.unlink(Ce);}catch{}if(v){let f=g;try{console.log("\u{1F6D1} Stopping server..."),await f.close?.(),console.log(`\u2705 Server stopped.
|
|
127
127
|
`);}catch{console.log(`\x1B[33m\u26A0\uFE0F Could not stop server gracefully.\x1B[0m
|
|
128
128
|
`);}}}console.log(`\x1B[32m\u2728 SDK generation complete!\x1B[0m
|
|
129
|
-
`);}};p([x({description:"Path to the server instance file (should export a Server instance)",required:false,defaultValue:"test/server/instance.ts"})],q,"serverPath"),p([m({description:"Output directory for generated SDK",type:"string",aliases:["o"],name:"output",required:false,defaultValue:"sdk"})],q,"outputPath"),p([m({description:"Swagger UI path on your server",type:"string",aliases:["s"],name:"swagger-path",required:false})],q,"swaggerPath"),p([m({description:"HTTP client to use (axios or fetch)",type:"string",aliases:["c"],name:"client",required:false,defaultValue:"fetch"})],q,"httpClient"),p([m({description:"Unwrap response data automatically",type:"boolean",name:"unwrap-response-data",required:false,defaultValue:false})],q,"unwrapResponseData"),p([m({description:"Generate single HTTP client instance",type:"boolean",name:"single-http-client",required:false,defaultValue:false})],q,"singleHttpClient"),p([m({description:"Add prefix to all generated types",type:"string",name:"type-prefix",required:false})],q,"typePrefix"),p([m({description:"Add suffix to all generated types",type:"string",name:"type-suffix",required:false})],q,"typeSuffix"),p([m({description:"Use enum names as values",type:"boolean",name:"enum-names-as-values",required:false,defaultValue:false})],q,"enumNamesAsValues"),p([m({description:"Sort types alphabetically",type:"boolean",name:"sort-types",required:false,defaultValue:false})],q,"sortTypes");var O=class extends h{static commandName="init";static description="Initialize a new balda project in the current directory";static help=["Initialize a new balda project, it is given for granted that balda is installed in the project as a dependency","All the files are created in the /src directory (created if not exists)","It adds a server.ts for the file instance and a index.ts for the entry point with a dummy hello world route","Example: npx balda init -p ./src -t true"];static srcPath;static typescript;static mqtt;static cron;static graphql;static devDependencies=["esbuild","esbuild-plugin-copy","tsx","typescript"];static async handle(){this.logger.info("Initializing project...");let[e,t,s]=await $();if(["npm","yarn","pnpm"].includes(e)){let a=await R(this.devDependencies);if(a.length&&(this.logger.info(`Found ${a.length} missing dev dependencies`),!await S(`${e} ${t} ${a.join(" ")} -${s}`,e,a,{stdio:"inherit"}))){this.logger.info("Installation cancelled by user. Project initialization aborted.");return}a.length||this.logger.info("All dev dependencies are already installed");}if(this.mqtt&&["npm","yarn","pnpm"].includes(e)){let a=await R(["mqtt"]);a.length&&(await S(`${e} ${t} mqtt`,e,["mqtt"],{stdio:"inherit"},false)||(this.logger.info("MQTT installation cancelled by user. Skipping MQTT scaffolding."),this.mqtt=false)),a.length||this.logger.info("MQTT package is already installed");}if(this.cron&&["npm","yarn","pnpm"].includes(e)){let a=await R(["node-cron"]);a.length>0&&(await S(`${e} ${t} node-cron`,e,["node-cron"],{stdio:"inherit"},false)||(this.logger.info("node-cron installation cancelled by user. Skipping Cron scaffolding."),this.cron=false)),a.length||this.logger.info("node-cron package is already installed");}if(this.graphql&&["npm","yarn","pnpm"].includes(e)){let a=await R(["@apollo/server","graphql"]);a.length>0&&(await S(`${e} ${t} ${a.join(" ")}`,e,a,{stdio:"inherit"},false)||(this.logger.info("GraphQL installation cancelled by user. Skipping GraphQL scaffolding."),this.graphql=false)),a.length||this.logger.info("GraphQL packages are already installed");}let r=this.typescript?"ts":"js",i=this.getServerTemplate(),n=this.getIndexTemplate();if(u.exists(this.srcPath)||await u.mkdir(this.srcPath,{recursive:true}),this.logger.info(`Creating server.${r} file...`),await u.writeFile(`${this.srcPath}/server.${r}`,new TextEncoder().encode(i)),this.logger.info(`Creating index.${r} file...`),await u.writeFile(`${this.srcPath}/index.${r}`,new TextEncoder().encode(n)),this.mqtt){let a=d.join(this.srcPath,"mqtt");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getMqttConfigTemplate();this.logger.info(`Creating mqtt/mqtt.config.${r} file...`),await u.writeFile(d.join(a,`mqtt.config.${r}`),new TextEncoder().encode(l));}if(this.cron){let a=d.join(this.srcPath,"cron");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getCronConfigTemplate();this.logger.info(`Creating cron/cron.config.${r} file...`),await u.writeFile(d.join(a,`cron.config.${r}`),new TextEncoder().encode(l));}if(this.graphql){let a=d.join(this.srcPath,"graphql");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getGraphqlConfigTemplate();this.logger.info(`Creating graphql/graphql.config.${r} file...`),await u.writeFile(d.join(a,`graphql.config.${r}`),new TextEncoder().encode(l));}this.logger.info("Project initialized successfully!");}static getServerTemplate(){return `import { Server } from "balda";
|
|
129
|
+
`);}};p([x({description:"Path to the server instance file (should export a Server instance)",required:false,defaultValue:"test/server/instance.ts"})],q,"serverPath"),p([m({description:"Output directory for generated SDK",type:"string",aliases:["o"],name:"output",required:false,defaultValue:"sdk"})],q,"outputPath"),p([m({description:"Swagger UI path on your server",type:"string",aliases:["s"],name:"swagger-path",required:false})],q,"swaggerPath"),p([m({description:"HTTP client to use (axios or fetch)",type:"string",aliases:["c"],name:"client",required:false,defaultValue:"fetch"})],q,"httpClient"),p([m({description:"Unwrap response data automatically",type:"boolean",name:"unwrap-response-data",required:false,defaultValue:false})],q,"unwrapResponseData"),p([m({description:"Generate single HTTP client instance",type:"boolean",name:"single-http-client",required:false,defaultValue:false})],q,"singleHttpClient"),p([m({description:"Add prefix to all generated types",type:"string",name:"type-prefix",required:false})],q,"typePrefix"),p([m({description:"Add suffix to all generated types",type:"string",name:"type-suffix",required:false})],q,"typeSuffix"),p([m({description:"Use enum names as values",type:"boolean",name:"enum-names-as-values",required:false,defaultValue:false})],q,"enumNamesAsValues"),p([m({description:"Sort types alphabetically",type:"boolean",name:"sort-types",required:false,defaultValue:false})],q,"sortTypes");var O=class extends h{static commandName="init";static description="Initialize a new balda project in the current directory";static help=["Initialize a new balda project, it is given for granted that balda is installed in the project as a dependency","All the files are created in the /src directory (created if not exists)","It adds a server.ts for the file instance and a index.ts for the entry point with a dummy hello world route","Example: npx balda init -p ./src -t true"];static srcPath;static typescript;static mqtt;static cron;static graphql;static devDependencies=["esbuild","esbuild-plugin-copy","tsx","typescript"];static async handle(){this.logger.info("Initializing project...");let[e,t,s]=await $();if(["npm","yarn","pnpm"].includes(e)){let a=await R(this.devDependencies);if(a.length&&(this.logger.info(`Found ${a.length} missing dev dependencies`),!await S(`${e} ${t} ${a.join(" ")} -${s}`,e,a,{stdio:"inherit"}))){this.logger.info("Installation cancelled by user. Project initialization aborted.");return}a.length||this.logger.info("All dev dependencies are already installed");}if(this.mqtt&&["npm","yarn","pnpm"].includes(e)){let a=await R(["mqtt"]);a.length&&(await S(`${e} ${t} mqtt`,e,["mqtt"],{stdio:"inherit"},false)||(this.logger.info("MQTT installation cancelled by user. Skipping MQTT scaffolding."),this.mqtt=false)),a.length||this.logger.info("MQTT package is already installed");}if(this.cron&&["npm","yarn","pnpm"].includes(e)){let a=await R(["node-cron"]);a.length>0&&(await S(`${e} ${t} node-cron`,e,["node-cron"],{stdio:"inherit"},false)||(this.logger.info("node-cron installation cancelled by user. Skipping Cron scaffolding."),this.cron=false)),a.length||this.logger.info("node-cron package is already installed");}if(this.graphql&&["npm","yarn","pnpm"].includes(e)){let a=await R(["@apollo/server","@graphql-tools/schema","graphql"]);a.length>0&&(await S(`${e} ${t} ${a.join(" ")}`,e,a,{stdio:"inherit"},false)||(this.logger.info("GraphQL installation cancelled by user. Skipping GraphQL scaffolding."),this.graphql=false)),a.length||this.logger.info("GraphQL packages are already installed");}let r=this.typescript?"ts":"js",i=this.getServerTemplate(),n=this.getIndexTemplate();if(u.exists(this.srcPath)||await u.mkdir(this.srcPath,{recursive:true}),this.logger.info(`Creating server.${r} file...`),await u.writeFile(`${this.srcPath}/server.${r}`,new TextEncoder().encode(i)),this.logger.info(`Creating index.${r} file...`),await u.writeFile(`${this.srcPath}/index.${r}`,new TextEncoder().encode(n)),this.mqtt){let a=d.join(this.srcPath,"mqtt");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getMqttConfigTemplate();this.logger.info(`Creating mqtt/mqtt.config.${r} file...`),await u.writeFile(d.join(a,`mqtt.config.${r}`),new TextEncoder().encode(l));}if(this.cron){let a=d.join(this.srcPath,"cron");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getCronConfigTemplate();this.logger.info(`Creating cron/cron.config.${r} file...`),await u.writeFile(d.join(a,`cron.config.${r}`),new TextEncoder().encode(l));}if(this.graphql){let a=d.join(this.srcPath,"graphql");await u.exists(a)||await u.mkdir(a,{recursive:true});let l=this.getGraphqlConfigTemplate();this.logger.info(`Creating graphql/graphql.config.${r} file...`),await u.writeFile(d.join(a,`graphql.config.${r}`),new TextEncoder().encode(l));}this.logger.info("Project initialized successfully!");}static getServerTemplate(){return `import { Server } from "balda";
|
|
130
130
|
|
|
131
131
|
const serverInstance = new Server({
|
|
132
132
|
port: 80,
|