Skip to content

Commit

Permalink
Merge pull request #456 from hey-api/feat/client-axios
Browse files Browse the repository at this point in the history
Client packages 📦
  • Loading branch information
mrlubos authored Apr 23, 2024
2 parents 09935b4 + e549d06 commit ab77695
Show file tree
Hide file tree
Showing 49 changed files with 1,788 additions and 428 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.9.0
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
**/node_modules
**/templates
**/dist
**/.vitepress
**/.vitepress/cache
**/.vitepress/dist
**/test/e2e

**/CHANGELOG.md
Expand Down
34 changes: 22 additions & 12 deletions docs/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import { defineConfig } from 'vitepress';

export default defineConfig({
description: 'Turn your OpenAPI specification into a beautiful TypeScript client',
description:
'Turn your OpenAPI specification into a beautiful TypeScript client',
lang: 'en-US',
themeConfig: {
sidebar: [
{
text: 'openapi-ts',
items: [
{ text: 'Get Started', link: '/openapi-ts/get-started' },
{ text: 'Configuration', link: '/openapi-ts/configuration' },
{ text: 'Clients <span class="soon">soon</span>', link: '/openapi-ts/clients' },
{ text: 'Interceptors', link: '/openapi-ts/interceptors' },
{ text: 'Integrations <span class="soon">soon</span>', link: '/openapi-ts/integrations' },
{ text: 'TanStack Query <span class="soon">soon</span>', link: '/openapi-ts/tanstack-query' },
{ text: 'Migrating', link: '/openapi-ts/migrating' },
{ link: '/openapi-ts/get-started', text: 'Get Started' },
{ link: '/openapi-ts/configuration', text: 'Configuration' },
{
link: '/openapi-ts/clients',
text: 'Clients <span class="soon">soon</span>',
},
{ link: '/openapi-ts/interceptors', text: 'Interceptors' },
{
link: '/openapi-ts/integrations',
text: 'Integrations <span class="soon">soon</span>',
},
{
link: '/openapi-ts/tanstack-query',
text: 'TanStack Query <span class="soon">soon</span>',
},
{ link: '/openapi-ts/migrating', text: 'Migrating' },
],
text: 'openapi-ts',
},
{
text: '@hey-api',
items: [
{ text: 'Philosophy', link: '/about' },
{ text: 'Contributing', link: '/contributing' },
{ link: '/about', text: 'Philosophy' },
{ link: '/contributing', text: 'Contributing' },
],
text: '@hey-api',
},
],
},
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import en from './en';
import shared from './shared';

export default defineConfig({
...shared,
locales: {
root: { label: 'English', ...en },
},
...shared,
locales: {
root: { label: 'English', ...en },
},
});
61 changes: 36 additions & 25 deletions docs/.vitepress/config/shared.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
import { defineConfig } from 'vitepress';

export default defineConfig({
title: 'Hey API',
lastUpdated: false,
sitemap: {
hostname: 'https://heyapi.vercel.app',
head: [
['link', { href: '/logo.png', rel: 'icon', type: 'image/png' }],
['meta', { content: 'website', property: 'og:type' }],
['meta', { content: 'en', property: 'og:locale' }],
[
'meta',
{
content:
'Turn your OpenAPI specification into a beautiful TypeScript client',
property: 'og:title',
},
],
['meta', { content: 'OpenAPI TypeScript', property: 'og:site_name' }],
['meta', { content: '/logo.png', property: 'og:image' }],
['meta', { content: 'https://heyapi.vercel.app', property: 'og:url' }],
[
'script',
{},
'window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };',
],
['script', { defer: '', src: '/_vercel/insights/script.js' }],
],
lastUpdated: false,
sitemap: {
hostname: 'https://heyapi.vercel.app',
},
themeConfig: {
externalLinkIcon: true,
logo: '/logo.png',
search: {
provider: 'local',
},
head: [
['link', { rel: 'icon', type: 'image/png', href: '/logo.png' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: 'en' }],
['meta', { property: 'og:title', content: 'Turn your OpenAPI specification into a beautiful TypeScript client' }],
['meta', { property: 'og:site_name', content: 'OpenAPI TypeScript' }],
['meta', { property: 'og:image', content: '/logo.png' }],
['meta', { property: 'og:url', content: 'https://heyapi.vercel.app' }],
['script', {}, 'window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };'],
['script', { defer: '', src: '/_vercel/insights/script.js' }],
socialLinks: [
{ icon: 'npm', link: 'https://npmjs.com/package/@hey-api/openapi-ts' },
{ icon: 'github', link: 'https://github.com/hey-api/openapi-ts' },
],
themeConfig: {
externalLinkIcon: true,
logo: '/logo.png',
socialLinks: [
{ icon: 'npm', link: 'https://npmjs.com/package/@hey-api/openapi-ts' },
{ icon: 'github', link: 'https://github.com/hey-api/openapi-ts' },
],
search: {
provider: 'local',
}
}
},
title: 'Hey API',
});
38 changes: 19 additions & 19 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
:root {
--c-gradient-start: #d486b8;
--vp-c-brand-1: #a37ab4;
--vp-c-brand-2: #d486b8;
--vp-c-brand-3: #a37ab4;
--c-gradient-start: #d486b8;
--vp-c-brand-1: #a37ab4;
--vp-c-brand-2: #d486b8;
--vp-c-brand-3: #a37ab4;
}

html.dark {
--c-gradient-start: #86b9b0;
--vp-c-bg: #001b2e;
--vp-c-bg-alt: #041421;
--vp-c-bg-soft: #041421;
--vp-c-brand-1: #b3cde4;
--vp-c-brand-2: #b3cde4;
--vp-c-brand-3: #537692;
--c-gradient-start: #86b9b0;
--vp-c-bg: #001b2e;
--vp-c-bg-alt: #041421;
--vp-c-bg-soft: #041421;
--vp-c-brand-1: #b3cde4;
--vp-c-brand-2: #b3cde4;
--vp-c-brand-3: #537692;
}

.soon {
background-color: var(--vp-button-brand-bg);
border-radius: 1em;
color: var(--vp-button-brand-text);
font-size: .6em;
padding: .2em .4em;
position: relative;
text-transform: lowercase;
top: -1em;
background-color: var(--vp-button-brand-bg);
border-radius: 1em;
color: var(--vp-button-brand-text);
font-size: 0.6em;
padding: 0.2em 0.4em;
position: relative;
text-transform: lowercase;
top: -1em;
}
3 changes: 2 additions & 1 deletion docs/.vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DefaultTheme from 'vitepress/theme';
import './custom.css';

import DefaultTheme from 'vitepress/theme';

export default DefaultTheme;
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# openapi-ts-docs
# @hey-api/docs

## 0.5.2

Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "openapi-ts-docs",
"name": "@hey-api/docs",
"version": "0.5.2",
"description": "Documentation for OpenaAPI TypeScript.",
"private": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/openapi-ts/eslint.config.js → eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default tseslint.config(
'temp/',
'**/test/e2e/generated/',
'**/test/generated/',
'**/.vitepress/cache',
'**/.vitepress/dist',
],
},
);
28 changes: 24 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
"scripts": {
"build": "pnpm --recursive build",
"changeset": "changeset",
"docs": "pnpm --filter openapi-ts-docs --",
"client-axios": "pnpm --filter @hey-api/client-axios --",
"client-core": "pnpm --filter @hey-api/client-core --",
"client-fetch": "pnpm --filter @hey-api/client-fetch --",
"client-nextjs": "pnpm --filter @hey-api/client-nextjs --",
"docs": "pnpm --filter @hey-api/docs --",
"format": "prettier --write .",
"lint:fix": "prettier --check . && pnpm --recursive lint:fix",
"lint": "prettier --check . && pnpm --recursive lint",
"lint:fix": "prettier --check . && eslint . --fix",
"lint": "prettier --check . && eslint .",
"openapi-ts": "pnpm --filter @hey-api/openapi-ts --",
"prepare": "husky",
"test:coverage": "pnpm --recursive test:coverage",
Expand All @@ -33,10 +37,26 @@
},
"devDependencies": {
"@changesets/cli": "2.27.1",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "11.1.6",
"@svitejs/changesets-changelog-github-compact": "1.1.0",
"@types/node": "20.12.7",
"@vitest/coverage-v8": "1.5.0",
"eslint": "9.1.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-simple-import-sort": "12.1.0",
"eslint-plugin-sort-keys-fix": "1.1.2",
"globals": "15.0.0",
"husky": "9.0.11",
"lint-staged": "15.2.2",
"prettier": "3.2.5"
"prettier": "3.2.5",
"rimraf": "5.0.5",
"rollup": "4.16.1",
"rollup-plugin-dts": "6.1.0",
"typescript": "5.4.5",
"typescript-eslint": "7.7.0",
"vitest": "1.5.0"
},
"packageManager": "pnpm@8.15.7+sha256.50783dd0fa303852de2dd1557cd4b9f07cb5b018154a6e76d0f40635d6cee019"
}
59 changes: 59 additions & 0 deletions packages/client-axios/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@hey-api/client-axios",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "Type-safe Axios client for your openapi-ts types",
"homepage": "https://heyapi.vercel.app/",
"repository": {
"type": "git",
"url": "git+https://github.com/hey-api/openapi-ts.git"
},
"bugs": {
"url": "https://github.com/hey-api/openapi-ts/issues"
},
"license": "MIT",
"keywords": [
"axios",
"client",
"codegen",
"generator",
"javascript",
"openapi",
"react",
"svelte",
"swagger",
"typescript",
"vue"
],
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"scripts": {
"build-bundle": "rollup --config rollup.config.ts --configPlugin typescript",
"build-types-check": "tsc --project tsconfig.check.json",
"build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp",
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src",
"build-types": "pnpm build-types-temp && pnpm build-types-roll && pnpm build-types-check",
"build": "pnpm clean && pnpm build-bundle && pnpm build-types",
"clean": "rimraf dist coverage node_modules/.cache",
"dev": "rimraf dist && pnpm build-bundle --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --coverage",
"test:update": "vitest watch --update",
"test:watch": "vitest watch",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"engines": {
"node": "^18.0.0 || >=20.0.0"
},
"dependencies": {
"@hey-api/client-core": "workspace:*"
},
"peerDependencies": {
"axios": ">= 1.0.0 < 2"
},
"devDependencies": {
"axios": "1.6.8"
}
}
47 changes: 47 additions & 0 deletions packages/client-axios/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import type { RollupOptions } from 'rollup';
import { defineConfig } from 'rollup';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url)).toString(),
);

