Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coverage
out/
build
dist
generated


# Debug
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"name": "workspace",
"private": true,
"module": "true",
"type": "module",
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"test": "turbo run test",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"check-types": "turbo run check-types"
"gen-hook": "turbo gen hook --config \"turbo/generators/config.cts\" && pnpm format"
},
"devDependencies": {
"@turbo/gen": "^2.5.0",
"date-fns": "^4.1.0",
"prettier": "^3.5.3",
"turbo": "^2.5.0",
"typescript": "5.8.2"
},
"packageManager": "pnpm@9.0.0",
"engines": {
"node": ">=18"
}
"node": ">=18.17"
},
"license": "MIT"
}
1,363 changes: 1,346 additions & 17 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions turbo/generators/config.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { PlopTypes } from '@turbo/gen'
import { format } from 'date-fns'
import path from 'path'

export default function generator(plop: PlopTypes.NodePlopAPI): void {
const usehooksSrcPath = path.resolve('packages/usehooks-ts/src')
plop.setGenerator('hook', {
description: 'Create a post',
prompts: [
{
type: 'input',
name: 'name',
message: 'post name please (eg: "use test")',
},
],
actions: [
{
type: 'add',
path: usehooksSrcPath + '/{{camelCase name}}/{{camelCase name}}.ts',
templateFile: 'templates/hook/hook.ts.hbs',
},
{
type: 'add',
path: usehooksSrcPath + '/{{camelCase name}}/{{camelCase name}}.test.ts',
templateFile: 'templates/hook/hook.test.ts.hbs',
},
{
data: {
date: format(new Date(), 'yyyy-MM-dd'),
},
type: 'add',
path: usehooksSrcPath + '/{{camelCase name}}/{{camelCase name}}.md',
templateFile: 'templates/hook/hook.mdx.hbs',
},
{
type: 'add',
path: usehooksSrcPath + '/{{camelCase name}}/{{camelCase name}}.demo.tsx',
templateFile: 'templates/hook/hook.demo.tsx.hbs',
},
{
type: 'add',
path: usehooksSrcPath + '/{{camelCase name}}/index.ts',
templateFile: 'templates/hook/index.ts.hbs',
},
{
type: 'append',
path: usehooksSrcPath + '/index.ts',
templateFile: 'templates/index.ts.hbs',
},
],
})
}
7 changes: 7 additions & 0 deletions turbo/generators/templates/hook/hook.demo.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { {{camelCase name}} } from './{{camelCase name}}'

export default function Component() {
const [two] = {{camelCase name}}()

return <div>Hello {two}</div>
}
1 change: 1 addition & 0 deletions turbo/generators/templates/hook/hook.mdx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This hook description markdown text.
13 changes: 13 additions & 0 deletions turbo/generators/templates/hook/hook.test.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { renderHook } from '@testing-library/react'

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

describe('{{camelCase name}}()', () => {
it('should {{name}} be ok', () => {
const { result } = renderHook(() => {{camelCase name}}())
const [value, setNumber] = result.current

expect(value).toBe(2)
expect(typeof setNumber).toBe('function')
})
})
32 changes: 32 additions & 0 deletions turbo/generators/templates/hook/hook.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useState } from 'react'

import type { Dispatch, SetStateAction } from 'react'

/** Hook return type */
type {{pascalCase name}}ReturnType = {
/** The value of ... */
value: number
/** A method to update the value of ... */
setValue: Dispatch<SetStateAction<number>>
}

/**
* Custom hook that ...
* @param {boolean} [defaultValue] - The initial value for ... (default is `0`).
* @returns {[number, Dispatch<SetStateAction<number>>]} A tuple containing ...
* @see [Documentation](https://usehooks-ts.com/react-hook/{{kebabCase name}})
* @public
* @example
* ```tsx
* const { value, setValue } = {{camelCase name}}(2);
*
* console.log(value); // 2
* ```
*/
export function {{camelCase name}}(
defaultValue?: number,
): {{pascalCase name}}ReturnType {
const [value, setValue] = useState(defaultValue || 0)

return { value, setValue }
}
1 change: 1 addition & 0 deletions turbo/generators/templates/hook/index.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './{{camelCase name}}'
1 change: 1 addition & 0 deletions turbo/generators/templates/index.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './{{camelCase name}}'