Skip to content

Commit

Permalink
feat: typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyajeet Hora committed Dec 12, 2019
1 parent 052d4bc commit d86e1b3
Show file tree
Hide file tree
Showing 51 changed files with 1,793 additions and 409 deletions.
31 changes: 30 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,45 @@ module.exports = {
'react/no-access-state-in-setstate': 'off', // fixme
'react/no-array-index-key': 'off', // fixme
'react/no-this-in-sfc': 'off',
'import/no-unresolved': 'off', // fixme
},
plugins: ['formatjs'],
overrides: [
{
files: ['*.test.js'],
files: ['*.test.js', '*.test.tsx'],
globals: {
shallow: true,
mount: true,
takeScreenshot: true,
},
},
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off', // fixme
'import/extensions': 'off',
},
parser: "@typescript-eslint/parser",
extends: [
eslintrc,
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
],
"settings": {
"import/resolver": {
"typescript": {
"directory": "."
}
}
},
overrides: [
{
files: ['*.stories.tsx', '*.test.tsx'],
rules: {
'import/no-extraneous-dependencies': 'off'
},
}
]
}
]
};
2 changes: 1 addition & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ addParameters({
},
});

configure([require.context('../src', true, /\.stories\.js$/)], module);
configure([require.context('../src', true, /\.stories\.(js|tsx)$/)], module);
6 changes: 6 additions & 0 deletions .storybook/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.md' {
const content: string;
export = content;
}

declare function takeScreenshot(id: string): void;
21 changes: 16 additions & 5 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ const language = process.env.LANGUAGE;
const webpackConfig = Array.isArray(webpackConf) ? webpackConf[0] : webpackConf;
const locale = language ? language.substr(0, language.indexOf('-')) : 'en';

