Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: add ci #3

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
.webpack
.data
build
infra
release.config.js
.next
routeTree.gen.ts
30 changes: 26 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "simple-import-sort"],
"plugins": [
"react",
"@typescript-eslint",
"simple-import-sort",
"import",
"unused-imports"
],
"rules": {
"simple-import-sort/imports": "error",
"react/react-in-jsx-scope": "off",
"@typescript-eslint/no-empty-function": "off",
"react/display-name": 0,
"@typescript-eslint/ban-ts-comment": "off",
"react/prop-types": "off",
"(@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-unused-vars": "warn",
"prefer-const": "error"
"@typescript-eslint/no-empty-interface": "off",
"react/no-unescaped-entities": "off",
"@typescript-eslint/no-var-requires": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"import/no-useless-path-segments": ["error"],
"import/no-duplicates": ["error", { "considerQueryString": true }],
"import/no-unassigned-import": ["off"],
"import/newline-after-import": ["error", { "count": 1 }]
},
"settings": {
"react": {
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on: [pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run yarn install
run: yarn install

- name: Run prettier and eslint
run: yarn lint
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dist
.yarn
node_modules
.next

styled-system
styled-system/**
styled-system/**/*
routeTree.gen.ts
build
.docusaurus
37 changes: 37 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"editor.formatOnSave": true,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.insertFinalNewline": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*/lib": true,
"**/*/build": true,
"**/.webpack": true
},
"files.watcherExclude": {
"**/*/lib": true,
"**/*/dist": true,
"**/*/build": true,
"**/.webpack": true,
"**/node_modules": false
},
"search.exclude": {
"**/*/lib": true,
"**/*/dist": true,
"**/*/build": true,
"**/.webpack": true,
"**/.next": true,
"**/node_modules": true
},
"javascript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifier": "relative"
}
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ Let's first create a route on the server:

```typescript title="Route creation with Fastify and Zod"
// server.ts
import { createRoute } from "@http-wizard/core";
import { z } from "zod";
import { createRoute } from '@http-wizard/core';
import { z } from 'zod';

const User = z.object({
id: z.string(),
name: z.string(),
});

export const getUsers = (fastify: FastifyInstance) => {
return createRoute("/users", {
method: "GET",
return createRoute('/users', {
method: 'GET',
schema: {
response: {
200: z.array(User),
Expand All @@ -86,13 +86,13 @@ Now, let's use the Router type on the client:

```typescript title="Client instanciation with axios"
// client.ts
import { createClient, ZodTypeProvider } from "@http-wizard/core";
import axios from "axios";
import { createClient, ZodTypeProvider } from '@http-wizard/core';
import axios from 'axios';

import type { Router } from "./server";
import type { Router } from './server';

const apiClient = createClient<Router, ZodTypeProvider>(axios.instance());
const users = await apiClient.ref("[GET]/users").query({});
const users = await apiClient.ref('[GET]/users').query({});
// users array is safe: { id:string, name:string }[]
```

Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"devDependencies": {},
"dependencies": {
"scripts": {
"lint": "yarn lint:eslint && yarn lint:prettier",
"lint:eslint": "eslint .",
"lint:prettier": "prettier --check ."
},
"devDependencies": {
"typescript": "^5.0.4",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.51.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"prettier": "^3.0.3"
}
}
16 changes: 8 additions & 8 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ Let's first create a route on the server:

```typescript title="Route creation with Fastify and Zod"
// server.ts
import { createRoute } from "@http-wizard/core";
import { z } from "zod";
import { createRoute } from '@http-wizard/core';
import { z } from 'zod';

const User = z.object({
id: z.string(),
name: z.string(),
});

export const getUsers = (fastify: FastifyInstance) => {
return createRoute("/users", {
method: "GET",
return createRoute('/users', {
method: 'GET',
schema: {
response: {
200: z.array(User),
Expand All @@ -86,13 +86,13 @@ Now, let's use the Router type on the client:

```typescript title="Client instanciation with axios"
// client.ts
import { createClient, ZodTypeProvider } from "@http-wizard/core";
import axios from "axios";
import { createClient, ZodTypeProvider } from '@http-wizard/core';
import axios from 'axios';

import type { Router } from "./server";
import type { Router } from './server';

const apiClient = createClient<Router, ZodTypeProvider>(axios.instance());
const users = await apiClient.ref("[GET]/users").query({});
const users = await apiClient.ref('[GET]/users').query({});
// users array is safe: { id:string, name:string }[]
```

Expand Down
6 changes: 3 additions & 3 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
transform: {
"^.+\\.tsx?$": "esbuild-jest",
'^.+\\.tsx?$': 'esbuild-jest',
},
collectCoverageFrom: ["src/**/*.{ts,tsx}"],
testEnvironment: "node",
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
testEnvironment: 'node',
};
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"version": "1.3.16",
"scripts": {
"dev": "tsup src/index.ts --watch",
"typecheck": "tsc",
"build": "tsup src/index.ts --dts",
"test": "jest"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/RouteDefinition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AxiosRequestConfig } from 'axios';

import { SchemaTypeBox } from './providers/TypeboxProvider';
import { SchemaZod } from './providers/ZodProvider';

export type Schema = SchemaTypeBox | SchemaZod;

export type RouteDefinition = {
method: AxiosRequestConfig['method'];
url: string | (({ params }: { params: { [s: string]: string } }) => string);
okCode?: number;
schema: Schema;
};
Loading