This commit is contained in:
Jorge Mario Arita Ramírez 2024-01-21 14:13:07 -06:00
parent 5c33cd496d
commit 2a26a5c9b7
21 changed files with 5423 additions and 0 deletions

11
.babelrc Normal file
View File

@ -0,0 +1,11 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-runtime",
"macros"
]
}

49
.eslintrc.json Normal file
View File

@ -0,0 +1,49 @@
// devDependencies required
// - eslint
// - eslint-config-next
// - eslint-config-standard
// - eslint-plugin-import
// - eslint-plugin-n
// - eslint-plugin-promise
// - eslint-plugin-react
// - eslint-plugin-tailwindcss
// command yarn install
// yarn add -D eslint eslint-config-next eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-react eslint-plugin-tailwindcss eslint-plugin-n
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"plugin:react/recommended",
"standard",
"plugin:tailwindcss/recommended"
],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "tailwindcss"],
"rules": {
"react-hooks/exhaustive-deps": "off",
"tailwindcss/no-custom-classname": "off",
"tailwindcss/classnames-order": "error",
"camelcase": "off",
"react-hooks/rules-of-hooks": "off",
"object-curly-spacing": [2, "always"],
"no-console": ["warn", { "allow": ["warn", "error"] }],
"indent": [
"error",
2,
{
"SwitchCase": 1,
"flatTernaryExpressions": true
}
]
}
}

132
.gitignore vendored Normal file
View File

@ -0,0 +1,132 @@
# ---> Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
# dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

16
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
"editor.tabSize": 2,
"editor.detectIndentation": false,
"search.exclude": {
"package-lock.json": true
},
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.addMissingImports": "explicit",
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"headlessui"
]
}

2
dist/components/button/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare const Button: () => any;
export default Button;

2
dist/components/button/index.js vendored Normal file
View File

@ -0,0 +1,2 @@
import t from"react";var e=function(){return t.createElement("div",null,"Button")};export{e as default};
//# sourceMappingURL=index.js.map

1
dist/components/button/index.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../src/components/button/index.tsx"],"sourcesContent":["import React from 'react'\r\n\r\nconst Button = () => {\r\n return (\r\n <div>Button</div>\r\n )\r\n}\r\n\r\nexport default Button"],"names":["Button","React","createElement"],"mappings":"qBAEA,IAAMA,EAAS,WACb,OACEC,EAAiBC,cAAA,MAAA,KAAA,SAErB"}

2
dist/components/input/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare const Input: () => any;
export default Input;

2
dist/components/input/index.js vendored Normal file
View File

@ -0,0 +1,2 @@
import t from"react";var e=function(){return t.createElement("div",null,"Input")};export{e as default};
//# sourceMappingURL=index.js.map

1
dist/components/input/index.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../src/components/input/index.tsx"],"sourcesContent":["import React from 'react'\r\n\r\nconst Input = () => {\r\n return (\r\n <div>Input</div>\r\n )\r\n}\r\n\r\nexport default Input"],"names":["Input","React","createElement"],"mappings":"qBAEA,IAAMA,EAAQ,WACZ,OACEC,EAAgBC,cAAA,MAAA,KAAA,QAEpB"}

3
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export * from './components/button';
export * from './components/input';
export * from './lib/utils';

1
dist/lib/utils.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function cn(...inputs: any[]): string;

64
generateRollupConfig.cjs Normal file
View File

@ -0,0 +1,64 @@
const requireContext = require('require-context')
const fs = require('fs')
// const path = require('path')
const requireComponent = requireContext(
'./../../src', true, /\.(js|ts)x?$/, 'lazy'
)
const dependencias = {
Example: '',
VCalendar: "'react-big-calendar', 'moment'"
}
const makeConfig = () => {
let config = ''
requireComponent.keys().forEach(fileName => {
// Ajusta la ruta para que coincida con tus rutas y extensiones de archivo
const folderName = fileName.replace(/components[\\/]/, '').replace(/index\.(jsx|tsx)$/, '')
if (folderName != null && folderName && !folderName.includes('index.')) {
const defaultItem = `
{
input: 'src/components/${folderName}/index.${fileName.endsWith('.tsx') ? 'tsx' : 'jsx'}',
output: {
dir: 'dist/${folderName}',
format: 'es'
},
external: [/@babel\\/runtime/, 'react', 'prop-types'${dependencias[folderName] != null ? (', ' + dependencias[folderName]) : ''}],
plugins: [
typescript(),
babel({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime']
}),
postcss({ plugins: [autoprefixer()], sourceMap: true, extract: true, minimize: true }),
tailwind({ input: './styles/globals.css', purge: false })
]
},`
config = `${config} ${defaultItem}`
}
})
return config
}
const content = `// File generated by npm run generateRollupFile
import typescript from '@rollup/plugin-typescript';
import babel from '@rollup/plugin-babel';
import postcss from 'rollup-plugin-postcss';
import tailwind from 'rollup-plugin-tailwindcss';
import autoprefixer from 'autoprefixer';
const config = [${makeConfig()}
];
export default config;
`
fs.writeFile('rollup.config.js', content, err => {
if (err) {
console.error(err)
return
}
console.log('file written successfully')
})

