Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
balzdur committed Jul 10, 2023
1 parent 55debeb commit ac56a97
Show file tree
Hide file tree
Showing 206 changed files with 9,490 additions and 796 deletions.
2,690 changes: 1,895 additions & 795 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,12 @@
"tslib": "^2.6.0",
"winston": "^3.9.0",
"zod": "^3.21.4"
}
},
"workspaces": [
"packages/tailwind-preset",
"packages/typescript-utils",
"packages/marble-api",
"packages/ui-icons",
"packages/ui-design-system"
]
}
25 changes: 25 additions & 0 deletions packages/marble-api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/lib/generated/marble-api.ts"],
"rules": {
"@typescript-eslint/ban-types": "off", // oazapfts generate {} instead of Record<string,empy>
"@typescript-eslint/no-explicit-any": "error" // you should change OAS spec to generate non any types
}
}
]
}
37 changes: 37 additions & 0 deletions packages/marble-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# api-marble

This library generates Marble API client based on `src/scripts/openapi.yaml`.

## Getting started

The generated code can be found in `src/lib/generated/marble-api.ts`

1. Make sure to have `scripts/openapi.yaml` up to date
2. Run `npm run generate-api -w marble-api` to generate the client
3. Review generated code and commit changes

> NB: in case update introduced breaking changes, you may need to resolve TS issues in places the client is used
## Development

### Edit ECMAScript generation process

Change the generation script by editing `scripts/generate.ts`

### Expose some usefull helpers

Change or add files in `src/helpers`

> don't forget to explicitly expose public interface in `src/index.ts`
### Get updated regex to easilly find new operators in backend code

> May be deprcated soon with the new AST based approach
1. Run `npm run operator-regex -w marble-api` to generate the regexp
2. Copy the regexp
3. Use the "Find All" VS Code tab from the backend

![regexp-example-backend](./docs/regexp-example.png)

> NB: make sure to check the regexp box in the VS Code UI
Binary file added packages/marble-api/docs/regexp-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/marble-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "marble-api",
"version": "1.0.0",
"description": "",
"devDependencies": {},
"scripts": {
"generate-api": "node -r esbuild-register scripts/generate.ts",
"operator-regex": "node -r esbuild-register scripts/operator-regexp.ts"
},
"author": "",
"license": "ISC"
}
13 changes: 13 additions & 0 deletions packages/marble-api/scripts/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type Opts } from 'oazapfts/lib/codegen/index';
import { join } from 'path';

export const OPENAPI_SPEC = join('scripts', 'openapi.yaml');

export const GENERATED_FOLDER = join('src', 'generated');
export const GENERATED_API = join(GENERATED_FOLDER, 'marble-api.ts');

export const OPENAPI_OPTIONS: Opts = {
optimistic: true,
useEnumType: false,
unionUndefined: false,
};
38 changes: 38 additions & 0 deletions packages/marble-api/scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mkdir, rm, writeFile } from 'fs/promises';
import { generateSource } from 'oazapfts/lib/codegen/index';
import ora from 'ora';

import {
GENERATED_API,
GENERATED_FOLDER,
OPENAPI_OPTIONS,
OPENAPI_SPEC,
} from './config';

async function openapiGenerator() {
const spinner = ora('Start to generate OpenAPI client...').start();
try {
const code = await generateSource(OPENAPI_SPEC, OPENAPI_OPTIONS);

await writeFile(GENERATED_API, code);

spinner.succeed('Succesfully generated OpenAPI client');
} catch (error) {
spinner.fail('Failed to generate OpenAPI client');
throw error;
}
}

async function main() {
try {
await rm(GENERATED_FOLDER, { recursive: true, force: true });
await mkdir(GENERATED_FOLDER);

await openapiGenerator();
} catch (error) {
console.error('\n', error);
process.exit(1);
}
}

main();
Loading

0 comments on commit ac56a97

Please sign in to comment.