diff --git a/.gitignore b/.gitignore index 5fe22bc1..d4752f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,8 @@ # testing # production -/dist +/lib +/build # workspace .vscode @@ -15,6 +16,7 @@ .env.development.local .env.test.local .env.production.local +.rpt2_cache npm-debug.log* yarn-debug.log* yarn-error.log* diff --git a/package-lock.json b/package-lock.json index 470a616a..b50b21e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-semantics", - "version": "0.1.1", + "version": "0.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -66,6 +66,12 @@ "@types/enzyme": "*" } }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/jest": { "version": "23.3.0", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.0.tgz", @@ -5634,6 +5640,94 @@ "glob": "^7.0.5" } }, + "rollup": { + "version": "0.63.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.63.4.tgz", + "integrity": "sha512-IGTH7u0P6bmu7cXL0g11UDYTR9WKku70cYlqVyOYdqLoQopBGmCbGC3SMeheqHymnehHe/5yf6BJ6BEoxQBVTQ==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "@types/node": "*" + } + }, + "rollup-plugin-typescript2": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.16.1.tgz", + "integrity": "sha512-7x4NcMv8OR/Z6WskCv1QpvYUvHtuZ1jp1LFw16pEzNiY0d2Nm7z7SNUmPE7Vt2HRtQsigEksuYD8O4xi6enV7A==", + "dev": true, + "requires": { + "fs-extra": "5.0.0", + "resolve": "1.8.1", + "rollup-pluginutils": "2.3.0", + "tslib": "1.9.3" + }, + "dependencies": { + "estree-walker": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz", + "integrity": "sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig==", + "dev": true + }, + "fs-extra": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", + "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "resolve": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", + "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", + "dev": true, + "requires": { + "path-parse": "^1.0.5" + } + }, + "rollup-pluginutils": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.3.0.tgz", + "integrity": "sha512-xB6hsRsjdJdIYWEyYUJy/3ki5g69wrf0luHPGNK3ZSocV6HLNfio59l3dZ3TL4xUwEKgROhFi9jOCt6c5gfUWw==", + "dev": true, + "requires": { + "estree-walker": "^0.5.2", + "micromatch": "^2.3.11" + } + } + } + }, + "rollup-plugin-uglify": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-4.0.0.tgz", + "integrity": "sha512-f6W31EQLzxSEYfN3x6/lyljHqXSoCjXKcTsnwz3evQvHgU1+qTzU2SE0SIG7tbAvaCewp2UaZ5x3k6nYsxOP9A==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0-beta.47", + "uglify-js": "^3.3.25" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "uglify-js": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.5.tgz", + "integrity": "sha512-Fm52gLqJqFBnT+Sn411NPDnsgaWiYeRLw42x7Va/mS8TKgaepwoGY7JLXHSEef3d3PmdFXSz1Zx7KMLL89E2QA==", + "dev": true, + "requires": { + "commander": "~2.16.0", + "source-map": "~0.6.1" + } + } + } + }, "rst-selector-parser": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz", diff --git a/package.json b/package.json index f64b06d2..36d244fe 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,12 @@ "type": "git", "url": "https://github.com/csvenke/react-semantics.git" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "lib/index.min.js", + "types": "lib/types/index.d.ts", "files": [ - "dist" + "lib/index.min.js", + "lib/types/index.d.ts", + "lib/types/components" ], "private": false, "license": "MIT", @@ -43,6 +45,9 @@ "react-dom": "^16.4.1", "react": "^16.4.1", "rimraf": "^2.6.2", + "rollup-plugin-typescript2": "^0.16.1", + "rollup-plugin-uglify": "^4.0.0", + "rollup": "^0.63.4", "ts-jest": "^23.0.1", "tslint-config-prettier": "^1.14.0", "tslint-plugin-prettier": "^1.3.0", @@ -50,11 +55,13 @@ "typescript": "^2.9.2" }, "scripts": { - "build": "npm run clean:build && npm run lint && npm run prettify && npm run test && tsc -p ./tsconfig.build.json", - "clean:build": "rimraf ./dist", - "lint": "tslint -c tslint.json './src/**/*'", - "lintfix": "tslint -c tslint.json --fix './src/**/*'", - "prettify": "prettier -c .prettierrc --write \"src/**/*.@(ts|tsx)\"", + "build": "npm run clean:build && npm run lint && npm run test && rollup -c", + "clean:build": "rimraf ./lib", + "lint": "npm run lint:write './src/**/*'", + "lint:fix": "npm run lint:write --fix './src/**/*'", + "lint:write": "tslint -c tslint.json", + "prettier": "npm run prettier:write \"src/**/*.@(ts|tsx)\"", + "prettier:write": "prettier -c .prettierrc --write", "test": "jest" }, "husky": { @@ -77,7 +84,7 @@ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "testPathIgnorePatterns": [ "/node_modules/", - "/dist/" + "/lib/" ], "setupTestFrameworkScriptFile": "/src/setupTests.ts", "moduleFileExtensions": [ diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..10dd1706 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,31 @@ +import typescript from 'rollup-plugin-typescript2'; +import { uglify } from 'rollup-plugin-uglify'; +import pkg from './package.json'; + +const externals = [ + ...(Object.keys(pkg.dependencies) || {}), + ...(Object.keys(pkg.peerDependencies) || {}), +]; + +const createConfig = ({ output } = {}) => ({ + input: 'src/index.ts', + output, + external: externals, + plugins: [ + typescript({ + useTsconfigDeclarationDir: true, + tsconfig: './tsconfig.build.json', + typescript: require('typescript'), + }), + uglify(), + ], +}); + +export default [ + createConfig({ + output: { + file: pkg.main, + format: 'cjs', + }, + }), +]; diff --git a/src/components/Switch/Switch.tsx b/src/components/Switch/Switch.tsx index 90cc8916..0ed40a10 100644 --- a/src/components/Switch/Switch.tsx +++ b/src/components/Switch/Switch.tsx @@ -2,7 +2,9 @@ import * as PropTypes from 'prop-types'; import * as React from 'react'; import SwitchCase, { ISwitchCaseProps } from './SwitchCase'; -import SwitchDefault from './SwitchDefault'; +import SwitchDefault, { ISwitchDefaultProps } from './SwitchDefault'; + +type SwitchChildProps = ISwitchCaseProps & ISwitchDefaultProps; export interface ISwitchProps { /** Conditional statement. */ @@ -46,7 +48,7 @@ class Switch extends React.Component { React.Children.forEach( this.props.children, - (element: React.ReactElement) => { + (element: React.ReactElement) => { if (match === undefined && React.isValidElement(element)) { const caseValue = element.props.value; child = element; diff --git a/tsconfig.build.json b/tsconfig.build.json index efb75bc0..757689dd 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,11 +1,18 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "dist", + "outDir": "./lib", "sourceMap": false, "declaration": true, - "removeComments": false + "removeComments": false, + "declarationDir": "lib/types" }, - "include": ["src/**/*"], - "exclude": ["node_modules"] + "include": [ + "src/index.ts", + "src/components/**/index.ts" + ], + "exclude": [ + "src/**/*.test.ts", + "src/**/*.test.tsx" + ] } diff --git a/tsconfig.json b/tsconfig.json index f5e1eb8a..6353c0b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compileOnSave": false, "compilerOptions": { - "outDir": "./dist/out", + "outDir": "./build", "baseUrl": ".", "typeRoots": ["./node_modules/@types"], "target": "es5", @@ -12,8 +12,9 @@ "sourceMap": true, "allowSyntheticDefaultImports": false, "noUnusedLocals": true, - "noUnusedParameters": true, - "removeComments": false + "noUnusedParameters": true }, - "exclude": ["node_modules", "dist"] + "include": [ + "src/**/*" + ] }