From cb559789165e978276ab2bf2e696a043cba955b5 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Fri, 19 Aug 2022 17:47:41 +0000 Subject: [PATCH] 123 --- .babelrc | 27 ++++++ .eslintignore | 4 + .eslintrc | 8 ++ .npmignore | 16 ++++ .nvmrc | 2 + .storybook/main.js | 9 ++ commitlint.config.js | 1 + jest.config.js | 193 +++++++++++++++++++++++++++++++++++++++++++ package.json | 133 +++++++++++++++++++++++++++++ renovate.json | 5 ++ rollup.config.js | 84 +++++++++++++++++++ 11 files changed, 482 insertions(+) create mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .npmignore create mode 100644 .nvmrc create mode 100644 .storybook/main.js create mode 100644 commitlint.config.js create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 renovate.json create mode 100644 rollup.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..29d52c4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,27 @@ +{ + "env": { + "test": { + "presets": [ + [ + "@babel/preset-env" + ], + "@babel/preset-react" + ] + } + }, + "presets": [ + [ + "@babel/preset-env", + { + "modules": false + } + ], + "@babel/preset-react" + ], + "ignore": [ + "node_modules/**" + ], + "plugins": [ + "@babel/plugin-transform-runtime" + ] +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..49c5f30 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +coverage/* +build +node_modules +*.stories.jsx diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..4ef7c95 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "airbnb" + ], + "env": { + "jest": true + } +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..7c016dc --- /dev/null +++ b/.npmignore @@ -0,0 +1,16 @@ +.DS_Store +.eslintcache +node_modules +npm-debug.log +.travis.yml +src/ +test/ +*.test.js +coverage/ +*.stories.js +*.stories.jsx +rollup.config.js +.babelrc +.eslintignore +.eslintric +.gitignore diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..1f8c136 --- /dev/null +++ b/.nvmrc @@ -0,0 +1,2 @@ +16.17.0 + diff --git a/.storybook/main.js b/.storybook/main.js new file mode 100644 index 0000000..176fde3 --- /dev/null +++ b/.storybook/main.js @@ -0,0 +1,9 @@ +module.exports = { + stories: ['../src/**/*.stories.jsx'], + addons: [ + { + name: '@storybook/addon-essentials', + }, + ], +}; + diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..69b18d9 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = { extends: ['@commitlint/config-angular'] }; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..8816c62 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,193 @@ +/* eslint max-len: 0 */ + +// For a detailed explanation regarding each configuration property, visit: +// https://jestjs.io/docs/en/configuration.html + +module.exports = { + // All imported modules in your tests should be mocked automatically + // automock: false, + + // Stop running tests after `n` failures + // bail: 0, + + // Respect "browser" field in package.json when resolving modules + // browser: false, + + // The directory where Jest should store its cached dependency information + // cacheDirectory: "/private/var/folders/53/g80kbdbs5lldxtc3d58cgw1w0000gn/T/jest_dx", + + // Automatically clear mock calls and instances between every test + clearMocks: true, + + // Indicates whether the coverage information should be collected while executing the test + // collectCoverage: false, + + // An array of glob patterns indicating a set of files for which coverage information should be collected + // collectCoverageFrom: undefined, + + // The directory where Jest should output its coverage files + coverageDirectory: 'coverage', + + // An array of regexp pattern strings used to skip coverage collection + // coveragePathIgnorePatterns: [ + // "/node_modules/" + // ], + + // A list of reporter names that Jest uses when writing coverage reports + // coverageReporters: [ + // "json", + // "text", + // "lcov", + // "clover" + // ], + + // An object that configures minimum threshold enforcement for coverage results + // coverageThreshold: undefined, + + // A path to a custom dependency extractor + // dependencyExtractor: undefined, + + // Make calling deprecated APIs throw helpful error messages + // errorOnDeprecated: false, + + // Force coverage collection from ignored files using an array of glob patterns + // forceCoverageMatch: [], + + // A path to a module which exports an async function that is triggered once before all test suites + // globalSetup: undefined, + + // A path to a module which exports an async function that is triggered once after all test suites + // globalTeardown: undefined, + + // A set of global variables that need to be available in all test environments + // globals: {}, + + // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. + // maxWorkers: "50%", + + // An array of directory names to be searched recursively up from the requiring module's location + // moduleDirectories: [ + // "node_modules" + // ], + + // An array of file extensions your modules use + // moduleFileExtensions: [ + // "js", + // "json", + // "jsx", + // "ts", + // "tsx", + // "node" + // ], + + // A map from regular expressions to module names that allow to stub out resources with a single module + // moduleNameMapper: {}, + + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader + // modulePathIgnorePatterns: [], + + // Activates notifications for test results + // notify: false, + + // An enum that specifies notification mode. Requires { notify: true } + // notifyMode: "failure-change", + + // A preset that is used as a base for Jest's configuration + // preset: undefined, + + // Run tests from one or more projects + // projects: undefined, + + // Use this configuration option to add custom reporters to Jest + // reporters: undefined, + + // Automatically reset mock state between every test + // resetMocks: false, + + // Reset the module registry before running each individual test + // resetModules: false, + + // A path to a custom resolver + // resolver: undefined, + + // Automatically restore mock state between every test + // restoreMocks: false, + + // The root directory that Jest should scan for tests and modules within + // rootDir: undefined, + + // A list of paths to directories that Jest should use to search for files in + // roots: [ + // "" + // ], + + // Allows you to use a custom runner instead of Jest's default test runner + // runner: "jest-runner", + + // The paths to modules that run some code to configure or set up the testing environment before each test + // setupFiles: [], + + // A list of paths to modules that run some code to configure or set up the testing framework before each test + setupFilesAfterEnv: ['/setupTests.js'], + + // A list of paths to snapshot serializer modules Jest should use for snapshot testing + // snapshotSerializers: [], + + // The test environment that will be used for testing + testEnvironment: 'node', + + // Options that will be passed to the testEnvironment + // testEnvironmentOptions: {}, + + // Adds a location field to test results + // testLocationInResults: false, + + // The glob patterns Jest uses to detect test files + // testMatch: [ + // "**/__tests__/**/*.[jt]s?(x)", + // "**/?(*.)+(spec|test).[tj]s?(x)" + // ], + + // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped + // testPathIgnorePatterns: [ + // "/node_modules/" + // ], + + // The regexp pattern or array of patterns that Jest uses to detect test files + // testRegex: [], + + // This option allows the use of a custom results processor + // testResultsProcessor: undefined, + + // This option allows use of a custom test runner + // testRunner: "jasmine2", + + // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href + // testURL: "http://localhost", + + // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" + // timers: "real", + + // A map from regular expressions to paths to transformers + transform: { + '^.+\\.(js|jsx)?$': '/node_modules/babel-jest', + '.+\\.(css|styl|less|sass|scss)$': 'jest-transform-css', + }, + + // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation + // transformIgnorePatterns: [ + // "/node_modules/" + // ], + + // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them + // unmockedModulePathPatterns: undefined, + + // Indicates whether each individual test should be reported during the run + // verbose: undefined, + + // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode + // watchPathIgnorePatterns: [], + + // Whether to use watchman for file crawling + // watchman: true, +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..7df87ce --- /dev/null +++ b/package.json @@ -0,0 +1,133 @@ +{ + "name": "react-email-components-template", + "version": "0.2.0", + "description": "Example React Component for npm Publication using Rollup", + "main": "build/index.cjs.js", + "module": "build/index.esm.js", + "browser": "build/index.js", + "style": "build/index.css", + "files": [ + "build" + ], + "scripts": { + "build": "npx rollup -c", + "codecov": "npx codecov", + "commitmsg": "npx commitlint -e $GIT_PARAMS", + "deploy-storybook-ci": "npx storybook-to-ghpages --ci", + "gc": "commit", + "lint": "npx eslint --ext .js,.jsx .", + "prepare": "npm run build", + "semantic-release": "npx semantic-release", + "start": "npm run build -- -w", + "storybook": "npx start-storybook -p 6006", + "test": "npx jest --coverage", + "travis-deploy-once": "npx travis-deploy-once", + "is-build-es5": "npx es-check es5 './build/**/*.!(esm).js'" + }, + "repository": { + "type": "git", + "url": "https://github.com/LLazyEmail/react-email-template" + }, + "publishConfig": { + "access": "public" + }, + "keywords": [ + "rollup", + "react", + "react component", + "rollup react", + "component", + "example react component", + "example rollup react component" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/LLazyEmail/react-email-template/issues" + }, + "homepage": "https://github.com/LLazyEmail/react-email-template#readme", + "devDependencies": { + "@babel/cli": "7.18.10", + "@babel/core": "7.18.10", + "@babel/plugin-transform-runtime": "7.18.10", + "@babel/preset-env": "7.18.10", + "@babel/preset-react": "7.18.6", + "@commitlint/cli": "17.0.3", + "@commitlint/config-angular": "17.0.3", + "@commitlint/prompt": "17.0.3", + "@commitlint/prompt-cli": "17.0.3", + "@rollup/plugin-babel": "5.3.1", + "@rollup/plugin-commonjs": "22.0.2", + "@rollup/plugin-node-resolve": "13.3.0", + "@storybook/addon-a11y": "6.5.10", + "@storybook/addon-actions": "6.5.10", + "@storybook/addon-centered": "5.3.21", + "@storybook/addon-console": "1.2.3", + "@storybook/addon-essentials": "6.5.10", + "@storybook/addon-info": "5.3.21", + "@storybook/addon-notes": "5.3.21", + "@storybook/addon-options": "5.3.21", + "@storybook/addons": "6.5.10", + "@storybook/channels": "6.5.10", + "@storybook/cli": "6.5.10", + "@storybook/react": "6.5.10", + "@storybook/storybook-deployer": "2.8.12", + "acorn": "8.8.0", + "autoprefixer": "10.4.8", + "babel-jest": "28.1.3", + "babel-loader": "8.2.5", + "babel-preset-minify": "0.6.0-alpha.9", + "bufferutil": "4.0.6", + "canvas": "2.9.3", + "classnames": "2.3.1", + "codecov": "3.8.3", + "css-loader": "6.7.1", + "enzyme": "3.11.0", + "enzyme-adapter-react-16": "1.15.6", + "es-check": "7.0.0", + "eslint": "8.22.0", + "eslint-config-airbnb": "19.0.4", + "eslint-plugin-import": "2.26.0", + "eslint-plugin-jsx-a11y": "6.6.1", + "eslint-plugin-react": "7.30.1", + "eslint-plugin-react-hooks": "4.6.0", + "fibers": "5.0.2", + "husky": "8.0.1", + "jest": "28.1.3", + "jest-transform-css": "4.0.1", + "node-sass": "7.0.1", + "postcss": "8.4.16", + "react-test-renderer": "18.2.0", + "rollup": "2.78.0", + "rollup-plugin-filesize": "9.1.2", + "rollup-plugin-postcss": "4.0.2", + "sass": "1.54.4", + "sass-loader": "13.0.2", + "semantic-release": "19.0.3", + "source-map-loader": "4.0.0", + "style-loader": "3.3.1", + "travis-deploy-once": "5.0.11", + "typescript": "4.7.4", + "utf-8-validate": "5.0.9", + "webpack": "5.74.0", + "webpack-build-notifier": "2.3.0", + "webpack-cli": "4.10.0", + "webpack-dev-server": "4.10.0" + }, + "peerDependencies": { + "prop-types": "^15.7.2", + "react": "^16.12.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.12.0 || ^17.0.0 || ^18.0.0" + }, + "dependencies": { + "@babel/runtime": "^7.14.6", + "atherdon-react-markdown-component-body": "^0.1.0", + "atherdon-react-markdown-component-typography": "^0.0.3", + "react-email-components-table": "^0.1.2", + "react-email-components-typography": "^0.0.4", + "react-emails-components-miscellaneous": "^0.2.0" + }, + "storybook-deployer": { + "gitUsername": "xxx", + "gitEmail": "xxx" + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..e0cb3b2 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,84 @@ +import babel from '@rollup/plugin-babel'; +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import postcss from 'rollup-plugin-postcss'; +import filesize from 'rollup-plugin-filesize'; +import autoprefixer from 'autoprefixer'; + +import pkg from './package.json'; + +const INPUT_FILE_PATH = 'src/index.js'; +const OUTPUT_NAME = 'Example'; + +const extensions = [ + ".js", + ".jsx" +]; + +const GLOBALS = { + react: 'React', + 'react-dom': 'ReactDOM', + 'prop-types': 'PropTypes', +}; + +const PLUGINS = [ + postcss({ + extract: true, + plugins: [ + autoprefixer, + ], + }), + babel({ + babelHelpers: 'runtime', + skipPreflightCheck: true, + exclude: 'node_modules/**', + }), + resolve({ + browser: true, + resolveOnly: [ + /^(?!react$)/, + /^(?!react-dom$)/, + /^(?!prop-types)/, + ], + }), + commonjs(), + filesize(), +]; + +const EXTERNAL = [ + 'react', + 'react-dom', + 'prop-types', +]; + +// https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers +const CJS_AND_ES_EXTERNALS = EXTERNAL.concat(/@babel\/runtime/); + +const OUTPUT_DATA = [ + { + file: pkg.browser, + format: 'umd', + }, + { + file: pkg.main, + format: 'cjs', + }, + { + file: pkg.module, + format: 'es', + }, +]; + +const config = OUTPUT_DATA.map(({ file, format }) => ({ + input: INPUT_FILE_PATH, + output: { + file, + format, + name: OUTPUT_NAME, + globals: GLOBALS, + }, + external: ['cjs', 'es'].includes(format) ? CJS_AND_ES_EXTERNALS : EXTERNAL, + plugins: PLUGINS, +})); + +export default config;