Skip to content

Commit fc37f7b

Browse files
committed
Initial commit
1 parent b8184b5 commit fc37f7b

19 files changed

+12593
-0
lines changed

.github/CODEOWNERS

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence, they will
6+
# be requested for review when someone opens a pull request.
7+
* @prc5
8+
9+
# Order is important; the last matching pattern takes the most
10+
# precedence. When someone opens a pull request that only
11+
# modifies JS files, only @js-owner and not the global
12+
# owner(s) will be requested for a review.
13+
# *.js @js-owner
14+
15+
# You can also use email addresses if you prefer. They'll be
16+
# used to look up users just like we do for commit author
17+
# emails.
18+
19+
20+
# In this example, @doctocat owns any files in the build/logs
21+
# directory at the root of the repository and any of its
22+
# subdirectories.
23+
# /build/logs/ @doctocat
24+
25+
# The `docs/*` pattern will match files like
26+
# `docs/getting-started.md` but not further nested files like
27+
# `docs/build-app/troubleshooting.md`.
28+
29+
30+
# In this example, @octocat owns any file in an apps directory
31+
# anywhere in your repository.
32+
# apps/ @octocat
33+
34+
# In this example, @doctocat owns any file in the `/docs`
35+
# directory in the root of your repository.
36+
# /docs/ @doctocat

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.eslintcache
16+
.idea
17+
.vscode
18+
.DS_Store
19+
.env.local
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
node_modules

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": false,
10+
"proseWrap": "always",
11+
"arrowParens": "always"
12+
}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CHANGELOG
2+
3+
## Version: x.x.x
4+
5+
##### Published: xx.xx.xxxx
6+
7+
-
8+
-
9+
-

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 prc5
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "template",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.11.4",
7+
"@testing-library/react": "^11.1.0",
8+
"@testing-library/user-event": "^12.1.10",
9+
"@types/jest": "^26.0.15",
10+
"@types/node": "^12.0.0",
11+
"@types/react": "^17.0.0",
12+
"@types/react-dom": "^17.0.0",
13+
"react": "^17.0.2",
14+
"react-dom": "^17.0.2",
15+
"react-scripts": "4.0.3",
16+
"typescript": "^4.1.2",
17+
"web-vitals": "^1.0.1"
18+
},
19+
"scripts": {
20+
"start": "react-scripts start",
21+
"build": "react-scripts build",
22+
"test": "react-scripts test",
23+
"eject": "react-scripts eject"
24+
},
25+
"eslintConfig": {
26+
"extends": [
27+
"react-app",
28+
"react-app/jest"
29+
]
30+
},
31+
"browserslist": {
32+
"production": [
33+
">0.2%",
34+
"not dead",
35+
"not op_mini all"
36+
],
37+
"development": [
38+
"last 1 chrome version",
39+
"last 1 firefox version",
40+
"last 1 safari version"
41+
]
42+
},
43+
"devDependencies": {
44+
"@rollup/plugin-babel": "^5.3.0",
45+
"@rollup/plugin-commonjs": "^21.0.0",
46+
"@rollup/plugin-node-resolve": "^13.0.5",
47+
"@svgr/rollup": "^5.5.0",
48+
"@zerollup/ts-transform-paths": "^1.7.18",
49+
"postcss": "^8.3.9",
50+
"reflect-metadata": "^0.1.13",
51+
"rollup": "^2.58.0",
52+
"rollup-plugin-copy": "^3.4.0",
53+
"rollup-plugin-delete": "^2.0.0",
54+
"rollup-plugin-dts": "^4.0.0",
55+
"rollup-plugin-peer-deps-external": "^2.2.4",
56+
"rollup-plugin-postcss": "^4.0.1",
57+
"rollup-plugin-terser": "^7.0.2",
58+
"rollup-plugin-typescript2": "^0.30.0",
59+
"rollup-plugin-url": "^3.0.1"
60+
}
61+
}

