Skip to content

Commit

Permalink
refactor: Reduce lib size by removing indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Sep 22, 2022
1 parent 2b5421b commit abf633c
Show file tree
Hide file tree
Showing 43 changed files with 80 additions and 119 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ npm run test
```bash
📂 ./src
├── 📂 useHookName
│ ├── 📄 index.ts # used for exports
│ ├── 📄 useHookName.demo.tsx # working demo
│ ├── 📝 useHookName.mdx # the documentation content
│ ├── 🧪 useHookName.test.ts # unit tests
Expand Down
7 changes: 0 additions & 7 deletions plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ module.exports = function (plop) {
},
],
actions: [
// Create the hook index file (for quick export)
{
type: 'add',
path: 'src/{{camelCase name}}/index.ts',
templateFile: 'templates/plop/hooks/hook/index.ts.hbs',
},

// Create the hook file itself
{
type: 'add',
Expand Down
8 changes: 6 additions & 2 deletions scripts/copyHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ function copyFile({ source, dest, useSandbox, toMarkdown }: CopyFileProps) {

if (toMarkdown) {
// rename import from "from '..'" to "from 'usehooks-ts'"
const re = new RegExp("^import { (use[A-Z][a-zA-Z]*..)+ } from '..'$")
const regex = new RegExp("from '..'$")

const transform = (line: string) => {
return line.replace(re, match => match.replace('..', 'usehooks-ts'))
return regex.test(line)
? line.replace("from '..'", "from 'usehooks-ts'")
: line
}

data = data.split('\n').map(transform).join('\n')

// wrap code into markdown code tags
Expand Down
105 changes: 70 additions & 35 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,70 @@
export * from './useBoolean'
export * from './useClickAnyWhere'
export * from './useCopyToClipboard'
export * from './useCountdown'
export * from './useCounter'
export * from './useDarkMode'
export * from './useDebounce'
export * from './useEffectOnce'
export * from './useElementSize'
export * from './useEventCallback'
export * from './useEventListener'
export * from './useFetch'
export * from './useHover'
export * from './useImageOnLoad'
export * from './useIntersectionObserver'
export * from './useInterval'
export * from './useIsClient'
export * from './useIsFirstRender'
export * from './useIsMounted'
export * from './useIsomorphicLayoutEffect'
export * from './useLocalStorage'
export * from './useLockedBody'
export * from './useMap'
export * from './useMediaQuery'
export * from './useOnClickOutside'
export * from './useReadLocalStorage'
export * from './useScreen'
export * from './useScript'
export * from './useSessionStorage'
export * from './useSsr'
export * from './useStep'
export * from './useTernaryDarkMode'
export * from './useTimeout'
export * from './useUpdateEffect'
export * from './useWindowSize'
export { default as useBoolean } from './useBoolean/useBoolean'
export * from './useBoolean/useBoolean'
export { default as useClickAnyWhere } from './useClickAnyWhere/useClickAnyWhere'
export * from './useClickAnyWhere/useClickAnyWhere'
export { default as useCopyToClipboard } from './useCopyToClipboard/useCopyToClipboard'
export * from './useCopyToClipboard/useCopyToClipboard'
export { default as useCountdown } from './useCountdown/useCountdown'
export * from './useCountdown/useCountdown'
export { default as useCounter } from './useCounter/useCounter'
export * from './useCounter/useCounter'
export { default as useDarkMode } from './useDarkMode/useDarkMode'
export * from './useDarkMode/useDarkMode'
export { default as useDebounce } from './useDebounce/useDebounce'
export * from './useDebounce/useDebounce'
export { default as useEffectOnce } from './useEffectOnce/useEffectOnce'
export * from './useEffectOnce/useEffectOnce'
export { default as useElementSize } from './useElementSize/useElementSize'
export * from './useElementSize/useElementSize'
export { default as useEventCallback } from './useEventCallback/useEventCallback'
export * from './useEventCallback/useEventCallback'
export { default as useEventListener } from './useEventListener/useEventListener'
export * from './useEventListener/useEventListener'
export { default as useFetch } from './useFetch/useFetch'
export * from './useFetch/useFetch'
export { default as useHover } from './useHover/useHover'
export * from './useHover/useHover'
export { default as useImageOnLoad } from './useImageOnLoad/useImageOnLoad'
export * from './useImageOnLoad/useImageOnLoad'
export { default as useIntersectionObserver } from './useIntersectionObserver/useIntersectionObserver'
export * from './useIntersectionObserver/useIntersectionObserver'
export { default as useInterval } from './useInterval/useInterval'
export * from './useInterval/useInterval'
export { default as useIsClient } from './useIsClient/useIsClient'
export * from './useIsClient/useIsClient'
export { default as useIsFirstRender } from './useIsFirstRender/useIsFirstRender'
export * from './useIsFirstRender/useIsFirstRender'
export { default as useIsMounted } from './useIsMounted/useIsMounted'
export * from './useIsMounted/useIsMounted'
export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect'
export * from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect'
export { default as useLocalStorage } from './useLocalStorage/useLocalStorage'
export * from './useLocalStorage/useLocalStorage'
export { default as useLockedBody } from './useLockedBody/useLockedBody'
export * from './useLockedBody/useLockedBody'
export { default as useMap } from './useMap/useMap'
export * from './useMap/useMap'
export { default as useMediaQuery } from './useMediaQuery/useMediaQuery'
export * from './useMediaQuery/useMediaQuery'
export { default as useOnClickOutside } from './useOnClickOutside/useOnClickOutside'
export * from './useOnClickOutside/useOnClickOutside'
export { default as useReadLocalStorage } from './useReadLocalStorage/useReadLocalStorage'
export * from './useReadLocalStorage/useReadLocalStorage'
export { default as useScreen } from './useScreen/useScreen'
export * from './useScreen/useScreen'
export { default as useScript } from './useScript/useScript'
export * from './useScript/useScript'
export { default as useSessionStorage } from './useSessionStorage/useSessionStorage'
export * from './useSessionStorage/useSessionStorage'
export { default as useSsr } from './useSsr/useSsr'
export * from './useSsr/useSsr'
export { default as useStep } from './useStep/useStep'
export * from './useStep/useStep'
export { default as useTernaryDarkMode } from './useTernaryDarkMode/useTernaryDarkMode'
export * from './useTernaryDarkMode/useTernaryDarkMode'
export { default as useTimeout } from './useTimeout/useTimeout'
export * from './useTimeout/useTimeout'
export { default as useUpdateEffect } from './useUpdateEffect/useUpdateEffect'
export * from './useUpdateEffect/useUpdateEffect'
export { default as useWindowSize } from './useWindowSize/useWindowSize'
export * from './useWindowSize/useWindowSize'
2 changes: 0 additions & 2 deletions src/useBoolean/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useClickAnyWhere/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useCopyToClipboard/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useCountdown/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useCounter/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useDarkMode/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useDebounce/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useEffectOnce/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useElementSize/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/useElementSize/useElementSize.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, renderHook } from '@testing-library/react-hooks'

import { useElementSize } from '.'
import { useElementSize } from '..'

const setupHook = () => renderHook(() => useElementSize())

Expand Down
1 change: 0 additions & 1 deletion src/useEventCallback/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useEventListener/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useFetch/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useHover/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useImageOnLoad/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useIntersectionObserver/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useInterval/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useIsClient/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useIsFirstRender/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useIsMounted/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useIsomorphicLayoutEffect/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useLocalStorage/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useLockedBody/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useMap/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useMediaQuery/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useOnClickOutside/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useReadLocalStorage/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useScreen/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useScript/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useSessionStorage/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useSsr/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useStep/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useTernaryDarkMode/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useTimeout/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useUpdateEffect/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/useWindowSize/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion templates/plop/hooks/hook/demo.tsx.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { {{camelCase name}} } from './index'
import { {{camelCase name}} } from '..'

export default function Component() {
const [two] = {{camelCase name}}()
Expand Down
2 changes: 0 additions & 2 deletions templates/plop/hooks/hook/index.ts.hbs

This file was deleted.

3 changes: 2 additions & 1 deletion templates/plop/hooks/index.ts.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './{{camelCase name}}'
export { default as {{camelCase name}} } from './{{camelCase name}}/{{camelCase name}}'
export * from './{{camelCase name}}/{{camelCase name}}'

0 comments on commit abf633c

Please sign in to comment.