Skip to content

Commit

Permalink
✨ feat(all): fix issues and update builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ángel Albiñana Espejo authored and Ángel Albiñana Espejo committed Aug 30, 2024
1 parent c75d136 commit 8b28f5b
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 37 deletions.
9 changes: 6 additions & 3 deletions docs/guide/builder/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand Down Expand Up @@ -104,7 +107,7 @@ export type BuilderSchemaParams = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<object>,
app: App<Env>,
/**
* The path where the resulting `json` file will be saved.
*/
Expand All @@ -131,7 +134,7 @@ type BuilderMDParams = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<object>,
app: App<Env>,
/**
* The path where the resulting `Markdown` file will be saved.
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/backan/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# backan

## 0.0.15

### Patch Changes

- Updated dependencies []:
- @backan/core@0.0.15

## 0.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backan/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/builder/examples/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { App } from '@backan/core'
export const app = new App( {

type AppEnv = {DB: object}
export const app = new App<AppEnv>( {
version : '1.0.0',
title : 'BACKAN Example app',
description : 'API documentation for BACKAN Example',
Expand Down
5 changes: 2 additions & 3 deletions packages/builder/examples/build.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/examples/md.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { buildMD } from '../src/md'
import { app } from './app'

buildMD( {
app : app,
output : 'example-openapi.md',
output : 'openapi.md',
} )
5 changes: 3 additions & 2 deletions packages/builder/examples/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { buildSchema } from '../src/schema'
import { app } from './app'

buildSchema( {
app : app,
output : 'example-openapi.json',
app,
output : 'openapi.json',
} )
9 changes: 2 additions & 7 deletions packages/builder/examples/server.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
30 changes: 28 additions & 2 deletions packages/builder/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 )

Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Env extends object>( { app, output }: BuilderMDParams<Env> ) => {

try {

Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Env extends object> ( { app, output }: BuilderSchemaParams<Env> ) => {

try{

Expand Down
16 changes: 10 additions & 6 deletions packages/builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@ import type {
ERROR_ID,
} from './const'

export type BuilderMDParams = {
export type BuilderMDParams<Env extends object> = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<object>,
app: App<Env>,
/**
* The path where the resulting `Markdown` file will be saved.
*/
output: string
}
export type BuilderSchemaParams = {
export type BuilderSchemaParams<Env extends object> = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<object>,
app: App<Env>,
/**
* 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,
/**
*
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/super.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class AppSuper<Env extends object> {

},
}

protected app = new OpenAPIHono<Env>( {
defaultHook : ( res, c ) => {

Expand Down
2 changes: 2 additions & 0 deletions packages/create/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# create-backan

## 0.0.15

## 0.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @backan/docs

## 0.0.15

## 0.0.14

## 0.0.13
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@backan/docs",
"version": "0.0.14",
"version": "0.0.15",
"description": "Documentation for backan",
"type": "module",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions packages/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/server/examples/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppEnv>( {
version,
title : 'BACKAN Example app',
description : 'API documentation for BACKAN Example',
Expand All @@ -34,7 +35,7 @@ const app = new App( {
} )

const id = 'random'
const healthRoute = new Route( {
const healthRoute = new Route<AppEnv, typeof id>( {
path : id,
} )
healthRoute.RESPONSE_MESSAGES.ERROR_400 = 'Error getting random data'
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const tryServe = async <Env extends object>(
}

/**
* Starts a node server with BACKAN.
* Start a server for BACKAN.
*
* @template Env - The environment type.
* @param {ServerOpts<Env>} opts - The server options.
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type ServerOpts<Env extends object> = {
* The fetch handler for the server.
*
*/
app: App<Env>,
app: InstanceType<typeof App> | App<Env>,
/**
* The port to start the server on.
*
Expand Down

0 comments on commit 8b28f5b

Please sign in to comment.