module.exports = async ({ config, mode }) => {
module.exports = async ({ config }) => {
config.plugins = [...webpackConfig.plugins, ...config.plugins];
config.resolve.extensions = [...config.resolve.extensions, ...webpackConfig.resolve.extensions];
config.resolve.alias = {
...config.resolve.alias,
'react-intl-locale-data': path.resolve(`node_modules/react-intl/locale-data/${locale}`),
'box-ui-elements-locale-data': path.resolve(`i18n/${language}`),
};
config.module.rules.push({
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
});
config.module.rules.push(
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: [
{ loader: 'babel-loader' },
{ loader: 'react-docgen-typescript-loader' }
]
},
);
return config;
};
12 changes: 7 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Place your settings in this file to overwrite default and user settings.
{
"typescript.validate.enable": false,
"typescript.format.enable": false,
"flow.useNPMPackagedFlow": true,
"flow.enabled": true,
"eslint.autoFixOnSave": true,
"javascript.validate.enable": false,
"prettier.printWidth": 120,
"prettier.tabWidth": 4,
"prettier.singleQuote": true
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
]
}
21 changes: 21 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ module.exports = {
'@babel/preset-react',
'@babel/preset-flow',
],
overrides: [
{
test: ['./src/**/*.ts', './src/**/*.tsx'],
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
'@babel/preset-react',
[
'@babel/preset-typescript',
{
isTSX: true,
allExtensions: true,
},
],
],
},
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-flow-strip-types',
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module.exports = {
'\\.(css|less|scss|md)$': '<rootDir>/scripts/jest/mocks/styleMock.js',
},
transformIgnorePatterns: ['node_modules/(?!(react-virtualized/dist/es))'],
testPathIgnorePatterns: ['/node_modules/', 'stories.test.js$'],
testPathIgnorePatterns: ['/node_modules/', 'stories.test.js$', 'stories.test.tsx$'],
collectCoverage: false,
coverageDirectory: '<rootDir>/reports',
collectCoverageFrom: ['src/**/*.js', '!**/node_modules/**', '!**/__tests__/**'],
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', '!**/node_modules/**', '!**/__tests__/**'],
globalSetup: '<rootDir>/scripts/jest/env-setup.js',
roots: ['src'],
rootDir: path.join(__dirname),
Expand Down
78 changes: 52 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"main": "es/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"types": "src/components/index.d.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
Expand Down Expand Up @@ -42,28 +43,29 @@
"build:ci:es": "yarn build:prod:es",
"build:ci:dist": "LANGUAGE=en-US ENTRY=explorer REACT=true yarn build:prod:dist",
"build:dev:dist": "LANGUAGE=en-US BABEL_ENV=development NODE_ENV=development webpack --config scripts/webpack.config.js --mode development --progress --colors",
"build:dev:es": "BABEL_ENV=development NODE_ENV=development yarn build:es --copy-files --source-maps inline --watch --ignore \"**/__tests__/**,**/__mocks__/**\"",
"build:es": "babel src --out-dir es",
"build:dev:es": "BABEL_ENV=development NODE_ENV=development yarn build:es --copy-files --source-maps inline --watch --ignore \"**/*.d.ts,**/__tests__/**,**/__mocks__/**\"",
"build:es": "babel src --extensions '.js,.tsx,.ts' --out-dir es",
"build:i18n": "props2es",
"build:npm": "npm-run-all clean build:i18n build:prod:npm build:prod:es",
"build:prod:analyze": "BUNDLE_ANALYSIS=true npm-run-all setup build:prod:npm",
"build:prod:es": "BABEL_ENV=npm NODE_ENV=production yarn build:es --source-maps --ignore \"**/__tests__/**,**/__mocks__/**\"",
"build:prod:es": "BABEL_ENV=npm NODE_ENV=production yarn build:es --source-maps --ignore \"**/*.d.ts,**/__tests__/**,**/__mocks__/**\"",
"build:prod:dist": "NODE_ENV=production webpack --config scripts/webpack.config.js --mode production",
"build:prod:examples": "LANGUAGE=en-US REACT=true NODE_ENV=production node --max_old_space_size=8192 node_modules/react-styleguidist/bin/styleguidist.js build --config scripts/styleguide.config.js --mode production",
"build:prod:npm": "BABEL_ENV=production OUTPUT=dist LANGUAGE=en-US REACT=true yarn build:prod:dist",
"build:prod:storybook": "LANGUAGE=en-US REACT=true BROWSERSLIST_ENV=production BABEL_ENV=development NODE_ENV=development build-storybook -c .storybook -o styleguide/storybook",
"build:sync": "LANGUAGE=en-US BABEL_ENV=development NODE_ENV=development RSYNC=true webpack --config scripts/webpack.config.js --mode development",
"build:variables": "cat `find src/styles/constants -name '*.scss'` > src/styles/variables.scss | node ./scripts/build-style-vars.js src/styles/variables.scss && rm src/styles/variables.scss",
"clean": "rm -rf dist es i18n/json i18n/*.js reports styleguide",
"copy:flow": "flow-copy-source --ignore \"**/__tests__/**\" --ignore \"**/__mocks__/**\" --ignore \"**/*.ts\" ./src ./es",
"copy:styles": "copyfiles './src/**/*.scss' es --up 1",
"copy:flow": "flow-copy-source --ignore \"**/__tests__/**\" --ignore \"**/__mocks__/**\" ./src ./es",
"cy:open": "yarn cy:wait; yarn cypress open",
"cy:run": "yarn cy:wait; yarn cypress run --spec \"test/integration/**/*.test.js\"",
"cy:wait": "wait-on http-get://localhost:6060/#",
"lint": "npm-run-all lint:*",
"lint:js": "eslint --max-warnings=0 .",
"lint:ts": "tsc && eslint --ext=.tsx,.ts --max-warnings=0 .",
"lint:css": "stylelint \"src/**/*.scss\" --syntax scss",
"prebuild:es": "npm-run-all build:variables copy:styles copy:flow",
"prebuild:es": "npm-run-all build:variables copy:styles ts:defs copy:flow",
"release": "yarn release:beta",
"release:beta": "DIST=beta BRANCH=master ./scripts/release.sh",
"release:hotfix": "DIST=latest HOTFIX=true ./scripts/release.sh",
Expand All @@ -83,7 +85,8 @@
"test:e2e": "BROWSERSLIST_ENV=test npm-run-all -p -r start:examples cy:run",
"test:e2e:open": "BROWSERSLIST_ENV=test npm-run-all -p -r start:examples cy:open",
"test:images": "yarn test -c scripts/jest/jest.config.js --maxWorkers=4",
"test:visuals": "start-server-and-test start:storybook:ci http-get://localhost:6061 test:images"
"test:visuals": "start-server-and-test start:storybook:ci http-get://localhost:6061 test:images",
"ts:defs": "tsc --declaration --emitDeclarationOnly --declarationDir es --noEmit false"
},
"browserslist": {
"production": [
Expand All @@ -98,6 +101,8 @@
},
"lint-staged": {
"*.js": ["eslint --fix", "git add"],
"*.ts": ["eslint --ext=.ts --fix", "git add"],
"*.tsx": ["eslint --ext=.tsx --fix", "git add"],
"*.md": ["prettier --write --parser=markdown", "git add"],
"*.json": ["prettier --write --parser=json", "git add"],
"*.html": ["prettier --write --parser=html", "git add"],
Expand All @@ -116,36 +121,51 @@
"yarn": ">=1.10.0"
},
"devDependencies": {
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/helper-create-class-features-plugin": "^7.7.4",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
"@babel/plugin-transform-flow-strip-types": "^7.7.4",
"@babel/plugin-transform-object-assign": "^7.7.4",
"@babel/polyfill": "^7.7.0",
"@babel/preset-env": "^7.7.4",
"@babel/preset-env": "^7.7.6",
"@babel/preset-flow": "^7.7.4",
"@babel/preset-react": "^7.7.4",
"@babel/preset-typescript": "^7.7.2",
"@babel/template": "^7.7.4",
"@babel/types": "^7.7.4",
"@box/frontend": "^5.1.3",
"@box/frontend": "^5.1.4",
"@box/languages": "^1.0.0",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@commitlint/travis-cli": "^8.2.0",
"@hapi/address": "^2.0.0",
"@sambego/storybook-state": "^1.3.6",
"@storybook/addon-actions": "^5.2.6",
"@storybook/addon-docs": "^5.2.6",
"@storybook/addon-info": "^5.2.6",
"@storybook/addon-knobs": "^5.2.6",
"@storybook/addon-links": "^5.2.6",
"@storybook/addon-notes": "^5.2.6",
"@storybook/addon-storyshots": "^5.2.6",
"@storybook/addon-viewport": "^5.2.6",
"@storybook/addons": "^5.2.6",
"@storybook/react": "^5.2.6",
"@storybook/addon-actions": "^5.2.8",
"@storybook/addon-docs": "^5.2.8",
"@storybook/addon-info": "^5.2.8",
"@storybook/addon-knobs": "^5.2.8",
"@storybook/addon-links": "^5.2.8",
"@storybook/addon-notes": "^5.2.8",
"@storybook/addon-storyshots": "^5.2.8",
"@storybook/addon-viewport": "^5.2.8",
"@storybook/addons": "^5.2.8",
"@storybook/preset-typescript": "^1.1.0",
"@storybook/react": "^5.2.8",
"@types/classnames": "^2.2.9",
"@types/enzyme": "^3.10.4",
"@types/jest": "^24.0.23",
"@types/jest-image-snapshot": "^2.11.0",
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.17",
"@types/react": "^16.9.16",
"@types/react-dom": "^16.9.4",
"@types/sinon": "^7.5.1",
"@types/webpack": "^4.41.0",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"autoprefixer": "^9.7.2",
"axios": "0.18.1",
"babel-core": "^7.0.0-bridge.0",
Expand Down Expand Up @@ -175,19 +195,20 @@
"enzyme": "3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
"enzyme-to-json": "^3.4.3",
"eslint": "^6.7.1",
"eslint": "^6.7.2",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.7.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-cypress": "^2.7.0",
"eslint-plugin-flowtype": "^4.5.2",
"eslint-plugin-formatjs": "^1.5.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.4",
"eslint-plugin-formatjs": "^1.5.4",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.1.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-lodash": "^6.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^1.7.0",
"filesize": "^4.1.2",
"flow-bin": "^0.95.1",
Expand All @@ -205,7 +226,7 @@
"jest-puppeteer": "^4.3.0",
"jsuri": "^1.3.1",
"leche": "^2.3.0",
"lint-staged": "^9.4.3",
"lint-staged": "^9.5.0",
"lodash": "^4.17.15",
"message-accumulator": "^2.1.1",
"mini-css-extract-plugin": "^0.8.0",
Expand All @@ -229,6 +250,8 @@
"react": "^16.9.0",
"react-animate-height": "^2.0.8",
"react-beautiful-dnd": "^9.0.2",
"react-docgen-typescript": "^1.16.1",
"react-docgen-typescript-loader": "^3.6.0",
"react-dom": "^16.9.0",
"react-draggable": "^3.3.0",
"react-immutable-proptypes": "^2.1.0",
Expand All @@ -250,13 +273,16 @@
"semantic-release": "^16.0.0-beta.36",
"sinon": "^2.3.7",
"start-server-and-test": "^1.10.6",
"storybook": "^5.1.11",
"string-replace-loader": "^2.2.0",
"style-loader": "^1.0.0",
"stylelint": "^12.0.0",
"stylelint-config-rational-order": "^0.1.2",
"stylelint-config-standard": "^19.0.0",
"stylelint-order": "^3.1.1",
"tabbable": "^1.1.3",
"ts-loader": "^6.2.1",
"typescript": "^3.7.3",
"uuid": "^3.3.2",
"wait-on": "^3.3.0",
"webpack": "^4.41.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');

module.exports = {
preset: 'jest-puppeteer',
testRegex: '(.*)?__tests__\\/.*\\.stories\\.test\\.js$',
testRegex: '(.*)?__tests__\\/.*\\.stories\\.test\\.(js|tsx)$',
setupFilesAfterEnv: [
'<rootDir>/node_modules/regenerator-runtime/runtime.js',
'<rootDir>/scripts/jest/visual-adapter.js',
Expand Down
Loading

0 comments on commit d86e1b3

Please sign in to comment.