export const externalDependencies = [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
];

function createConfig(isProduction: boolean) {
return defineConfig({
external: externalDependencies,
input: path.resolve(__dirname, 'src/index.ts'),
output: {
file: path.resolve(__dirname, 'dist/index.cjs'),
format: 'cjs',
},
plugins: [
typescript({
declaration: false,
tsconfig: path.resolve(__dirname, 'src/tsconfig.json'),
}),
commonjs({
sourceMap: false,
}),
isProduction && terser(),
],
});
}

export default (commandLineArgs: any): RollupOptions[] => {
const isDev = commandLineArgs.watch;
const isProduction = !isDev;
return defineConfig([createConfig(isProduction)]);
};
16 changes: 16 additions & 0 deletions packages/client-axios/rollup.dts.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'rollup';
import dts from 'rollup-plugin-dts';

import { externalDependencies } from './rollup.config';

export default defineConfig({
external: externalDependencies,
input: {
index: './temp/index.d.ts',
},
output: {
dir: './dist',
format: 'cjs',
},
plugins: [dts({ respectExternal: true })],
});
7 changes: 7 additions & 0 deletions packages/client-axios/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, expect, it } from 'vitest';

describe('Axios client', () => {
it('works', () => {
expect(1).toBe(1);
});
});
Loading

0 comments on commit ab77695

Please sign in to comment.