-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flow types generation, fix flow types #207
Changes from 20 commits
20b9d1f
fefbc9f
ebb3a63
e1fa079
dcdde97
d9fec59
56962d2
2094646
6ab920f
8e4f4ef
508c41c
5635ca9
ab0a34e
627862e
da17d26
0a7ff12
fba7a4e
889e555
9368637
e4c979f
f03e50c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable */ | ||
const { execSync } = require('child_process'); | ||
|
||
const p = require('../package.json'); | ||
|
||
const currentVersion = p.version; | ||
const flowVersion = String(execSync('flow version')).match(/[\d\.]+/)[0]; | ||
|
||
const declarations = execSync( | ||
`jscodeshift -s -t scripts/extractFlowTypes.js src/components/**/*.jsx src/components/layout/**/*.jsx --parser flow` | ||
); | ||
|
||
console.log(` | ||
// flow-typed version: <<STUB>>/@wework-dev/plasma_v${currentVersion}/flow_v${flowVersion} | ||
|
||
${String(declarations).replace(/\bNode\b/g, 'React$Node')} | ||
|
||
declare module '@wework-dev/plasma' { | ||
declare type Data = { key: string, value: string }; | ||
|
||
declare export class CountedTextInput extends React$Component<{ ...$PropertyType<TextInput, 'props'>, counterStyle: string }> { } | ||
declare export class CountedTextArea extends React$Component<{ ...$PropertyType<TextArea, 'props'>, counterStyle: string }> { } | ||
|
||
declare export var LocationPin: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we automatically export all files under icons as strings? |
||
} | ||
`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
export default function transformer(file, api) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
|
||
root.find(j.TypeAlias).forEach(p => { | ||
const componentName = file.path.match(/(\w+)\.jsx/)[1]; | ||
|
||
const { line, column } = p.value.id.loc.start; | ||
|
||
const typeAtPosOutput = String( | ||
execSync(`flow type-at-pos ${file.path} ${line} ${column + 1} --quiet`) | ||
); | ||
|
||
const fullTypeDeclaration = typeAtPosOutput.split('\n')[0]; | ||
const typeDeclarationRHS = fullTypeDeclaration.replace(/^type\s+\w+\s+=\s+/, ''); | ||
|
||
if (p.value.id.name === 'Props') { | ||
// declare export class ... | ||
console.log( | ||
`declare export class ${componentName} extends React$Component<${typeDeclarationRHS}> { }` | ||
); | ||
} else if (p.value.id.name !== 'State') { | ||
// declare type ... = ... | ||
console.log(`declare ${fullTypeDeclaration}`); | ||
} | ||
|
||
console.log('\n'); | ||
}); | ||
return file.source; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,15 @@ type HandleEvent = {| | |
}, | ||
|}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a mock (and roundabout) definition of |
||
type Props = {| | ||
data: Data, | ||
disabled: boolean, | ||
error: boolean, | ||
data?: Data, | ||
disabled?: boolean, | ||
error?: boolean, | ||
maxValue: number, | ||
minValue: number, | ||
onBlur: HandleEvent => void, | ||
onBlur?: HandleEvent => void, | ||
onChange: HandleEvent => void, | ||
onFocus: HandleEvent => void, | ||
placeholder: string, | ||
onFocus?: HandleEvent => void, | ||
placeholder?: string, | ||
step: number, | ||
value: string, | ||
|}; | ||
|
@@ -42,6 +42,7 @@ class NumberInput extends React.Component<Props> { | |
step: 1, | ||
maxValue: Number.MAX_SAFE_INTEGER, | ||
minValue: Number.MIN_SAFE_INTEGER, | ||
onChange() {}, | ||
}; | ||
|
||
handleIncrement = (): void => { | ||
|
@@ -59,7 +60,7 @@ class NumberInput extends React.Component<Props> { | |
}; | ||
|
||
handleChange = (e: HandleEvent): void => { | ||
this.props.onChange(e.nativeEvent.target.value); | ||
this.props.onChange && this.props.onChange(e.nativeEvent.target.value); | ||
}; | ||
|
||
handleBlur = (e: HandleEvent): void => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ import style from './style.scss'; | |
|
||
type Props = {| | ||
data?: Data, | ||
checked: boolean, | ||
description: ?string, | ||
disabled: ?boolean, | ||
fancy: ?boolean, | ||
fieldValue: string, | ||
icon: ?string, | ||
isLarge: ?boolean, | ||
checked?: boolean, | ||
description?: ?string, | ||
disabled?: ?boolean, | ||
fancy?: ?boolean, | ||
fieldValue?: string, | ||
icon?: ?string, | ||
isLarge?: ?boolean, | ||
name: string, | ||
onChange: () => mixed, | ||
onChange: (event: SyntheticEvent<HTMLInputElement>) => mixed, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest |
||
text: string, | ||
value?: string, | ||
|}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we would generate decorated components automatically