Skip to content

Commit

Permalink
feat: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
danieloprado committed Jul 10, 2023
0 parents commit 17df7ef
Show file tree
Hide file tree
Showing 17 changed files with 2,179 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@eduzz/eslint-config/react"]
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @danieloprado @ffernandomoraes @JonathasRodrigues
77 changes: 77 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Publish

on:
push:
branches:
- master

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true

jobs:
should-release:
name: Should Release
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3
- name: Node
uses: actions/setup-node@v3
- name: Deps
run: npm i -g semver
- name: Run should-release
run: node ./scripts/should-release.js
- name: Current Version
id: current-version
run: echo 'CURRENT_VERSION='$(node -p -e "require('./package.json').version") >> $GITHUB_OUTPUT
- name: Check Skip Release
id: skip-release
run: echo 'SKIP='$(cat .skip-release) >> $GITHUB_OUTPUT
outputs:
SKIP: ${{ steps.skip-release.outputs.SKIP }}
CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }}

publish:
needs: [should-release]
if: needs.should-release.outputs.SKIP != 'true'
name: Publish
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3
- name: Node
uses: actions/setup-node@v3
- name: Cache Yarn
id: cache-nodemodules
uses: actions/cache@v3
with:
path: node_modules
key: packages-${{ hashFiles('yarn.lock') }}
restore-keys: |
packages-
- name: Yarn
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: yarn install --immutable
- name: Setup NPM Registry
run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}' > ~/.npmrc && npm config get registry && npm whoami
- name: Build
run: npm run build
- name: Publish
run: npm publish
- name: Check Skip Release
id: skip-release
run: echo 'SKIP='$(cat .skip-release) >> $GITHUB_OUTPUT
- name: Create tag
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/v${{ needs.should-release.outputs.CURRENT_VERSION }}",
sha: context.sha
})
outputs:
SKIP: ${{ steps.skip-release.outputs.SKIP }}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
*.log
.DS_Store
.skip-release
*.js
*.d.ts
*.map

!.prettierrc.js
!scripts/*.js
16 changes: 16 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.vscode
node_modules
.eslintignore
.eslintrc
.prettierrc
.prettierrc.js
tsconfig.json
/**/**/*.tsx
/**/**/*.ts
!/**/**/*.d.ts
.git
scripts
*.md
!README.md
.github
.vscode
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@eduzz/eslint-config/.prettierrc')
};
58 changes: 58 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"[css]": {
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnPaste": false,
"editor.formatOnSave": false,
"editor.formatOnType": false,
"editor.quickSuggestions": {
"strings": true
},
"editor.rulers": [
{
"color": "#fd3e3e78",
"column": 120
}
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"files.associations": {
"*.css": "tailwindcss"
},
"files.exclude": {
"**/*.lock.json": true,
"**/*?.d.ts": true,
"**/*?.js": {
"when": "$(basename).ts"
},
"**/**?.js": {
"when": "$(basename).tsx"
},
"**/*?.css.js": true,
"**/.DS_Store": true,
"**/*.map": true,
"**/.git": true,
"**/.gradle/**": true,
"**/.idea/**": true,
"**/.svn": true,
"**/.tmp": true,
"**/Pods/**": true,
"**/bin/**": true,
"**/build/**": true,
"**/dist/**": true,
"**/node_modules": true,
"**/obj/**": true,
"**/vendor/**": true,
".docker-data": true,
"tsconfig.tsbuildinfo": true
}
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Eduzz Hooks