71
package.json Normal file
View File

@ -0,0 +1,71 @@
{
"name": "library-template",
"version": "1.0.1",
"type": "module",
"exports": {
"./*": "./dist/components/*/index.js"
},
"types": "dist/index.d.ts",
"files": [
"dist"
],
"license": "MIT",
"peerDependencies": {
"prop-types": "^15",
"react": "^16",
"react-dom": "^16"
},
"scripts": {
"beforeUpdate": "node -e \"console.log('Para generar el css quitar type module de package json')\"",
"updateCss": "tailwindcss -i ./styles/globals.css -o ./styles/generated/output.css",
"generateRollupFile": "node generateRollupConfig.cjs",
"rollupPrebuild": "rimraf srs && rimraf dist",
"rollupBuild": "rollup -c --bundleConfigAsCjs",
"rollupBuildProd": "rollup -c --environment NODE_ENV:production",
"deploy": "git pull origin main && yarn rollupPrebuild && yarn rollupBuildProd && git add . && yarn version --patch && git push origin dev_ja && git push origin --tags"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/plugin-transform-runtime": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.20.7",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"autoprefixer": "^10.4.17",
"babel-plugin-macros": "^3.1.0",
"eslint": "^8.56.0",
"eslint-config-next": "^14.0.4",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-tailwindcss": "^3.14.0",
"postcss": "^8.4.33",
"prop-types": "^15",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"require-context": "^1.1.0",
"rollup": "^4.9.5",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-tailwindcss": "^1.0.0",
"rollup-plugin-terser": "^7.0.2",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
},
"dependencies": {
"class-variance-authority": "^0.7.0",
"tailwind-merge": "^2.2.0",
"tslib": "^2.6.2"
},
"browser": {
"fs": false,
"path": false,
"os": false
}
}

66
rollup.config.js Normal file
View File

@ -0,0 +1,66 @@
import fs from 'fs'
import path from 'path'
import typescript from '@rollup/plugin-typescript'
import babel from '@rollup/plugin-babel'
import postcss from 'rollup-plugin-postcss'
import tailwind from 'rollup-plugin-tailwindcss'
import autoprefixer from 'autoprefixer'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
// Recursively get .tsx files from a directory
const getComponents = (dir) =>
fs.readdirSync(dir).reduce((files, file) => {
const name = path.join(dir, file)
const isDirectory = fs.statSync(name).isDirectory()
const isIndexFile = path.basename(name).includes('index')
if (isDirectory) {
return files.concat(getComponents(name))
} else if (isIndexFile && name.endsWith('.tsx')) {
return files.concat(name)
} else {
return files
}
}, [])
// Generate Rollup configuration for each component
const componentsDir = 'src/components'
const componentFiles = getComponents(componentsDir)
const rollupConfig = componentFiles.map((inputFile) => ({
input: inputFile,
output: [
{
dir: 'dist',
format: 'es',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src'
}
],
external: [/@babel\/runtime/, 'react', 'prop-types'],
plugins: [
resolve(),
commonjs(),
typescript(),
babel({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime']
}),
postcss({
plugins: [autoprefixer()],
sourceMap: true,
extract: true,
minimize: true
}),
tailwind({
input: './styles/globals.css',
purge: false
}),
terser()
]
}))
export default rollupConfig

View File

@ -0,0 +1,9 @@
import React from 'react'
const Button = () => {
return (
<div>Button</div>
)
}
export default Button

View File

@ -0,0 +1,9 @@
import React from 'react'
const Input = () => {
return (
<div>Input</div>
)
}
export default Input

3
src/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './components/button';
export * from './components/input';
export * from './lib/utils';

13
src/lib/utils.ts Normal file
View File

@ -0,0 +1,13 @@
import { twMerge } from 'tailwind-merge'
export function cn (...inputs) {
const classes = inputs
.filter((input) => input)
.flatMap((input) =>
typeof input === 'object'
? Object.entries(input).filter(([, value]) => value).map(([key]) => key)
: input.split(' ')
)
return twMerge(...classes)
}

29
tsconfig.json Normal file
View File

@ -0,0 +1,29 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"esModuleInterop": true,
"noUnusedLocals": true,
"outDir": "./dist",
"declaration": true,
"target": "esnext",
"module": "esnext",
"jsx": "react",
"strict": false,
"noImplicitAny": false,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}

4937
yarn.lock Normal file

File diff suppressed because it is too large Load Diff