rollup.config.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import path from "path";
2+
import { DEFAULT_EXTENSIONS } from "@babel/core";
3+
4+
import pkg from "./package.json";
5+
import resolve from "@rollup/plugin-node-resolve";
6+
import babel from "@rollup/plugin-babel";
7+
import external from "rollup-plugin-peer-deps-external";
8+
import del from "rollup-plugin-delete";
9+
import typescript from "rollup-plugin-typescript2";
10+
import commonjs from "@rollup/plugin-commonjs";
11+
import svgr from "@svgr/rollup";
12+
import url from "rollup-plugin-url";
13+
import postcss from "rollup-plugin-postcss";
14+
import dts from "rollup-plugin-dts";
15+
import copy from "rollup-plugin-copy";
16+
import { terser } from "rollup-plugin-terser";
17+
18+
export default [
19+
{
20+
input: pkg.source,
21+
output: [
22+
{ file: pkg.main, format: "cjs", exports: "named", sourcemap: true },
23+
{ file: pkg.module, format: "esm", exports: "named", sourcemap: true },
24+
],
25+
plugins: [
26+
del({ targets: ["dist/*"] }),
27+
external({
28+
includeDependencies: true,
29+
}),
30+
resolve({
31+
browser: true,
32+
moduleDirectories: ["node_modules", "src"],
33+
}),
34+
commonjs({
35+
include: ["node_modules/**"],
36+
}),
37+
typescript({
38+
declaration: true,
39+
rollupCommonJSResolveHack: true,
40+
}),
41+
babel({
42+
exclude: ["node_modules/**"],
43+
extensions: [...DEFAULT_EXTENSIONS, ".ts", ".tsx"],
44+
}),
45+
postcss({
46+
minimize: true,
47+
extract: "assets/styles/index.css",
48+
modules: {
49+
globalModulePaths: [/^((?!module.css)[\s\S])*$/],
50+
},
51+
}),
52+
url({
53+
fileName: "[dirname][hash][extname]",
54+
sourceDir: path.join(__dirname, "src"),
55+
}),
56+
svgr({
57+
svgoConfig: {
58+
plugins: {
59+
removeViewBox: false,
60+
},
61+
},
62+
}),
63+
copy({
64+
targets: [{ src: "src/assets/styles/light-theme.css", dest: "dist/assets/styles" }],
65+
}),
66+
terser({
67+
compress: true,
68+
}),
69+
],
70+
external: Object.keys(pkg.peerDependencies || {}),
71+
},
72+
{
73+
input: pkg.source,
74+
output: [{ file: pkg.types, format: "es" }],
75+
external: [/\.scss$/, /\.css$/],
76+
plugins: [
77+
dts({
78+
compilerOptions: {
79+
baseUrl: "./src",
80+
},
81+
}),
82+
],
83+
},
84+
];

src/hooks/use-did-mount.hook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { useEffect } from "react";
2+
3+
export const useDidMount = (callback: VoidFunction) => useEffect(callback, []);
4+
5+
export default useDidMount;

src/hooks/use-did-render.hook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { useEffect } from "react";
2+
3+
export const useDidRender = (callback: VoidFunction) => useEffect(callback, []);
4+
5+
export default useDidRender;

src/hooks/use-did-update.hook.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useEffect, useRef } from "react";
2+
3+
export const useDidUpdate = (callback: VoidFunction, dependencies: any[], useOnMount = false) => {
4+
const didMountRef = useRef(useOnMount);
5+
6+
useEffect(() => {
7+
if (!didMountRef.current) {
8+
didMountRef.current = true;
9+
return;
10+
}
11+
12+
return callback();
13+
}, dependencies);
14+
};
15+
16+
export default useDidUpdate;

src/hooks/use-will-unmount.hook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { useEffect } from "react";
2+
3+
export const useWillUnmount = (callback: VoidFunction) => useEffect(() => callback, []);
4+
5+
export default useWillUnmount;

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// export * from "./lib" // export library entry point
2+
3+
export * from "./hooks/use-did-mount.hook";
4+
export * from "./hooks/use-did-render.hook";
5+
export * from "./hooks/use-did-update.hook";
6+
export * from "./hooks/use-will-unmount.hook";

src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

src/reportWebVitals.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReportHandler } from 'web-vitals';
2+
3+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4+
if (onPerfEntry && onPerfEntry instanceof Function) {
5+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6+
getCLS(onPerfEntry);
7+
getFID(onPerfEntry);
8+
getFCP(onPerfEntry);
9+
getLCP(onPerfEntry);
10+
getTTFB(onPerfEntry);
11+
});
12+
}
13+
};
14+
15+
export default reportWebVitals;

src/setupTests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom';

src/tests/todo-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export {}
2+
3+
//TODO

tsconfig.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"noEmit": true,
17+
"downlevelIteration": true,
18+
"jsx": "react-jsx",
19+
"baseUrl": "src",
20+
"experimentalDecorators": true,
21+
"emitDecoratorMetadata": true,
22+
"noImplicitReturns": false,
23+
"strictPropertyInitialization": false
24+
},
25+
"include": ["src"],
26+
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
27+
}

0 commit comments

Comments
 (0)