Skip to content

Commit

Permalink
Pladaria/ts (#32)
Browse files Browse the repository at this point in the history
* APPS-6692 WIP migrate to TS

* APPS-6692 WIP migrate to TS

* APPS-6692 WIP migrate to TS - cp theme-context.tsx

* APPS-6692 WIP migrate to TS - jss type tests

* APPS-6692 WIP migrate to TS - fix lint issues, create theme.tsx

* APPS-6692 WIP migrate to TS - add utils

* APPS-6692 WIP migrate to TS - fix eslint issues

* APPS-6692 WIP migrate to TS - copy platform and region-code

* APPS-6692 WIP migrate to TS - copy media queries

* APPS-6692 WIP migrate TS - cp colors

* APPS-6692 WIP migrate TS - colors

* APPS-6692 WIP migrate TS - colors

* APPS-6692 WIP migrate TS - jss types

* APPS-6692 WIP migrate TS - jss types

* APPS-6692 WIP migrate TS - jss types

* APPS-6692 WIP migrate TS - cp stack

* APPS-6692 WIP migrate TS - cp touchable

* APPS-6692 WIP migrate TS - add keycodes

* APPS-6692 WIP migrate TS - touchable

* APPS-6692 WIP migrate TS - update tsconfig

* APPS-6692 WIP migrate TS - screen reader only cp

* APPS-6692 WIP migrate TS - cp hooks

* APPS-6692 WIP migrate TS - screen size context

* APPS-6692 WIP migrate TS - screen size context

* APPS-6692 WIP migrate TS - fix locale

* APPS-6692 update hook

* APPS-6692 rm sync-from-webapp.sh script

* APPS-6692 update index

* APPS-6692 revert change in eslint config

* APPS-6692 dts-to-flow

* APPS-6692 flow types generation

* APPS-6692 flow types generation

* APPS-6692 flow types generation

* APPS-6692 flow types generation

* APPS-6692 flow types generation

* APPS-6692 flow types generation

* APPS-6692 improve jss types

* APPS-6692 cp button

* APPS-6692 cp spinner

* APPS-6692 cp spinner

* APPS-6692 cp spinner

* APPS-6692 cp spinner

* APPS-6692 spinner tsx

* APPS-6692 box tsx

* APPS-6692 cp color

* APPS-6692 color tsx

* APPS-6692 cp form context

* APPS-6692 cp theme variant context

* APPS-6692 migrate to tsx

* APPS-6692 update generator

* APPS-6692 update generator

* APPS-6692 some tooling

* APPS-6692 fix tabIndex type

* APPS-6692 improve flow definitions

* APPS-6692 cp to tsx

* APPS-6692 compatible types

* APPS-6692 fixes to adapt to webapp

* APPS-6692 expose textDanger

* APPS-6692 type overrides and type fixes

* APPS-6692 tweak types

* APPS-6692 rename all js to tsx

* APPS-6692 migrate all icons

* APPS-6692 migrate utils

* APPS-6692 migrate more components

* APPS-6692 [WIP] migrate to TS

* APPS-6692 [WIP] migrate to TS

* APPS-6692 [WIP] migrate to TS

* APPS-6692 [WIP] migrate to TS

* APPS-6692 [WIP] migrate to TS

* APPS-6692 [WIP] migrate to TS

* APPS-6692 format d.ts

* APPS-6692 rm js files

* APPS-6692 update flow-defs

* APPS-6692 storybook config for TS

* APPS-6692 update build script

* APPS-6692 improvements after CR

* APPS-6692 remove comments

* APPS-6692 update flow defs and use babel macro

* APPS-6692 working acceptance tests

* APPS-6692 unit tests passing

* APPS-6692 update config

* APPS-6692 remove FlowFixMes

* APPS-6692 remove debug code

* APPS-6692 remove screenshot

* APPS-6692 remove old screenshots

* APPS-6692 configure playroom

* APPS-6692 revert box changes

* APPS-6692 fix empty ComponentType transform

* APPS-6692 watch script

* APPS-6692 watch script

* APPS-6692 watch script

* APPS-6692 watch script
  • Loading branch information
pladaria authored Jun 25, 2020
1 parent 8614628 commit 3709888
Show file tree
Hide file tree
Showing 373 changed files with 7,887 additions and 2,691 deletions.
13 changes: 11 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"presets": [
"@babel/preset-react",
"@babel/preset-flow",
[
"@babel/preset-typescript",
{
"isTSX": true,
"allExtensions": true,
"allowNamespaces": false,
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
Expand All @@ -15,7 +23,8 @@
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
"@babel/plugin-proposal-optional-chaining",
"macros"
],
"env": {
"test": {
Expand Down
60 changes: 58 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parser: babel-eslint
parser: babel-eslint # typescript parser is used as an override (see overrides section)
env:
es6: true
node: true
browser: true
jest/globals: true
parserOptions: # http://eslint.org/docs/user-guide/configuring.html#specifying-parser-options
Expand All @@ -21,12 +22,15 @@ plugins:
- testing-library
- flowtype
- import
- '@typescript-eslint'
extends:
- 'eslint:recommended'
rules:
# Basic rules
default-case: error
dot-notation: error
eqeqeq: error
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*$']
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*(\.(config))?$'] # matches: "foo-bar" or "foo-bar.config"
new-cap: [error, {newIsCap: true, capIsNew: false}]
no-cond-assign: error
no-debugger: error
Expand Down Expand Up @@ -154,3 +158,55 @@ rules:
import/no-named-default: error
import/no-useless-path-segments: error
import/no-self-import: error

overrides:
# overrides for TypeScript files
- files:
- '*.tsx'
parser: '@typescript-eslint/parser'
rules:
'flowtype/no-types-missing-file-annotation': off
no-unused-vars: off
'@typescript-eslint/no-unused-vars':
- error
- vars: all
args: after-used
ignoreRestSiblings: true
'@typescript-eslint/no-empty-function': off
'@typescript-eslint/no-explicit-any': off
'@typescript-eslint/ban-ts-comment':
- error
- ts-expect-error: allow-with-description
ts-ignore: true
ts-nocheck: true
ts-check: false
'@typescript-eslint/no-namespace':
- error
- allowDeclarations: false
allowDefinitionFiles: false
'no-restricted-syntax':
- error
- selector: TSEnumDeclaration
message: 'enums are not allowed'
'@typescript-eslint/prefer-as-const': off # TODO: review this rule and check how flowgen translates "as const" syntax
extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'

# overrides for Type Tests
- files:
- '**/__type_tests__/*-type-test.tsx'
- '**/__type_tests__/*-type-test.js'
rules:
'no-unused-vars': off
'babel/no-unused-expressions': off
'@typescript-eslint/no-unused-vars': off

# overrides for flow definitions
- files:
- '*.js.flow'
rules:
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*\.js$'] # matches: "foo-bar.js"
no-use-before-define: off
import/no-duplicates: off
no-undef: off
5 changes: 4 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[ignore]
.*/node_modules/.*
!.*/node_modules/@tef-novum/.*
<PROJECT_ROOT>/dist/.*
<PROJECT_ROOT>/playroom/.*
<PROJECT_ROOT>/.storybook/.*
<PROJECT_ROOT>/scripts/dts-to-flow/overrides


[include]

Expand Down
38 changes: 38 additions & 0 deletions .storybook/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Workaround until these issues get fixed and released
// https://github.com/storybookjs/storybook/pull/10980
// https://github.com/storybookjs/storybook/pull/10813
//
// At this moment we cannot write addon's register in TSX (extension must be .js)
// but then we cannot import stuff from ./src
// So this module replaces the required parts from ./src/colors.tsx

/**
* @param {'Movistar' | 'Vivo' | 'O2'} skin
*/
export const getColors = (skin) => {
switch (skin) {
case 'Movistar':
return {
PRIMARY: '#019DF4',
TEXT_PRIMARY: '#313235',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#86888C',
};
case 'Vivo':
return {
PRIMARY: '#660099',
TEXT_PRIMARY: '#000000',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#666666',
};
case 'O2':
return {
PRIMARY: '#032B5A',
TEXT_PRIMARY: '#000033',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#757575',
};
default:
throw Error('Unexpected skin: ' + skin);
}
};
21 changes: 15 additions & 6 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// @flow
const path = require('path');

const config /*: any*/ = {
stories: ['./welcome-story.js', '../src/**/__stories__/*-story.js'],
module.exports = {
stories: ['./welcome-story.tsx', '../src/**/__stories__/*-story.tsx'],
addons: [
'@storybook/addon-links',
{
name: '@storybook/addon-storysource',
options: {
rule: {
test: [/\-story\.js/],
test: [/-story\.tsx/],
include: [path.resolve(__dirname, '..', 'src'), __dirname],
},
loaderOptions: {
Expand All @@ -19,6 +18,16 @@ const config /*: any*/ = {
},
'./.storybook/theme-selector-addon/register',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.tsx$/,
use: [
{
loader: require.resolve('ts-loader'),
},
],
});
config.resolve.extensions.push('.tsx');
return config;
},
};

module.exports = config;
1 change: 0 additions & 1 deletion .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import '../css/roboto.css';
import '../css/reset.css';
import {addons} from '@storybook/addons';
Expand Down
31 changes: 8 additions & 23 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import '../css/roboto.css';
import '../css/reset.css';
import * as React from 'react';
Expand All @@ -7,11 +6,8 @@ import {ThemeContextProvider, Box, MOVISTAR_SKIN, VIVO_SKIN, O2_SKIN} from '../s
import addons from '@storybook/addons';
import getTheme from './theme-selector-addon/themes';

import type {Context} from '@storybook/react';
import type {Skin} from '../src';

const getUserAgent = (): string => self.navigator.userAgent || '';
const isRunningAcceptanceTest = (): boolean => getUserAgent().includes('acceptance-test');
const getUserAgent = () => self.navigator.userAgent || '';
const isRunningAcceptanceTest = () => getUserAgent().includes('acceptance-test');

const acceptanceStyles = `
*, *:after, *:before {
Expand All @@ -29,18 +25,7 @@ const acceptanceStyles = `
height: 0 !important;
}`;

type DecoratorProps = {
Story: React.ComponentType<any>,
context?: {
...Context,
parameters: {
fullScreen?: boolean,
},
...
},
};

const LayoutDecorator = ({Story, context}: DecoratorProps) => {
const LayoutDecorator = ({Story, context}) => {
const styles = isRunningAcceptanceTest() ? <style>{acceptanceStyles}</style> : null;

return (
Expand All @@ -53,19 +38,19 @@ const LayoutDecorator = ({Story, context}: DecoratorProps) => {
);
};

const getSkin = (searchParams): ?Skin => {
const getSkin = (searchParams) => {
const qsSkin = searchParams.get('skin');
return [MOVISTAR_SKIN, O2_SKIN, VIVO_SKIN].find((skin) => skin === qsSkin);
};

const getPlatform = (searchParams): ?'ios' | 'android' => {
const getPlatform = (searchParams) => {
const qsPlatform = searchParams.get('platform');
return ['ios', 'android'].find((platform) => platform === qsPlatform);
};

const ThemeDecorator = ({Story}: DecoratorProps) => {
const ThemeDecorator = ({Story}) => {
const searchParams = new URLSearchParams(location.search);
const [skin, setSkin] = React.useState<?Skin>(getSkin(searchParams));
const [skin, setSkin] = React.useState(getSkin(searchParams));

React.useEffect(() => {
const channel = addons.getChannel();
Expand All @@ -81,5 +66,5 @@ const ThemeDecorator = ({Story}: DecoratorProps) => {
);
};

addDecorator((Story, context: any) => <LayoutDecorator Story={Story} context={context} />);
addDecorator((Story, context) => <LayoutDecorator Story={Story} context={context} />);
addDecorator((Story) => <ThemeDecorator Story={Story} />);
11 changes: 6 additions & 5 deletions .storybook/storybook-manager-theme.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @flow
import logo from '../img/mistica-logo.svg';
import {getColors} from '../src';
import {create} from '@storybook/theming/create';
import {getColors} from './colors';

import type {Skin} from '../src';
import {create} from '@storybook/theming/create';

const createTheme = (skin: Skin): any => {
/**
* @param {'Movistar' | 'Vivo' | 'O2'} skin
*/
const createTheme = (skin) => {
const colors = getColors(skin);
return create({
base: 'light',
Expand Down
5 changes: 2 additions & 3 deletions .storybook/theme-selector-addon/register.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @flow
import * as React from 'react';
import addonApi, {types} from '@storybook/addons';
import {WithTooltip, IconButton, TooltipLinkList} from '@storybook/components';
import {getColors} from '../../src';
import {getColors} from '../colors';
import {AVAILABLE_THEMES} from './themes';
import createManagerTheme from '../storybook-manager-theme';

Expand All @@ -26,7 +25,7 @@ const ThemeSelectorAddon = ({api}) => {

api.setOptions({theme: createManagerTheme(currentSkin)});

// We need this timeout because there could be some race condition between addon mount and storibook manager initialization on page load.
// We need this timeout because there could be some race condition between addon mount and storybook manager initialization on page load
const tid = setTimeout(() => {
api.setOptions({theme: createManagerTheme(currentSkin)});
}, 100);
Expand Down
13 changes: 5 additions & 8 deletions .storybook/theme-selector-addon/themes.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// @flow
import type {ThemeConfig, Skin} from '../../src';

export const Movistar: ThemeConfig = {
export const Movistar = {
i18n: {locale: 'es-ES', phoneNumberFormattingRegionCode: 'ES'},
skin: 'Movistar',
};

export const O2: ThemeConfig = {
export const O2 = {
i18n: {locale: 'en-US', phoneNumberFormattingRegionCode: 'GB'},
skin: 'O2',
};

export const Vivo: ThemeConfig = {
export const Vivo = {
i18n: {locale: 'pt-BR', phoneNumberFormattingRegionCode: 'BR'},
skin: 'Vivo',
};

export const AVAILABLE_THEMES = [Movistar, O2, Vivo];

export default (selectedSkin: ?Skin, selectedPlatform: ?'ios' | 'android'): ThemeConfig => {
const themeConfig: ThemeConfig = AVAILABLE_THEMES.find(({skin}) => skin === selectedSkin) || Movistar;
export default (selectedSkin, selectedPlatform) => {
const themeConfig = AVAILABLE_THEMES.find(({skin}) => skin === selectedSkin) || Movistar;
return selectedPlatform
? {
...themeConfig,
Expand Down
3 changes: 1 addition & 2 deletions .storybook/welcome-story.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import * as React from 'react';
import {Text, Stack, Box, ResponsiveLayout, useTheme, ButtonLink, TextLink} from '../src';
import logo from '../img/mistica-react-logo.svg';
Expand All @@ -16,7 +15,7 @@ const Paragraph = ({children}) => {
);
};

export const Mistica = (): React.Node => {
export const Mistica = () => {
return (
<ResponsiveLayout>
<Box paddingY={32}>
Expand Down
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"javascript.validate.enable": false
"javascript.validate.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",
"search.exclude": {
"**/node_modules": true,
"**/flow-defs": true,
"**/flow-typed": true
}
}
Loading

0 comments on commit 3709888

Please sign in to comment.