From 3095e8fb0d57c4ec1b297b33cc5c23867c1f0a32 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 7 Sep 2022 11:20:27 +0300 Subject: [PATCH] initial version of react-hooks component --- .gitignore | 23 ++++++++++++ .husky/pre-commit | 4 ++ README.md | 20 ++++++++++ package.json | 78 ++++++++++++++++++++++++++++++++++++++ scripts/copy-files.js | 87 +++++++++++++++++++++++++++++++++++++++++++ src/index.js | 2 + 6 files changed, 214 insertions(+) create mode 100644 .gitignore create mode 100644 .husky/pre-commit create mode 100644 README.md create mode 100644 package.json create mode 100644 scripts/copy-files.js create mode 100644 src/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2433d3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ + +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +node_modules + +# builds +build +dist +.rpt2_cache + +# misc +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +example/package-lock.json \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..6e9bf51 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run precommit diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b91d55 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# react-hooks + +## Install + +```bash +// with npm +npm i --save @flare/react-hooks --registry https://toodle.ddns.net/public-node-registry + +// with yarn +yarn add @flare/react-hooks --registry https://toodle.ddns.net/public-node-registry +``` + +## Usage + +```jsx +import { StandardCV } from "@flare/react-hooks"; +``` + +**1.0.0** +This version includes the initial version of react-hooks component. diff --git a/package.json b/package.json new file mode 100644 index 0000000..250438f --- /dev/null +++ b/package.json @@ -0,0 +1,78 @@ +{ + "name": "@flare/react-hooks", + "version": "1.0.0", + "description": "Standard curriculum vitae", + "author": { + "name": "Tudor Stanciu", + "email": "tudor.stanciu94@gmail.com", + "url": "https://toodle.ddns.net/tsp" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://dev.azure.com/tstanciu94/Packages/_git/react-hooks" + }, + "private": true, + "keywords": [ + "flare", + "react-hooks" + ], + "main": "./src/index.js", + "babel": { + "presets": [ + "@babel/preset-react" + ] + }, + "scripts": { + "prebuild": "rimraf build", + "build": "npm run build:cjs && npm run build:copy-files", + "build:cjs": "babel src -d build --copy-files", + "build:copy-files": "node ./scripts/copy-files.js", + "precommit": "lint-staged", + "prepare": "husky install", + "test": "echo \"Error: no test specified\" && exit 1", + "prepush": "npm run build", + "push": "cd build && npm publish --registry https://toodle.ddns.net/public-node-registry", + "push:major": "npm run version:major && npm run push", + "push:minor": "npm run version:minor && npm run push", + "push:patch": "npm run version:patch && npm run push", + "version:major": "npm version major --no-git-tag-version", + "version:minor": "npm version minor --no-git-tag-version", + "version:patch": "npm version patch --no-git-tag-version" + }, + "devDependencies": { + "@babel/cli": "^7.16.7", + "@babel/core": "^7.16.7", + "@babel/node": "^7.16.7", + "@babel/preset-env": "^7.16.7", + "@babel/preset-react": "^7.8.0", + "rimraf": "^3.0.2", + "fs-extra": "^10.0.0", + "husky": "^7.0.4", + "lint-staged": "^12.2.2", + "prettier": "^2.5.1" + }, + "peerDependencies": { + "prop-types": "^15.8.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-scripts": "5.0.1" + }, + "dependencies": {}, + "prettier": { + "trailingComma": "none", + "tabWidth": 2, + "semi": true, + "singleQuote": false, + "arrowParens": "avoid" + }, + "lint-staged": { + "**/*.+(js|md|ts|css|sass|less|graphql|scss|json|vue)": [ + "prettier --write", + "git add" + ] + }, + "publishConfig": { + "registry": "https://toodle.ddns.net/public-node-registry" + } +} diff --git a/scripts/copy-files.js b/scripts/copy-files.js new file mode 100644 index 0000000..99379e2 --- /dev/null +++ b/scripts/copy-files.js @@ -0,0 +1,87 @@ +/* eslint-disable no-console */ +const path = require("path"); +const fse = require("fs-extra"); +const glob = require("glob"); + +const packagePath = process.cwd(); +const buildPath = path.join(packagePath, "./build"); +const srcPath = path.join(packagePath, "./src"); + +/** + * Puts a package.json into every immediate child directory of rootDir. + * That package.json contains information about esm for bundlers so that imports + * like import Typography from '@material-ui/core/Typography' are tree-shakeable. + * + * It also tests that an this import can be used in typescript by checking + * if an index.d.ts is present at that path. + * + * @param {string} rootDir + */ +// async function createModulePackages({ from, to }) { +// const directoryPackages = glob.sync('*/index.js', { cwd: from }).map(path.dirname); + +// await Promise.all( +// directoryPackages.map(async directoryPackage => { +// const packageJson = { +// sideEffects: false, +// module: path.join('../esm', directoryPackage, 'index.js'), +// typings: './index.d.ts', +// }; +// const packageJsonPath = path.join(to, directoryPackage, 'package.json'); + +// /*const [typingsExist] =*/ await Promise.all([ +// //fse.exists(path.join(to, directoryPackage, 'index.d.ts')), +// fse.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)), +// ]); + +// // if (!typingsExist) { +// // throw new Error(`index.d.ts for ${directoryPackage} is missing`); +// // } + +// return packageJsonPath; +// }), +// ); +// } + +async function createPackageFile() { + const packageData = await fse.readFile( + path.resolve(packagePath, "./package.json"), + "utf8" + ); + // eslint-disable-next-line no-unused-vars + const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } = + JSON.parse(packageData); + const newPackageData = { + ...packageDataOther, + private: false, + main: "./index.js" + }; + const targetPath = path.resolve(buildPath, "./package.json"); + + await fse.writeFile( + targetPath, + JSON.stringify(newPackageData, null, 2), + "utf8" + ); + console.log(`Created package.json in ${targetPath}`); + + fse.copy("./README.md", `${buildPath}/README.md`, err => { + if (err) throw err; + console.log("README file was copied to destination"); + }); + + return newPackageData; +} + +async function run() { + try { + await createPackageFile(); + + //await createModulePackages({ from: srcPath, to: buildPath }); + } catch (err) { + console.error(err); + process.exit(1); + } +} + +run(); diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..e441dd0 --- /dev/null +++ b/src/index.js @@ -0,0 +1,2 @@ +const empty = ""; +export { empty };