diff --git a/docs/guide/builder/index.md b/docs/guide/builder/index.md index 35d084a..46fe699 100644 --- a/docs/guide/builder/index.md +++ b/docs/guide/builder/index.md @@ -57,7 +57,10 @@ All of these options are available with the `backan-builder` command by adding t ```ts type BuilderParams = { /** - * The input file for the build process. + * The app server input file. + * + * The input can be provided without an extension. + * If the extension is omitted, the system will automatically look for the following extensions: `.ts`, `.js`, `.mjs`, `.mts`. */ input: string, /** @@ -104,7 +107,7 @@ export type BuilderSchemaParams = { /** * The instance of the Backan application used to generate the OpenAPI schema. */ - app: App, + app: App, /** * The path where the resulting `json` file will be saved. */ @@ -131,7 +134,7 @@ type BuilderMDParams = { /** * The instance of the Backan application used to generate the OpenAPI schema. */ - app: App, + app: App, /** * The path where the resulting `Markdown` file will be saved. */ diff --git a/packages/backan/CHANGELOG.md b/packages/backan/CHANGELOG.md index 8c143e4..633d95d 100644 --- a/packages/backan/CHANGELOG.md +++ b/packages/backan/CHANGELOG.md @@ -1,5 +1,12 @@ # backan +## 0.0.15 + +### Patch Changes + +- Updated dependencies []: + - @backan/core@0.0.15 + ## 0.0.14 ### Patch Changes diff --git a/packages/backan/package.json b/packages/backan/package.json index 34ab7bc..248d1aa 100644 --- a/packages/backan/package.json +++ b/packages/backan/package.json @@ -1,6 +1,6 @@ { "name": "backan", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "license": "GPL-3.0", "homepage": "https://backan.pigeonposse.com", diff --git a/packages/builder/CHANGELOG.md b/packages/builder/CHANGELOG.md index c677608..57d0daa 100644 --- a/packages/builder/CHANGELOG.md +++ b/packages/builder/CHANGELOG.md @@ -1,5 +1,11 @@ # @backan/builder +## 0.0.15 + +### Patch Changes + +- fix issues and update builder for detect input without extensions + ## 0.0.14 ## 0.0.13 diff --git a/packages/builder/examples/app.ts b/packages/builder/examples/app.ts index ddc6f54..8fa67a8 100644 --- a/packages/builder/examples/app.ts +++ b/packages/builder/examples/app.ts @@ -1,5 +1,7 @@ import { App } from '@backan/core' -export const app = new App( { + +type AppEnv = {DB: object} +export const app = new App( { version : '1.0.0', title : 'BACKAN Example app', description : 'API documentation for BACKAN Example', diff --git a/packages/builder/examples/build.ts b/packages/builder/examples/build.ts index 514d660..aa107ab 100644 --- a/packages/builder/examples/build.ts +++ b/packages/builder/examples/build.ts @@ -1,9 +1,8 @@ -import { resolve } from 'node:path' -import { build } from '../src/main' +import { build } from '../src/main' // import { build } from '../dist/main' build( { - input : resolve( 'examples/server.ts' ), + input : 'examples/server', // name : 'backan', // outDir : resolve( 'build' ), // type : 'all', diff --git a/packages/builder/examples/md.ts b/packages/builder/examples/md.ts index c80455c..64b8fff 100644 --- a/packages/builder/examples/md.ts +++ b/packages/builder/examples/md.ts @@ -1,6 +1,7 @@ import { buildMD } from '../src/md' import { app } from './app' + buildMD( { app : app, - output : 'example-openapi.md', + output : 'openapi.md', } ) diff --git a/packages/builder/examples/schema.ts b/packages/builder/examples/schema.ts index 4d7d24f..a61f642 100644 --- a/packages/builder/examples/schema.ts +++ b/packages/builder/examples/schema.ts @@ -1,6 +1,7 @@ import { buildSchema } from '../src/schema' import { app } from './app' + buildSchema( { - app : app, - output : 'example-openapi.json', + app, + output : 'openapi.json', } ) diff --git a/packages/builder/examples/server.ts b/packages/builder/examples/server.ts index d87c9ad..ca74f1f 100644 --- a/packages/builder/examples/server.ts +++ b/packages/builder/examples/server.ts @@ -1,11 +1,6 @@ -import { App } from '@backan/core' -import { server } from '@backan/server' -export const app = new App( { - version : '1.0.0', - title : 'BACKAN Example app', - description : 'API documentation for BACKAN Example', -} ) +import { server } from '@backan/server' +import { app } from './app' server( { app, diff --git a/packages/builder/package.json b/packages/builder/package.json index 1c29269..089451a 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@backan/builder", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "license": "GPL-3.0", "homepage": "https://backan.pigeonposse.com/", diff --git a/packages/builder/src/main.ts b/packages/builder/src/main.ts index fa6c87f..e7bba49 100644 --- a/packages/builder/src/main.ts +++ b/packages/builder/src/main.ts @@ -77,7 +77,7 @@ export const buildConstructor = async ( { if( flags.onlyOs ) onlyOs = flags.onlyOs if( flags.outDir ) outDir = flags.outDir if( flags.type && Object.values( BUILDER_TYPE ).includes( flags.type ) ) type = flags.type - + if( !name ) name = getFilename( input ) const opts = { @@ -128,8 +128,34 @@ export const buildConstructor = async ( { }, null, 2 ) ) // EXIST INPUT - const exists = await existsPath( input ) + const getInput = async ( path: string ) => { + + const validExtensions = [ + '.ts', '.js', '.mjs', '.mts', + ] + + if( !validExtensions.some( ext => path.endsWith( ext ) ) ){ + + for ( let index = 0; index < validExtensions.length; index++ ) { + + const input = path + validExtensions[index] + + const exists = await existsPath( input ) + if( exists ) return input + + } + return undefined + + } + const exists = await existsPath( path ) + if( exists ) return path + return undefined + + } + + const exists = await getInput( input ) if( !exists ) throw new BuildError( ERROR_ID.NO_INPUT, data ) + else input = exists if( plat === 'unknown' ) throw new BuildError( ERROR_ID.PLATFORM_UNKWON, data ) diff --git a/packages/builder/src/md.ts b/packages/builder/src/md.ts index 7bc77a5..1ba51f6 100644 --- a/packages/builder/src/md.ts +++ b/packages/builder/src/md.ts @@ -18,7 +18,7 @@ import type { BuilderMDParams } from './types' * @throws {Error} Throws an error if any of the operations fail, including schema generation, file execution, or file removal. * @see https://backan.pigeonposse.com/guide/builder/ */ -export const buildMD = async ( { app, output }: BuilderMDParams ) => { +export const buildMD = async ( { app, output }: BuilderMDParams ) => { try { diff --git a/packages/builder/src/schema.ts b/packages/builder/src/schema.ts index 0de62ac..6424ff0 100644 --- a/packages/builder/src/schema.ts +++ b/packages/builder/src/schema.ts @@ -12,7 +12,7 @@ import type { BuilderSchemaParams } from './types' * @throws {Error} Throws an error if there is a problem during the file writing operation. * @see https://backan.pigeonposse.com/guide/builder/ */ -export const buildSchema = async ( { app, output }: BuilderSchemaParams ) => { +export const buildSchema = async ( { app, output }: BuilderSchemaParams ) => { try{ diff --git a/packages/builder/src/types.ts b/packages/builder/src/types.ts index 8a8bbb7..5a63e13 100644 --- a/packages/builder/src/types.ts +++ b/packages/builder/src/types.ts @@ -4,31 +4,35 @@ import type { ERROR_ID, } from './const' -export type BuilderMDParams = { +export type BuilderMDParams = { /** * The instance of the Backan application used to generate the OpenAPI schema. */ - app: App, + app: App, /** * The path where the resulting `Markdown` file will be saved. */ output: string } -export type BuilderSchemaParams = { +export type BuilderSchemaParams = { /** * The instance of the Backan application used to generate the OpenAPI schema. */ - app: App, + app: App, /** * The path where the resulting `json` file will be saved. */ output: string } + export type BuilderParams = { /** - * The input file for the build process or app. + * The app server input file. + * + * The input can be provided without an extension. + * If the extension is omitted, the system will automatically look for the following extensions: `.ts`, `.js`, `.mjs`, `.mts`. */ - input: string , + input: string, /** * */ diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 086dc66..b7adae7 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,11 @@ # @backan/core +## 0.0.15 + +### Patch Changes + +- fix issues and update builder for detect input without extensions + ## 0.0.14 ## 0.0.13 diff --git a/packages/core/package.json b/packages/core/package.json index 4cc1c70..c5f126e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@backan/core", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "license": "GPL-3.0", "homepage": "https://backan.pigeonposse.com", diff --git a/packages/core/src/lib/super.ts b/packages/core/src/lib/super.ts index c819c69..e4ce641 100644 --- a/packages/core/src/lib/super.ts +++ b/packages/core/src/lib/super.ts @@ -66,6 +66,7 @@ export class AppSuper { }, } + protected app = new OpenAPIHono( { defaultHook : ( res, c ) => { diff --git a/packages/create/CHANGELOG.md b/packages/create/CHANGELOG.md index 12233a3..709f052 100644 --- a/packages/create/CHANGELOG.md +++ b/packages/create/CHANGELOG.md @@ -1,5 +1,7 @@ # create-backan +## 0.0.15 + ## 0.0.14 ### Patch Changes diff --git a/packages/create/package.json b/packages/create/package.json index d6495ad..5ab6533 100644 --- a/packages/create/package.json +++ b/packages/create/package.json @@ -1,6 +1,6 @@ { "name": "create-backan", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "license": "GPL-3.0", "homepage": "https://backan.pigeonposse.com", diff --git a/packages/docs/CHANGELOG.md b/packages/docs/CHANGELOG.md index c535622..56ba6b2 100644 --- a/packages/docs/CHANGELOG.md +++ b/packages/docs/CHANGELOG.md @@ -1,5 +1,7 @@ # @backan/docs +## 0.0.15 + ## 0.0.14 ## 0.0.13 diff --git a/packages/docs/package.json b/packages/docs/package.json index 0d88612..a6d143d 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@backan/docs", - "version": "0.0.14", + "version": "0.0.15", "description": "Documentation for backan", "type": "module", "repository": { diff --git a/packages/server/CHANGELOG.md b/packages/server/CHANGELOG.md index f7aecee..07a5877 100644 --- a/packages/server/CHANGELOG.md +++ b/packages/server/CHANGELOG.md @@ -1,5 +1,11 @@ # @backan/server +## 0.0.15 + +### Patch Changes + +- fix issues and update builder for detect input without extensions + ## 0.0.14 ### Patch Changes diff --git a/packages/server/examples/app.ts b/packages/server/examples/app.ts index 1274211..7099371 100644 --- a/packages/server/examples/app.ts +++ b/packages/server/examples/app.ts @@ -7,7 +7,8 @@ import { import { bugs } from '../../../package.json' import { version } from '../package.json' -const app = new App( { +type AppEnv = {DB: object} +const app = new App( { version, title : 'BACKAN Example app', description : 'API documentation for BACKAN Example', @@ -34,7 +35,7 @@ const app = new App( { } ) const id = 'random' -const healthRoute = new Route( { +const healthRoute = new Route( { path : id, } ) healthRoute.RESPONSE_MESSAGES.ERROR_400 = 'Error getting random data' diff --git a/packages/server/package.json b/packages/server/package.json index 8367577..b4ed109 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@backan/server", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "license": "GPL-3.0", "homepage": "https://backan.pigeonposse.com", diff --git a/packages/server/src/main.ts b/packages/server/src/main.ts index 0635a87..fc31e1d 100644 --- a/packages/server/src/main.ts +++ b/packages/server/src/main.ts @@ -89,7 +89,7 @@ const tryServe = async ( } /** - * Starts a node server with BACKAN. + * Start a server for BACKAN. * * @template Env - The environment type. * @param {ServerOpts} opts - The server options. diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index c5796e1..2903a34 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -34,7 +34,7 @@ export type ServerOpts = { * The fetch handler for the server. * */ - app: App, + app: InstanceType | App, /** * The port to start the server on. *