Skip to content

Commit 7d1e12b

Browse files
committed
chore(publish): setup publish script
- install @babel/cli - add build and prepublishOnly script - updated the readme - refactor the code base [Chores publish]
1 parent 4ca7cb0 commit 7d1e12b

File tree

10 files changed

+94
-56
lines changed

10 files changed

+94
-56
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
webpack.config.js
22
/webpack
3+
dist

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules
22
/coverage
3+
/dist
34
*.DS_Store

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
<hr />
1818

19-
[![Build Status](https://travis-ci.com/Eazybee/useFormBee.svg?branch=develop)](https://travis-ci.com/Eazybee/useFormBee) <a href="https://codeclimate.com/github/Eazybee/useFormBee/test_coverage"><img src="https://api.codeclimate.com/v1/badges/d103b30217999d81e940/test_coverage" /></a> <a href="https://codeclimate.com/github/Eazybee/useFormBee/maintainability"><img src="https://api.codeclimate.com/v1/badges/d103b30217999d81e940/maintainability" /></a> [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![NPM Version](https://img.shields.io/badge/npm-v1.0.0-blue)](http://makeapullrequest.com)
19+
[![Build Status](https://travis-ci.com/Eazybee/useFormBee.svg?branch=develop)](https://travis-ci.com/Eazybee/useFormBee) <a href="https://codeclimate.com/github/Eazybee/useFormBee/test_coverage"><img src="https://api.codeclimate.com/v1/badges/d103b30217999d81e940/test_coverage" /></a> <a href="https://codeclimate.com/github/Eazybee/useFormBee/maintainability"><img src="https://api.codeclimate.com/v1/badges/d103b30217999d81e940/maintainability" /></a> [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![NPM Version](https://img.shields.io/badge/npm-v1.0.3-blue)](https://www.npmjs.com/package/useformbee)
2020

2121

2222
## The problem
2323
Handling forms in react can be a little bit tedious especially for new beginners like me 😃. **I often find myself re-writing the same stateful logic and form validations**, especially when I have different forms in different components (such as _signup, login, profile update form_).
2424

2525
## Inspiration
26-
My mentor <a href='https://github.com/benfluleck'>@benfluleck</a> suggested I abstract my form logic so that it can easily be reusable. I created a useForm hook and showed it to him and my other colleague. To my surprise, they loved it and adviced that I made some improvements on it and also upload it to [npm](https://npmjs.com) as a library.
26+
My mentor <a href='https://github.com/benfluleck'>@benfluleck</a> suggested I abstract my form logic so that it can easily be reusable. I created a useForm hook and showed it to him and my other colleague. To my surprise, they loved it and adviced that I made some improvements on it and also upload it to [npm](https://npmjs.com/package/useformbee) as a library.
2727

2828
## The solution
2929
**useFormBee** is a custom react hook that helps me manage and abstract form logic.<br>
@@ -77,7 +77,7 @@ const Form = () => {
7777
age: 'numeric',
7878
};
7979

80-
//create you callback function
80+
// create you callback function
8181
const saveFormData = (values) => {
8282
// ...your logic
8383
};
@@ -86,8 +86,8 @@ const Form = () => {
8686
values, handleChange, handleSubmit, errors, handleReset,
8787
} = useFormBee({ callback: saveFormData, rules });
8888

89-
//destructure field values
90-
89+
// destructure field values
90+
9191
// the values is created from Object.keys(rules)
9292
const { firstName, age } = values;
9393

@@ -100,6 +100,7 @@ const Form = () => {
100100
name='firstName'
101101
required
102102
/>
103+
103104
{/* display username error if there is an error */}
104105
{errors.firstName && <p>{errors.firstName }</p>}
105106
<br />
@@ -110,9 +111,11 @@ const Form = () => {
110111
onChange={handleChange}
111112
name='age'
112113
/>
114+
113115
{/* display age error if there is an error */}
114116
{errors.age && <p>{errors.age}</p>}
115117
<br />
118+
116119
<button type='submit'>Submit</button>
117120
<button type='reset'>Reset</button>
118121
</form>
@@ -126,10 +129,10 @@ Thanks goes to these people <a href='https://allcontributors.org/docs/en/emoji-k
126129

127130
<table>
128131
<tr>
129-
<td align="center"><a href="https://github.com/benfluleck"><img src="https://avatars3.githubusercontent.com/u/36575414?s=460&v=4" width="100px;" alt="Ezekiel Ilori"/><br /><sub><b>Ezekiel Ilori</b></sub></a><br /><a href="#" title="Idea">🤔</a> <a href="#" title="Code">💻</a> <a href="#" title="Tests">⚠️</a> <a href="#" title="Doc">📖</a></td>
132+
<td align="center"><a href="https://github.com/Eazybee"><img src="https://avatars3.githubusercontent.com/u/36575414?s=460&v=4" width="100px;" alt="Ezekiel Ilori"/><br /><sub><b>Ezekiel Ilori</b></sub></a><br /><a href="#" title="Idea">🤔</a> <a href="#" title="Code">💻</a> <a href="#" title="Tests">⚠️</a> <a href="#" title="Doc">📖</a></td>
130133
<td align="center"><a href="https://github.com/benfluleck"><img src="https://avatars0.githubusercontent.com/u/26222856?s=400&v=4" width="100px;" alt="Benny Ogidan"/><br /><sub><b>Benny Ogidan</b></sub></a><br /><a href="#" title="Review">👀</a> <a href="#" title="Tests">⚠️</a></td>
131134
</tr>
132135
</table>
133136

134137
## LICENSE
135-
- MIT
138+
- [MIT](https://github.com/Eazybee/useFormBee/blob/develop/LICENSE)

package-lock.json

+56-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2-
"name": "useFormBee",
3-
"version": "1.0.0",
2+
"name": "useformbee",
3+
"version": "1.0.3",
44
"description": "useFormBee is a custom react hook that helps handle form input, validations and other similar functionalities",
5-
"main": "src/index.js",
5+
"main": "dist/hooks/useFormBee.js",
66
"scripts": {
77
"lint": "eslint '**/*js'",
88
"lint:fix": "prettier-eslint '**/*js' --write",
99
"test": "jest",
1010
"clean": "rm -rf build",
1111
"start": "npm run clean && webpack-dev-server --env.mode development --open --hot",
12+
"build": "babel src --out-dir dist",
13+
"prepublishOnly": "npm run build",
1214
"build-dev": "npm run clean && webpack --env.mode development",
1315
"build-prod": "npm run clean && webpack --env.mode production"
1416
},
@@ -29,13 +31,14 @@
2931
"webpack-merge": "^4.2.1"
3032
},
3133
"devDependencies": {
34+
"@babel/cli": "^7.5.5",
3235
"@babel/core": "^7.5.0",
3336
"@babel/node": "^7.5.0",
3437
"@babel/plugin-transform-runtime": "^7.5.0",
3538
"@babel/preset-env": "^7.5.0",
3639
"@babel/preset-react": "^7.0.0",
3740
"@testing-library/jest-dom": "^4.0.0",
38-
"@testing-library/react": "^8.0.7",
41+
"@testing-library/react": "^8.0.9",
3942
"@testing-library/react-hooks": "^1.1.0",
4043
"babel-eslint": "^10.0.2",
4144
"babel-loader": "^8.0.6",
@@ -68,17 +71,17 @@
6871
},
6972
"repository": {
7073
"type": "git",
71-
"url": "git+https://github.com/Eazybee/Webpack.git"
74+
"url": "git+https://github.com/Eazybee/useFormBee.git"
7275
},
7376
"keywords": [
74-
"webpack",
7577
"react",
76-
"configuration"
78+
"useform",
79+
"react form"
7780
],
7881
"author": "Ilori Ezekiel",
7982
"license": "MIT",
8083
"bugs": {
81-
"url": "https://github.com/Eazybee/Webpack/issues"
84+
"url": "https://github.com/Eazybee/useFormBee/issues"
8285
},
83-
"homepage": "https://github.com/Eazybee/Webpack#readme"
86+
"homepage": "https://github.com/Eazybee/useFormBee#readme"
8487
}

src/components/App.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import '../styles/app.css';
3-
import useForm from '../hooks/useForm';
3+
import useFormBee from '../hooks/useFormBee';
44
import Table from './Table';
55

66
const App = () => {
@@ -18,7 +18,7 @@ const App = () => {
1818

1919
const {
2020
values, handleChange, handleSubmit, errors, handleReset,
21-
} = useForm({ callback: login, rules });
21+
} = useFormBee({ callback: login, rules });
2222

2323
const { userName, age } = values;
2424
const {
File renamed without changes.

src/hooks/useForm.spec.js src/hooks/useFormBee.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { renderHook, act } from '@testing-library/react-hooks';
2-
import useForm from './useForm';
2+
import useFormBee from './useFormBee';
33
import {
44
callback, rules, event, getEvent, checkBoxEvent, multipleSelectEvent,
5-
} from '../../test/fixtures/useForm';
5+
} from '../../test/fixtures/useFormBee';
66

77

88
describe('userForm hook', () => {
99
it(' should render', () => {
10-
const { result } = renderHook(() => useForm({ callback, rules }));
10+
const { result } = renderHook(() => useFormBee({ callback, rules }));
1111
const {
1212
values, errors, handleChange, handleSubmit, handleReset,
1313
} = result.current;
@@ -23,7 +23,7 @@ describe('userForm hook', () => {
2323

2424
describe('handleChange function', () => {
2525
it('should update username field value', () => {
26-
const { result } = renderHook(() => useForm({ callback, rules }));
26+
const { result } = renderHook(() => useFormBee({ callback, rules }));
2727
const { handleChange } = result.current;
2828
let valid;
2929

@@ -42,7 +42,7 @@ describe('userForm hook', () => {
4242

4343
it('should have error when passed empty string for a required field',
4444
() => {
45-
const { result } = renderHook(() => useForm({ callback, rules }));
45+
const { result } = renderHook(() => useFormBee({ callback, rules }));
4646
const { handleChange } = result.current;
4747
let valid;
4848

@@ -58,7 +58,7 @@ describe('userForm hook', () => {
5858
});
5959

6060
it('should have error when passed data with invalid data type', () => {
61-
const { result } = renderHook(() => useForm({ callback, rules }));
61+
const { result } = renderHook(() => useFormBee({ callback, rules }));
6262
const { handleChange } = result.current;
6363
let valid;
6464

@@ -75,7 +75,7 @@ describe('userForm hook', () => {
7575
});
7676

7777
it('should update checkbox', () => {
78-
const { result } = renderHook(() => useForm({ callback, rules: { agreement: 'required|boolean' } }));
78+
const { result } = renderHook(() => useFormBee({ callback, rules: { agreement: 'required|boolean' } }));
7979
const { handleChange } = result.current;
8080
let valid;
8181

@@ -91,7 +91,7 @@ describe('userForm hook', () => {
9191
});
9292

9393
it('should update checkbox and display required messaged for a required field', () => {
94-
const { result } = renderHook(() => useForm({ callback, rules: { agreement: 'required|boolean' } }));
94+
const { result } = renderHook(() => useFormBee({ callback, rules: { agreement: 'required|boolean' } }));
9595
const { handleChange } = result.current;
9696
let valid;
9797

@@ -107,7 +107,7 @@ describe('userForm hook', () => {
107107
});
108108

109109
it('should update multiple select', () => {
110-
const { result } = renderHook(() => useForm({
110+
const { result } = renderHook(() => useFormBee({
111111
callback, rules: { friends: ['alpha', { in: ['simi', 'mosimi', 'eazybee'] }] },
112112
}));
113113
const { handleChange } = result.current;
@@ -129,7 +129,7 @@ describe('userForm hook', () => {
129129

130130
describe('handleSubmit function', () => {
131131
it('should submit and call calback function', () => {
132-
const { result } = renderHook(() => useForm(
132+
const { result } = renderHook(() => useFormBee(
133133
{ callback, rules: { username: 'alpha' } },
134134
));
135135

@@ -146,7 +146,7 @@ describe('userForm hook', () => {
146146
});
147147

148148
it('should not submit nor call calback function', () => {
149-
const { result } = renderHook(() => useForm({ callback, rules }));
149+
const { result } = renderHook(() => useFormBee({ callback, rules }));
150150
const { handleSubmit } = result.current;
151151

152152
let callbackResponse;
@@ -164,7 +164,7 @@ describe('userForm hook', () => {
164164

165165
describe('handleReset function', () => {
166166
it('should clear all inputs field when called', () => {
167-
const { result } = renderHook(() => useForm({ callback, rules }));
167+
const { result } = renderHook(() => useFormBee({ callback, rules }));
168168

169169
const { handleReset } = result.current;
170170

test/fixtures/selectForm.js

-25
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)