Skip to content

Commit

Permalink
✨ feat(all): add feats to builder like: create client, create types d…
Browse files Browse the repository at this point in the history
…efinition etc
  • Loading branch information
angelespejo committed Sep 13, 2024
1 parent 8bfc2ad commit 78caa31
Show file tree
Hide file tree
Showing 40 changed files with 1,215 additions and 105 deletions.
79 changes: 65 additions & 14 deletions .dev/readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,67 @@ import { readme } from './templates/readme.mjs'
import {
pkg,
addTextBetweenAMark,
execProcess,
execProcess,
readFile,
existPath,
joinPath,
paths,
joinUrl,
} from '@backan/config/core'

await execProcess( {
name : 'CHANGE README',
on : async ( ) => {

const readmeTemp = readme( pkg )
const convertReadme = async filePath => {
const getContent = content => {

const lines = content.split( '\n' )
.filter( line => !line.startsWith( ':::' ) ) // Filtrar líneas que no empiezan por ':::'
const index = lines.findIndex( line => line.startsWith( '#' ) )
return index === -1 ? content : lines.slice( index + 1 ).join( '\n' ).trim()

}

const replaceRelativeUrls = ( inputString, baseUrl, basePath ) =>{

const regex = /(src="|]\()(\.{1,2}|\/)([^\s'")]+)/g

const result = inputString.replace( regex, ( match, prefix, relativeType, path ) => {

path = path.replace( /\.md$/, '' )
// console.log( {
// prefix,baseUrl, path, relativeType,
// } )
if ( relativeType === '/' ) return prefix + '' + joinUrl( baseUrl, path )

if ( relativeType === '..' ) return prefix + '' + joinUrl( baseUrl, basePath.split( '/' )[0] ,path )

return prefix + '' + joinUrl( baseUrl, basePath, path )

} )

return result

}
const readmeTemp = readme( pkg )

const convertReadme = async id => {

const filePath = id === 'monorepo' ? 'README.md' : joinPath( paths.workspaceDir,'packages', id, 'README.md' )
const docsPathID = id === 'backan' ? 'core' : id
const docsPath = joinPath( paths.workspaceDir, 'docs', 'guide', docsPathID, 'index.md' )
const existsDocs = await existPath( docsPath )

if( existsDocs ){

const content = replaceRelativeUrls(
getContent( await readFile( docsPath ) ),
pkg.data.homepage,
joinPath( 'guide', docsPathID ),
)
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START DOCS -->', '<!-- PIGEONPOSSE END DOCS -->', content )

}
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START MARK -->', '<!-- PIGEONPOSSE END MARK -->', readmeTemp.mark )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START CONTENT -->', '<!-- PIGEONPOSSE END CONTENT -->', readmeTemp.content )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START INDEX -->', '<!-- PIGEONPOSSE END INDEX -->', readmeTemp.index )
Expand All @@ -26,20 +77,20 @@ await execProcess( {

}

const readmePaths = [
'README.md',
'packages/_config/README.md',
'packages/backan/README.md',
'packages/builder/README.md',
'packages/core/README.md',
'packages/create/README.md',
'packages/docs/README.md',
'packages/server/README.md',
const ids = [
'monorepo',
'_config',
'backan',
'builder',
'core',
'create',
'docs',
'server',
]

for ( const path of readmePaths ) {
for ( const id of ids ) {

await convertReadme( path )
await convertReadme( id )

}

Expand Down
4 changes: 3 additions & 1 deletion .dev/templates/readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ${
}
[![Version](https://img.shields.io/npm/v/${pkg.data.extra.libraryId}?color=blue&style=for-the-badge&label=Version)](${pkg.data.extra.libraryUrl})
Create endpoints with type validations and OpenApi documentation, safely and quickly.
[**BACKAN**](${pkg.data.homepage}) Create endpoints with type validations and OpenApi documentation, safely and quickly.
`

Expand All @@ -80,6 +80,8 @@ Create endpoints with type validations and OpenApi documentation, safely and qui
const index = pkg => {

return `
## More from Backan
- [Documentation](${pkg.data.homepage})
- 📚 [Library](${joinUrl( pkg.data.homepage, pkg.data.extra.docsPath.core )})
- 🏁 [Create (setup)]( ${joinUrl( pkg.data.homepage, pkg.data.extra.docsPath.create )} )
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ DEVELOPED BY Angelo 🐦🌈
[![License](https://img.shields.io/github/license/pigeonposse/backan?color=green&style=for-the-badge&logoColor=white)](/LICENSE)
[![Version](https://img.shields.io/npm/v/backan?color=blue&style=for-the-badge&label=Version)](https://www.npmjs.com/package/backan)

Create endpoints with type validations and OpenApi documentation, safely and quickly.
[**BACKAN**](https://backan.pigeonposse.com/) Create endpoints with type validations and OpenApi documentation, safely and quickly.


<!-- PIGEONPOSSE END HEADER -->

<!-- PIGEONPOSSE START INDEX -->

## More from Backan

- [Documentation](https://backan.pigeonposse.com/)
- 📚 [Library](https://backan.pigeonposse.com/guide/core)
- 🏁 [Create (setup)]( https://backan.pigeonposse.com/guide/create )
Expand Down
83 changes: 64 additions & 19 deletions docs/guide/builder/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# *Backan* `Builder`

Compile your `backan` server into multiple binaries, available for each **platform** and **architecture**.
The backan builder library allows you to build multiple things. Among others:

- [**Executables / binaries**](#build-binaries)
- [**client library**](#create-client)
- [**JSON schema file**](#build-json-types-schema)
- [**TypeScript definitions file**](#build-json-types-schema)
- [**Markdown documentation**](#build-markdown-documentation)

## 🔑 Installation

Expand All @@ -24,6 +30,8 @@ yarn add @backan/builder

## Build `binaries`

Package your Node.js project into an executable that can be run even on devices without Node.js installed.

The construction of the binary allows compilation on `arm` and `x64` architecture.
> If you compile on an `x64` system it will not create the binaries for `arm`, but if you compile on `arm` it will create the binaries for both architectures.
Expand Down Expand Up @@ -64,7 +72,7 @@ type BuilderParams = {
*/
input: string,
/**
*
* Binary name.
*/
name?: string,
/**
Expand All @@ -85,10 +93,11 @@ type BuilderParams = {
* @default 'all'
*/
type?: 'all'|'cjs'|'bin'

}
```
## Build `JSON` schema
## Build `JSON` | `Types` schema
```js
import {buildSchema} from '@backan/builder'
Expand All @@ -104,14 +113,20 @@ buildSchema( {

```ts
export type BuilderSchemaParams = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<Env>,
/**
* The path where the resulting `json` file will be saved.
*/
output: string
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<Env>,
/**
* The path where the resulting `json` file will be saved.
*/
output: string
/**
* Generate dts file.
*
* @default true
*/
dts?: boolean
}
```
Expand All @@ -131,13 +146,43 @@ buildMD( {

```ts
type BuilderMDParams = {
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<Env>,
/**
* The path where the resulting `Markdown` file will be saved.
*/
output: string
/**
* The instance of the Backan application used to generate the OpenAPI schema.
*/
app: App<Env>,
/**
* The path where the resulting `Markdown` file will be saved.
*/
output: string
}
```
## Create client
Create a client for your `backan` API and make your frontend app able to access your API easily and with type. To achieve this, backan makes use of the [`openapi-featch`](https://openapi-ts.dev/openapi-fetch/) library.
```ts
import { createClient } from '@backan/builder'
import type { paths } from './openapi.d.ts' // Generate with buildSchema
const client = createClient<paths>( {
baseUrl : 'http://localhost:1312/',
} )

export {client}

```
### Example of call

```ts
import {client} from './client'
const response = await client.GET( '/random/child', {
params : {
query : {
value : 'myValue',
},
},
} )

console.log( response )
```
11 changes: 0 additions & 11 deletions docs/guide/core/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,5 @@ export type RouteParams<Path extends string> = {
* @example 'users'
*/
path: Path
// /**
// * Optional custom messages.
// */
// msg?: {
// /**
// * Custom message for 400 Bad Request errors.
// *
// * @example 'Invalid request parameters'
// */
// error400?: string
// }
}
```
10 changes: 7 additions & 3 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ Start building your restAPI app now 🌈.

## 📦 Build your project

- Create [`binaries`](./builder/index.md#build-binaries) of your project for all **systems** and **architectures** with zero config.
- Export the `OpenAPI schema` to a [`JSON file`](./builder/index.md#build-json-schema).
- Build your application documentation in a [`Markdown file`](./builder/index.md#build-markdown-documentation).
The backan builder library allows you to build multiple things. Among others:

- [**`Executables / binaries`**](./builder/index.md#build-binaries): Create binaries of your project for all **systems** and **architectures** with zero config.
- [**`Client library`**](./builder/index.md#create-client): Create a client to facilitate the implementation of the API in a frontend or other service.
- [**`JSON schema file`**](./builder/index.md#build-json-types-schema): Export the **OpenAPI schema** to a **JSON file**.
- [**`TypeScript definitions file`**](./builder/index.md#build-json-types-schema): Export **OpenAPI schema** to a **d.ts file**.
- [**`Markdown documentation`**](./builder/index.md#build-markdown-documentation): Build your application documentation in a **Markdown file**.

[Read more](./builder/index.md)
4 changes: 3 additions & 1 deletion docs/todo/v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 🌈 General

- [ ] Fix and complete README files
- [x] Fix and complete README files

## 🌞 Core

Expand All @@ -23,7 +23,9 @@

## 📦 Builder

- [x] Add `createClient` function
- [x] Add `json schema file` build of backan library
- [x] Add `d.ts schema file` build of backan library
- [x] Add `markdown documentation file` build of backan library
- [x] Add to the input option the possibility of adding the backan app method
- [x] Fix esbuild problem
Expand Down
6 changes: 6 additions & 0 deletions packages/_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @backan/config

## 0.0.8

### Patch Changes

- add feats to builder like: create client, create types definition etc

## 0.0.7

### Patch Changes
Expand Down
9 changes: 6 additions & 3 deletions packages/_config/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Backan - Config

> This package contains **_BACKAN_** config for monorepo
<!-- PIGEONPOSSE START HEADER -->

[![HEADER](https://raw.githubusercontent.com/pigeonposse/backan/main/docs/public/banner.png)](https://backan.pigeonposse.com/)
Expand All @@ -17,13 +15,18 @@
[![License](https://img.shields.io/github/license/pigeonposse/backan?color=green&style=for-the-badge&logoColor=white)](/LICENSE)
[![Version](https://img.shields.io/npm/v/backan?color=blue&style=for-the-badge&label=Version)](https://www.npmjs.com/package/backan)

Create endpoints with type validations and OpenApi documentation, safely and quickly.
[**BACKAN**](https://backan.pigeonposse.com/) Create endpoints with type validations and OpenApi documentation, safely and quickly.


<!-- PIGEONPOSSE END HEADER -->

> This package contains **_BACKAN_** config for monorepo

<!-- PIGEONPOSSE START INDEX -->

## More from Backan

- [Documentation](https://backan.pigeonposse.com/)
- 📚 [Library](https://backan.pigeonposse.com/guide/core)
- 🏁 [Create (setup)]( https://backan.pigeonposse.com/guide/create )
Expand Down
2 changes: 1 addition & 1 deletion packages/_config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@backan/config",
"version": "0.0.7",
"version": "0.0.8",
"description": "Configuration files for monorepo",
"type": "module",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions packages/_config/src/core/fs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ export const writeSync = ( projectPath, txt ) => {
export const joinPath = path.join
export const joinUrl = ( ...parts ) => {

// Eliminar barras inclinadas adicionales al principio y al final de cada parte
parts = parts.map( part => part.replace( /^\/+|\/+$/g, '' ) )
// Unir las partes con una barra inclinada entre ellas

return parts.join( '/' )

}
Expand All @@ -323,7 +322,7 @@ export const addTextBetweenAMark = async ( projectPath, startMarker, endMarker,

try {

const filePath = path.join( pkg.dir, projectPath )
const filePath = projectPath
const fileContent = await fs.promises.readFile( filePath, 'utf-8' )
const startIndex = fileContent.indexOf( startMarker )
const endIndex = fileContent.indexOf( endMarker )
Expand Down
9 changes: 9 additions & 0 deletions packages/backan/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# backan

## 0.0.18

### Patch Changes

- add feats to builder like: create client, create types definition etc

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

## 0.0.17

### Patch Changes
Expand Down
Loading

0 comments on commit 78caa31

Please sign in to comment.