Skip to content

Commit f367e5c

Browse files
Merge pull request #10 from code4rena-dev/leo95oliveira/bundle-fix
Library Bundling Fix
2 parents bec9b01 + 89e0872 commit f367e5c

File tree

10 files changed

+143
-44
lines changed

10 files changed

+143
-44
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.github/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[![Jest](https://github.com/code4rena-dev/components-library/actions/workflows/test-runner.yml/badge.svg)](https://github.com/code4rena-dev/components-library/actions/workflows/test-runner.yml)
2+
3+
# Code4rena Components Library
4+
---
5+
6+
## Using Components in your project
7+
8+
### 1. Installing the library
9+
Start by installing the components library in your project:
10+
11+
```
12+
npm install @code4rena/components-library
13+
```
14+
15+
### 2. Component Styling
16+
Next, to ensure that all the components have the appropriate styling, **import the library's styles** into your application. This can be done in one of two ways:
17+
18+
1. If you have a global CSS/SCSS file, you can import the custom styles using the CSS import rule into that global file.
19+
```
20+
@import "@code4rena/components-library/styles"
21+
```
22+
2. Another option is to import it in any layout/page/component which wraps your entire web application; in doing so, you make sure the styling bubbles down to all pages of the application using the library's components.
23+
```
24+
import "@code4rena/components-library/styles";
25+
```
26+
27+
### 3. Importing Components
28+
All the components in this package can be accessed through named imports. For a full list of available components, take a look at our [Storybook](https://components-library-wine.vercel.app)
29+
30+
```
31+
import { Alert } from "@code4rena/components-library";
32+
33+
<Alert {...args} />
34+
```
35+
36+
### 4. Typescript Support
37+
All components in this library have TypeScript support. Types for all complex component props are also named exports available through the `/types` subdirectory (see example below):
38+
```
39+
import { ButtonSize, ButtonType, ButtonVariant } from "@code4rena/componenets-library/types";
40+
41+
<Button
42+
label="Sample Button"
43+
type={ButtonType.BUTTON}
44+
variant={ButtonVariant.SECONDARY}
45+
size={ButtonSize.NARROW}
46+
/>
47+
```
48+
49+
## Run Storybook
50+
Storybook will run on [http://localhost:6006](http://localhost:6006)
51+
52+
```
53+
npm run storybook
54+
```
55+
OR
56+
```
57+
yarn storybook
58+
```
59+
60+
### Storybook Actions
61+
If you want to make use of [Storybook actions](https://storybook.js.org/docs/angular/essentials/actions) for a specific component, please refer to the `Input.stories.tsx` file. The recommendation is to pass the event handler function directly to the Story component as opposed to passing it through _ComponentName.args_. Passing the event handler function through the **args** parameter may not log the event in the `Actions` tab of the Story's dashboard.
62+
63+
## Testing
64+
For testing, we are using [Jest](https://jestjs.io/docs/getting-started) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/).
65+
66+
To maintain the standards, test files should be named `componentName.test.tsx` and be placed inside the component folder for which the test relates to.
67+
68+
To run tests you can use the command below (please ensure all tests are passing before creating your PRs)
69+
```
70+
npm test
71+
```
72+
OR
73+
```
74+
yarn test
75+
```
76+
77+
## Publishing to NPM
78+
79+
A GitHub Action has been developed to help automate package releases. All that you will need to do is:
80+
81+
1. Make sure to increase the `version` field in the **package.json**
82+
2. On the GitHub repo's home page, navigate to the righthand side and click on **Create a new release**
83+
3. Give the release a `title` and `description` outlining the changes made in the release
84+
4. Choose/Create a **tag** corresponding to the new version that was added in the package.json in **step 1**
85+
5. Once the details are filled out, submit the release. You will get taken to a confirmation page. This process will automatically trigger the GitHub action that will publish the package to npm.

.github/workflows/release-package.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
- uses: actions/setup-node@v3
2525
with:
2626
node-version: "18"
27-
registry-url: https://npm.pkg.github.com/
27+
registry-url: "https://registry.npmjs.org"
2828
- run: npm ci
2929
- run: npm run build
3030
- run: npm publish --access public
31+
env:
32+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
11
[![Jest](https://github.com/code4rena-dev/components-library/actions/workflows/test-runner.yml/badge.svg)](https://github.com/code4rena-dev/components-library/actions/workflows/test-runner.yml)
22

33
# Code4rena Components Library
4+
---
45

56
## Using Components in your project
67

8+
### 1. Installing the library
79
Start by installing the components library in your project:
810

911
```
1012
npm install @code4rena/components-library
1113
```
1214

13-
Next, to ensure that all the components have the appropriate styling, import the library's css file in your application's wrapping Layout or in any page/component wrapping your application where you would normally import global styling.
15+
### 2. Component Styling
16+
Next, to ensure that all the components have the appropriate styling, **import the library's styles** into your application. This can be done in one of two ways:
17+
18+
1. If you have a global CSS/SCSS file, you can import the custom styles using the CSS import rule into that global file.
19+
```
20+
@import "@code4rena/components-library/styles"
1421
```
15-
import "@code4rena/components-library/dist/style.css";
22+
2. Another option is to import it in any layout/page/component which wraps your entire web application; in doing so, you make sure the styling bubbles down to all pages of the application using the library's components.
23+
```
24+
import "@code4rena/components-library/styles";
1625
```
1726

18-
All the components in this package can be accessed through named imports. For a full list of available components, take a look at our [Storybook](components-library-wine.vercel.app)
27+
### 3. Importing Components
28+
All the components in this package can be accessed through named imports. For a full list of available components, take a look at our [Storybook](https://components-library-wine.vercel.app)
1929

2030
```
2131
import { Alert } from "@code4rena/components-library";
2232
2333
<Alert {...args} />
2434
```
2535

26-
## Run Storybook
27-
Storybook will run on [http://localhost:6006](http://localhost:6006)
28-
29-
```
30-
npm run storybook
31-
```
32-
OR
33-
```
34-
yarn storybook
36+
### 4. Typescript Support
37+
All components in this library have TypeScript support. Types for all complex component props are also named exports available through the `/types` subdirectory (see example below):
3538
```
39+
import { ButtonSize, ButtonType, ButtonVariant } from "@code4rena/componenets-library/types";
3640
37-
### Storybook Actions
38-
If you want to make use of [Storybook actions](https://storybook.js.org/docs/angular/essentials/actions) for a specific component, please refer to the `Button.stories.tsx` file. The recommendation is to pass the event handler function directly to the Story component as opposed to passing it through _ComponentName.args_. Passing the event handler function through the **args** parameter may not log the event in the `Actions` tab of the Story's dashboard.
39-
40-
## Testing
41-
For testing, we are using [Jest](https://jestjs.io/docs/getting-started) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/).
42-
43-
To maintain the standards, test files should be named `componentName.test.tsx` and be placed inside the component folder for which the test relates to.
44-
45-
## Publishing to NPM
46-
47-
A GitHub Action has been developed to help automate package releases. All that you will need to do is:
48-
49-
1. Make sure to increase the `version` field in the **package.json**
50-
2. On the GitHub repo's home page, navigate to the righthand side and click on **Create a new release**
51-
3. Give the release a `title` and `description` outlining the changes made in the release
52-
4. Choose/Create a **tag** corresponding to the new version that was added in the package.json in **step 1**
53-
5. Once the details are filled out, submit the release. You will get taken to a confirmation page. This process will automatically trigger the GitHub action that will publish the package to npm.
41+
<Button
42+
label="Sample Button"
43+
type={ButtonType.BUTTON}
44+
variant={ButtonVariant.SECONDARY}
45+
size={ButtonSize.NARROW}
46+
/>
47+
```

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
{
22
"name": "@code4rena/components-library",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Code4rena's official components library ",
5-
"main": "dist/components-library.umd.js",
6-
"module": "dist/components-library.mjs",
7-
"types": "dist/index.d.ts",
5+
"types": "./dist/lib.d.ts",
6+
"exports": {
7+
".": "./dist/lib.mjs",
8+
"./types": "./dist/types.mjs",
9+
"./styles": "./dist/style.css"
10+
},
11+
"typesVersions": {
12+
"*": {
13+
"types": [
14+
"./dist/types.d.ts"
15+
]
16+
}
17+
},
818
"files": [
9-
"dist"
19+
"/dist"
1020
],
1121
"scripts": {
1222
"build": "vite build && tsc",
@@ -67,14 +77,11 @@
6777
"react": "^18.2.0",
6878
"react-dom": "^18.2.0"
6979
},
70-
"publishConfig": {
71-
"@code4rena:registry": "https://npm.pkg.github.com"
72-
},
7380
"babel": {
7481
"presets": [
7582
"@babel/preset-env",
7683
"@babel/preset-typescript",
7784
"@babel/preset-react"
7885
]
7986
}
80-
}
87+
}

src/index.ts renamed to src/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import "./styles/base/typography.scss";
22

3-
export * from "./lib";
3+
export * from "./lib/index";

src/lib/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export * from "./Alert/Alert.types";
2+
export * from "./Button/Button.types";
3+
export * from "./Card/Card.types";
4+
export * from "./ContestStatus/ContestStatus.types";
5+
export * from "./ContestTile/ContestTile.types";
6+
export * from "./Dropdown/Dropdown.types";
7+
export * from "./EyebrowBar/EyebrowBar.types";
8+
export * from "./Input/Input.types";
9+
export * from "./NavBar/NavBar.types";
10+
export * from "./Tag/Tag.types";

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./lib/types";

vite.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ export default defineConfig ({
66
build: {
77
// Tells Vite we're building library code as opposed to application code
88
lib: {
9-
entry: resolve(__dirname, "src/index.ts"),
9+
entry: {
10+
lib: resolve(__dirname, "src/lib.ts"),
11+
types: resolve(__dirname, "src/types.ts")
12+
},
1013
// Component library name
1114
name: "components-library",
1215
formats: ["es"],
13-
// Output file name
14-
filename: "index",
1516
},
1617
plugins: [dts({ rollupTypes: true })],
1718
rollupOptions: {

0 commit comments

Comments
 (0)