diff --git a/.dev/readme.mjs b/.dev/readme.mjs index 04bc845..30b52ea 100644 --- a/.dev/readme.mjs +++ b/.dev/readme.mjs @@ -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, '', '', content ) + + } await addTextBetweenAMark( filePath, '', '', readmeTemp.mark ) await addTextBetweenAMark( filePath, '', '', readmeTemp.content ) await addTextBetweenAMark( filePath, '', '', readmeTemp.index ) @@ -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 ) } diff --git a/.dev/templates/readme.mjs b/.dev/templates/readme.mjs index fa29747..a9b2fe6 100644 --- a/.dev/templates/readme.mjs +++ b/.dev/templates/readme.mjs @@ -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. ` @@ -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 )} ) diff --git a/README.md b/README.md index a1393e3..f397fd5 100644 --- a/README.md +++ b/README.md @@ -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. +## More from Backan + - [Documentation](https://backan.pigeonposse.com/) - πŸ“š [Library](https://backan.pigeonposse.com/guide/core) - 🏁 [Create (setup)]( https://backan.pigeonposse.com/guide/create ) diff --git a/docs/guide/builder/index.md b/docs/guide/builder/index.md index 46fe699..3d5904f 100644 --- a/docs/guide/builder/index.md +++ b/docs/guide/builder/index.md @@ -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 @@ -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. @@ -64,7 +72,7 @@ type BuilderParams = { */ input: string, /** - * + * Binary name. */ name?: string, /** @@ -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' @@ -104,14 +113,20 @@ buildSchema( { ```ts export type BuilderSchemaParams = { - /** - * The instance of the Backan application used to generate the OpenAPI schema. - */ - app: App, - /** - * 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, + /** + * The path where the resulting `json` file will be saved. + */ + output: string + /** + * Generate dts file. + * + * @default true + */ + dts?: boolean } ``` @@ -131,13 +146,43 @@ buildMD( { ```ts type BuilderMDParams = { - /** - * The instance of the Backan application used to generate the OpenAPI schema. - */ - app: App, - /** - * 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, + /** + * 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( { + 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 ) +``` diff --git a/docs/guide/core/route.md b/docs/guide/core/route.md index 8b3c027..8a0faed 100644 --- a/docs/guide/core/route.md +++ b/docs/guide/core/route.md @@ -76,16 +76,5 @@ export type RouteParams = { * @example 'users' */ path: Path - // /** - // * Optional custom messages. - // */ - // msg?: { - // /** - // * Custom message for 400 Bad Request errors. - // * - // * @example 'Invalid request parameters' - // */ - // error400?: string - // } } ``` diff --git a/docs/guide/index.md b/docs/guide/index.md index 3f70a73..5010586 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -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) diff --git a/docs/todo/v1.md b/docs/todo/v1.md index a44a2b3..0acf641 100644 --- a/docs/todo/v1.md +++ b/docs/todo/v1.md @@ -2,7 +2,7 @@ ## 🌈 General -- [ ] Fix and complete README files +- [x] Fix and complete README files ## 🌞 Core @@ -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 diff --git a/packages/_config/CHANGELOG.md b/packages/_config/CHANGELOG.md index a9afdd5..6295191 100644 --- a/packages/_config/CHANGELOG.md +++ b/packages/_config/CHANGELOG.md @@ -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 diff --git a/packages/_config/README.md b/packages/_config/README.md index d5fbf85..065d6c7 100644 --- a/packages/_config/README.md +++ b/packages/_config/README.md @@ -1,7 +1,5 @@ # Backan - Config -> This package contains **_BACKAN_** config for monorepo - [![HEADER](https://raw.githubusercontent.com/pigeonposse/backan/main/docs/public/banner.png)](https://backan.pigeonposse.com/) @@ -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. +> This package contains **_BACKAN_** config for monorepo + + +## More from Backan + - [Documentation](https://backan.pigeonposse.com/) - πŸ“š [Library](https://backan.pigeonposse.com/guide/core) - 🏁 [Create (setup)]( https://backan.pigeonposse.com/guide/create ) diff --git a/packages/_config/package.json b/packages/_config/package.json index 8c7657c..79d6b7a 100644 --- a/packages/_config/package.json +++ b/packages/_config/package.json @@ -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": { diff --git a/packages/_config/src/core/fs.mjs b/packages/_config/src/core/fs.mjs index e946f0e..1ed7505 100644 --- a/packages/_config/src/core/fs.mjs +++ b/packages/_config/src/core/fs.mjs @@ -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( '/' ) } @@ -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 ) diff --git a/packages/backan/CHANGELOG.md b/packages/backan/CHANGELOG.md index 5eca906..2edc280 100644 --- a/packages/backan/CHANGELOG.md +++ b/packages/backan/CHANGELOG.md @@ -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 diff --git a/packages/backan/README.md b/packages/backan/README.md index b40c08d..7a49de5 100644 --- a/packages/backan/README.md +++ b/packages/backan/README.md @@ -1,7 +1,6 @@ # πŸ”₯ Backan All in one web API builder. -Create endpoints with type validations and OpenApi documentation, safely and quickly @@ -18,13 +17,82 @@ Create endpoints with type validations and OpenApi documentation, safely and qui [![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. + +Start building your restAPI app now 🌈. + +## πŸ”‘ Installation + +```bash [npm] +npm install backan +``` +```bash [pnpm] +pnpm i backan +``` +```bash [yarn] +yarn add backan +``` + +[![NPM Version](https://img.shields.io/npm/v/backan?style=for-the-badge&color=yellow)](https://www.npmjs.com/package/backan) + + +### Install only `core` + +```bash [npm] +npm install @backan/core +``` +```bash [pnpm] +pnpm i @backan/core +``` +```bash [yarn] +yarn add @backan/core +``` + +[![NPM Version](https://img.shields.io/npm/v/%40backan%2Fcore?style=for-the-badge&color=yellow)](https://www.npmjs.com/package/@backan/core) + + +## Setup + +You can automatically create a `backan` template with: + +```bash [npm] +npm create backan +``` +```bash [pnpm] +pnpm create backan +``` +```bash [yarn] +yarn create backan +``` + + +