[![version](https://img.shields.io/npm/v/@eduzz/ui-hooks)](https://www.npmjs.com/package/@eduzz/ui-hooks)
[![size](https://img.shields.io/bundlephobia/min/@eduzz/ui-hooks)](https://www.npmjs.com/package/@eduzz/ui-hooks)

Hooks diversos para auxiliar no desenvolvimento.

## Instalação

```bash
yarn add @eduzz/ui-hooks
```

## Hooks

- [useBoolean](https://github.com/eduzz/ui-hooks/blob/master/useBoolean/index.md).
- [useCallbackGenerator](https://github.com/eduzz/ui-hooks/blob/master/useCallbackGenerator/index.md).
5 changes: 5 additions & 0 deletions index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import useBooleanExport from './useBoolean';
import useCallbackGeneratorExport from './useCallbackGenerator';

export const useBoolean = useBooleanExport;
export const useCallbackGenerator = useCallbackGeneratorExport;
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@eduzz/ui-hooks",
"description": "Eduzz Hooks",
"version": "0.0.2",
"keywords": ["react-hooks", "hooks", "react", "eduzz"],
"main": "./index.js",
"types": "./index.d.ts",
"author": "Eduzz Team",
"license": "MIT",
"private": false,
"homepage": "https://github.com/eduzz/ui-hooks",
"repository": {
"type": "git",
"url": "https://github.com/eduzz/ui-hooks"
},
"bugs": {
"url": "https://github.com/eduzz/ui-hooks/issues"
},
"scripts": {
"clean": "git add . && git clean -fdx . -e node_modules",
"prebuild": "yarn clean && yarn lint",
"build": "yarn tsc -p tsconfig.json",
"lint": "eslint . --ext js,ts,tsx"
},
"dependencies": {
"lodash-es": "^4"
},
"devDependencies": {
"@eduzz/eslint-config": "^0.0.3",
"@types/lodash-es": "^4",
"@types/react-dom": "^18.2.6",
"@types/react": "^18.2.14",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-unused-imports": "^2.0.0",
"eslint": "^8.44.0",
"prettier": "^2",
"react-dom": "^18.2.0",
"react": "^18.2.0",
"typescript": "^5.1.6"
}
}
52 changes: 52 additions & 0 deletions scripts/should-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable @typescript-eslint/no-require-imports */
const childProccess = require('child_process');

const globalPackages = childProccess.execSync('npm root -g').toString().trim();
const semver = require(`${globalPackages}/semver`);

const package = require('../package.json');

async function init() {
if (!semver.valid(package.version)) {
throw new Error(`Invalid Version: ${package.version}`);
}

console.log('NEW VERSION:' + package.version);

const remoteVersion = await exec(`npm view ${package.name} version`);
package.remoteVersion = remoteVersion;

console.log(`REMOTE VERSIONS: ${package.remoteVersion}`);

const isGreater = semver.gt(package.version, package.remoteVersion);

if (!isGreater) {
console.log('Version already published, skipping...');
await exec('echo true > .skip-release');
return;
}

await exec('echo false > .skip-release');
}

function exec(command, live) {
return new Promise((resolve, reject) => {
const cmd = childProccess.exec(command, { env: { ...process.env } }, (err, stdout) => {
if (err) reject(err);
resolve(stdout?.trim());
});

if (!live) return;
cmd.stdout.on('data', data => console.log(data.toString()));
});
}

init()
.then(() => {
console.log(`NEW VERSION CAN BE PUBLISHED: ${package.version}`);
process.exit(0);
})
.catch(err => {
console.error(err);
process.exit(-1);
});
34 changes: 34 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"strict": true,
"outDir": ".",
"declaration": true,
"declarationDir": ".",
"module": "es2020",
"target": "ES6",
"experimentalDecorators": true,
"lib": ["es2020", "dom"],
"sourceMap": false,
"jsx": "react-jsx",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": false,
"noUnusedLocals": true,
"importHelpers": true,
"skipLibCheck": true,
"downlevelIteration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": [
"./**/*.tsx",
"./**/*.ts"
],
"exclude": [
"*.d.ts",
"./**/*.d.ts",
"dist",
"node_modules"
]
}
20 changes: 20 additions & 0 deletions useBoolean/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# useBoolean

Esse é um hooks apenas para facilitar o uso de booleanos, útil quando deseja passar como callback de uma função

## Como usar

```tsx
const [value, toggleValue, toTrue, toFalse] = useBoolean();
```

## Parâmetros e Retorno

```tsx
/**
* Simplify the way to use a boolean state
* @param initial A boolen of a function that return a boolean
* @returns [value, toogleValue, toTrue, toFalse]
*/
export default function useBoolean(initial?: boolean | (() => boolean)): [boolean, () => void, () => void, () => void];
```
15 changes: 15 additions & 0 deletions useBoolean/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useState, useCallback } from 'react';

/**
* Simplify the way to use a boolean state
* @param initial A boolen of a function that return a boolean
* @returns [value, toogleValue, toTrue, toFalse]
*/
export default function useBoolean(initial?: boolean | (() => boolean)): [boolean, () => void, () => void, () => void] {
const [value, setValue] = useState(initial ?? false);
const toogleValue = useCallback(() => setValue(value => !value), []);
const toTrue = useCallback(() => setValue(() => true), []);
const toFalse = useCallback(() => setValue(() => false), []);

return [value, toogleValue, toTrue, toFalse];
}

0 comments on commit 17df7ef

Please sign in to comment.