#!/bin/zsh function jsonValue() { KEY=$1 num=$2 awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p } echo "Creating directory " $1 mkdir $1 cd $1 echo "Initiate NPM Repository"; npm init mkdir example example/public example/src && touch example/.gitignore example/package.json example/README.md example/public/index.html example/public/manifest.json example/public/robots.txt example/src/App.js example/src/index.js example/src/App.test.js example/src/reportWebVitals.js example/src/setupTests.js mkdir src && touch src/index.tsx src/index.test.tsx src/$2.tsx touch README.md rollup.config.js tsconfig.json .npmignore .babelrc .gitignore .eslintrc .eslintignore .editorconfig echo "Creating .editorconfig content"; cat > .editorconfig < .eslintrc < .eslintignore < .gitignore < tsconfig.json < .babelrc < 1%", "Chrome >= 48", "Firefox >= 44", "Firefox ESR", "Safari >= 9.1", "Edge >= 12", "ios_saf >= 9.3", "ie 11" ] }, "modules": false, "forceAllTransforms": true } ] ], "env": { "test": { "presets": [ [ "@babel/preset-env", { "targets": { "node": "current" } } ] ], "plugins": [ [ "babel-plugin-styled-components", { "minify": false } ] ] } } } EOF echo "Creating rollup config js content" cat > rollup.config.js << 'EOF' import babel from '@rollup/plugin-babel'; import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; import external from 'rollup-plugin-peer-deps-external'; import { terser } from 'rollup-plugin-terser'; import { uglify } from 'rollup-plugin-uglify'; import typescript from 'rollup-plugin-typescript2'; import pkg from './package.json'; const input = "src/index.tsx" export default [ { input: input, output: { name: pkg.name, file: `dist/${pkg.name}.dev.js`, format: "cjs", exports: "named", }, plugins: [ resolve({ browser: true, preferBuiltins: true, extensions: [".mjs", ".js", ".jsx",".tsx"], }), external(), babel({ exclude: "node_modules/**" }), commonjs({ include: "node_modules/**", }), typescript({ typescript: require("typescript"), }) ], external: ["react", "react-dom"] }, { input: input, output: { name:pkg.name, file: pkg.main, format: "cjs", exports: "named", }, plugins: [ resolve({ browser: true, preferBuiltins: true, extensions: [".mjs", ".js", ".jsx",".tsx"], }), external(), babel({ exclude: "node_modules/**" }), commonjs({ include: "node_modules/**", }), uglify(), typescript({ typescript: require("typescript"), }) ], external: ["react", "react-dom"] }, { input: input, output: { name:pkg.name, file: pkg.module, format: "es", exports: "named", }, plugins: [ resolve({ browser: true, preferBuiltins: true, extensions: [".mjs", ".js", ".jsx",".tsx"], }), external(), babel({ exclude: "node_modules/**" }), commonjs({ include: "node_modules/**", }), terser(), typescript({ typescript: require("typescript"), }) ], external: ["react", "react-dom"] }, { input: input, output: { name: pkg.name, file: `dist/${pkg.name}.umd.js`, format: "umd", globals: { react: "React", }, exports: "named", }, plugins: [ resolve({ browser: true, preferBuiltins: true, extensions: [".mjs", ".js", ".jsx",".tsx"], }), external(), babel({ exclude: "node_modules/**" }), commonjs({ include: "node_modules/**", }), uglify({}), typescript({ typescript: require("typescript"), }) ], external: ["react", "react-dom"] } ] EOF echo "Going to install npm packages, this will take a while to complete" npm i -D react react-dom react-scripts web-vitals typescript @types/react @types/react-dom @types/jest @types/node rollup rollup-plugin-typescript2 @rollup/plugin-babel @rollup/plugin-commonjs @rollup/plugin-node-resolve rollup-plugin-peer-deps-external rollup-plugin-terser rollup-plugin-uglify @babel/core @babel/runtime rimraf npm-run-all cross-env @testing-library/jest-dom @testing-library/react @testing-library/user-event mainJsonPackage="package.json" node > new_${mainJsonPackage} <=16.8.0", "react-dom": ">=16.8.0" }; data.files = ["dist"]; //Output data console.log(JSON.stringify(data,null,2)); EOF cp new_package.json package.json rm new_package.json packageName=`cat package.json | jsonValue name | xargs`; echo "new package Name " $packageName; cat > src/index.tsx << EOF import $2 from "./$2"; export default $2; EOF cat > src/$2.tsx << EOF const $2 = () => { return (
Your $2 Component
) } export default $2; EOF cat > src/index.test.tsx << EOF import $2 from '.' describe("$2", () => { it('is truthy', () => { expect($2).toBeTruthy() }) }); EOF cp .gitignore example/.gitignore cat > example/package.json <0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } } EOF cat > example/public/index.html << EOF Example $2
EOF curl https://static.thenounproject.com/png/24031-200.png > example/public/favicon.ico curl https://static.thenounproject.com/png/24031-200.png > example/public/logo192.png cat > example/public/manifest.json << EOF { "short_name": "example", "name": "$2 example app", "icons": [ { "src": "favicon.ico", "sizes": "64x64 32x32 24x24 16x16", "type": "image/x-icon" }, { "src": "logo192.png", "type": "image/png", "sizes": "192x192" } ], "start_url": ".", "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff" } EOF cat > example/public/robots.txt << EOF # https://www.robotstxt.org/robotstxt.html User-agent: * Disallow: EOF cat > example/src/App.js << EOF import $2 from '$packageName'; import { useEffect, useState } from "react"; function App() { const [count,setCount] = useState(0); useEffect(() => { setCount(prevCount => prevCount + 1); },[]); return (
<$2 text={'Hola la le lo '} number={count}/> Learn React
); } export default App; EOF cat > example/src/index.js << EOF import React from "react"; import ReactDOM from "react-dom"; import App from "./App"; import reportWebVitals from "./reportWebVitals"; ReactDOM.render( , document.getElementById("root") ); // If you want to start measuring performance in your app, pass a function // to log results (for example: reportWebVitals(console.log)) // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals reportWebVitals(); EOF cat > example/src/App.test.js << EOF import { render, screen } from "@testing-library/react"; import App from "./App"; test("renders learn react link", () => { render(); const linkElement = screen.getByText(/learn react/i); expect(linkElement).toBeInTheDocument(); }); EOF cat > example/src/reportWebVitals.js << EOF const reportWebVitals = onPerfEntry => { if (onPerfEntry && onPerfEntry instanceof Function) { import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { getCLS(onPerfEntry); getFID(onPerfEntry); getFCP(onPerfEntry); getLCP(onPerfEntry); getTTFB(onPerfEntry); }); } }; export default reportWebVitals; EOF cat > example/src/setupTests.js << EOF // jest-dom adds custom jest matchers for asserting on DOM nodes. // allows you to do things like: // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import "@testing-library/jest-dom"; EOF cd example npm i