-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
276 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"jsx-a11y/accessible-emoji": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `yarn observer` | ||
|
||
A command-line interface to observe the impact of a change across the component library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React from 'react'; | ||
import tinycolor from 'tinycolor2'; | ||
import tokens from '@shopify/polaris-tokens'; | ||
import {Box, Text, render, Color} from 'ink'; | ||
|
||
const data = [ | ||
{ | ||
path: 'src/components/Button/', | ||
filename: 'Button.tsx', | ||
componentsAffected: [ | ||
{path: 'src/components/ButtonGroup/', filename: 'ButtonGroup.tsx'}, | ||
{path: 'src/components/CalloutCard/', filename: 'CalloutCard.tsx'}, | ||
{path: 'src/components/Caption/', filename: 'Caption.tsx'}, | ||
{path: 'src/components/TopBar/', filename: 'TopBar.tsx'}, | ||
], | ||
}, | ||
{ | ||
path: 'src/components/Button/', | ||
filename: 'Button.scss', | ||
componentsAffected: [ | ||
{path: 'src/components/ButtonGroup/', filename: 'ButtonGroup.tsx'}, | ||
{path: 'src/components/Caption/', filename: 'Caption.tsx'}, | ||
{path: 'src/components/Button/', filename: 'Button.tsx'}, | ||
], | ||
}, | ||
{ | ||
path: 'src/components/Checkbox/', | ||
filename: 'Checkbox.tsx', | ||
componentsAffected: [ | ||
{ | ||
path: 'src/components/ContextualSaveBar/', | ||
filename: 'ContextualSaveBar.tsx', | ||
}, | ||
{ | ||
path: 'src/components/EmptySearchResult/', | ||
filename: 'EmptySearchResult.tsx', | ||
}, | ||
{path: 'src/components/Labelled/', filename: 'Labelled.tsx'}, | ||
{path: 'src/components/Button/', filename: 'Button.tsx'}, | ||
], | ||
}, | ||
]; | ||
|
||
const Component = ({path, filename, componentsAffected}) => ( | ||
<Box marginBottom={1} flexDirection="column"> | ||
<Box paddingLeft={2}> | ||
{filename.endsWith('tsx') ? '🧩 ' : '💅 '} | ||
<Text underline> | ||
<Color dim>{path}</Color> | ||
<Text bold>{filename}</Text> | ||
</Text> | ||
</Box> | ||
<Box marginLeft={4}>Affected files:</Box> | ||
{componentsAffected.map(({path, filename}) => ( | ||
<Box marginLeft={4} key={path + filename}> | ||
<Text> | ||
<Color dim>{path}</Color> | ||
{filename} | ||
</Text> | ||
</Box> | ||
))} | ||
</Box> | ||
); | ||
|
||
const Components = ({components}) => ( | ||
<React.Fragment> | ||
{components.map(({path, filename, componentsAffected}) => ( | ||
<Component | ||
key={path + filename} | ||
path={path} | ||
filename={filename} | ||
componentsAffected={componentsAffected} | ||
/> | ||
))} | ||
</React.Fragment> | ||
); | ||
|
||
const Summary = ({ | ||
componentsModified, | ||
componentsAffected, | ||
}: { | ||
componentsModified: number; | ||
componentsAffected: number; | ||
}) => ( | ||
<Box flexDirection="column"> | ||
<Box> | ||
<Box width={22}> | ||
<Text>Components modified:</Text> | ||
</Box> | ||
{componentsModified} | ||
</Box> | ||
<Box> | ||
<Box width={22}> | ||
<Text>Components affected:</Text> | ||
</Box> | ||
{componentsAffected} | ||
</Box> | ||
</Box> | ||
); | ||
|
||
render( | ||
<React.Fragment> | ||
<Box marginBottom={1}> | ||
💡 tip: command + click file paths to open them in your text editor | ||
</Box> | ||
<Components components={data} /> | ||
<Summary | ||
componentsModified={data.length} | ||
componentsAffected={ | ||
new Map([ | ||
...data.map(({path, filename}) => [path, path + filename]), | ||
...data.reduce( | ||
(val, curr) => | ||
val.concat( | ||
curr.componentsAffected.map(({path}) => [ | ||
path, | ||
curr.path + curr.filename, | ||
]), | ||
), | ||
[], | ||
), | ||
]).size | ||
} | ||
/> | ||
</React.Fragment>, | ||
); |
Oops, something went wrong.