Skip to content

Commit

Permalink
refactor: better types build
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini committed Nov 10, 2023
1 parent fe2e50c commit bff344f
Show file tree
Hide file tree
Showing 11 changed files with 856 additions and 367 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"test": "yarn lerna run test"
},
"devDependencies": {
"@versini/dev-dependencies-client": "1.0.3"
"@versini/dev-dependencies-client": "1.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/documentation/src/modules/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function App() {
<section>
<h2>Buttons</h2>
<Section kind="light">
<ButtonIcon label="Settings">
<ButtonIcon label="Settings" toto="1">
<IconSettings />
</ButtonIcon>
<Button>Default Button</Button>
Expand Down
14 changes: 9 additions & 5 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
"dist"
],
"scripts": {
"build:barrel": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"",
"build:check": "tsc",
"build:js": "vite build",
"build:types": "tsup",
"build": "npm-run-all --serial clean build:check build:js build:types build:barrel",
"clean": "rimraf dist",
"dev": "yarn run clean && vite build --watch --mode development",
"build": "yarn run clean && tsc && vite build && yarn run build:types",
"build:types": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix --color",
"start": "static-server dist --port 5173",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:coverage:ui": "vitest --coverage --ui",
"test:watch": "vitest"
"test:coverage": "vitest run --coverage",
"test:watch": "vitest",
"test": "vitest run",
"types1": "yarn run clean && tsc"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-components/src/common/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingType } from "./commonTypes";
import type { SpacingType } from ".";

const hasOwnProperty = Object.prototype.hasOwnProperty;
const toString = Object.prototype.toString;
Expand Down
23 changes: 14 additions & 9 deletions packages/ui-components/src/components/Button/ButtonTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
export type ButtonProps = {
onClick?: React.MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
export type CommonButtonProps = {
kind?: "dark" | "light";
fullWidth?: boolean;
className?: string;
slim?: boolean;
type?: "button" | "submit" | "reset";
raw?: boolean;
} & {
children?: React.ReactNode;
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
};

export type ButtonProps = {
onClick?: React.MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
type?: "button" | "submit" | "reset";
} & CommonButtonProps & {
children?: React.ReactNode;
} & React.ButtonHTMLAttributes<HTMLButtonElement>;

export type ButtonIconProps = {
label?: string;
children: React.ReactNode;
} & ButtonProps;
} & CommonButtonProps &
React.ButtonHTMLAttributes<HTMLButtonElement>;

export type ButtonLinkProps = {
children?: React.ReactNode;
link?: string;
target?: string;
maxLabelLength?: number;
} & ButtonProps;
} & ButtonProps &
React.AnchorHTMLAttributes<HTMLAnchorElement>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SpacingType } from "../../common/commonTypes";
import { SpacingType } from "../../common";

export type IconsProps = {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingType } from "../../../common/commonTypes";
import type { SpacingType } from "../../../common";

export type SvgIconProps = {
children: React.ReactNode;
Expand Down
12 changes: 12 additions & 0 deletions packages/ui-components/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "tsup";

export default defineConfig({
format: "esm",
entry: {
components: "src/components/index.ts",
common: "src/common/index.d.ts",
},
dts: {
only: true,
},
});
11 changes: 6 additions & 5 deletions packages/ui-components/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { resolve } from "node:path";

import fs from "fs-extra";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";

// import dts from "vite-plugin-dts";

const packageJson = fs.readJSONSync("package.json");

Expand Down Expand Up @@ -51,9 +52,9 @@ export default defineConfig({
"import.meta.env.BUILDVERSION": JSON.stringify(packageJson.version),
},
plugins: [
dts({
include: ["src"],
exclude: ["**/__tests__/**/*", "vite-env.d.ts"],
}),
// dts({
// include: ["src"],
// exclude: ["**/__tests__/**/*", "vite-env.d.ts"],
// }),
],
});
Loading

0 comments on commit bff344f

Please sign in to comment.