-
Notifications
You must be signed in to change notification settings - Fork 3
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
[ParseCodeString] Implements the ParseCodeString utilities #87
Open
AkimaLunar
wants to merge
4
commits into
main
Choose a base branch
from
85-utility-for-parsing-files-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-arbutus-component-preview-b11b8013-7423-4c08-8669-5484e48df854.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Implements the ParseCodeString utilities", | ||
"packageName": "@microsoft/arbutus.component-preview", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@microsoft-arbutus-parse-code-string-b2b1dfed-1048-4753-bd50-1cc83bd2ceae.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Implements the ParseCodeString utilities", | ||
"packageName": "@microsoft/arbutus.parse-code-string", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"generatedAt":1678406000963,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":false,"hasStorybookEslint":false,"refCount":0,"monorepo":"Workspaces","packageManager":{"type":"npm","version":"8.19.2"},"storybookVersion":"6.5.15","language":"typescript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.15"},"@storybook/builder-webpack5":{"version":"6.5.15"},"@storybook/jest":{"version":"0.0.10"},"@storybook/manager-webpack5":{"version":"6.5.15"},"@storybook/react":{"version":"6.5.15"},"@storybook/testing-library":{"version":"0.0.13"}},"framework":{"name":"react"},"addons":{"@storybook/addon-links":{"version":"6.5.15"},"@storybook/addon-essentials":{"options":{"docs":false},"version":"6.5.15"},"@storybook/addon-interactions":{"version":"6.5.15"}}} | ||
{"generatedAt":1678489849818,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":false,"hasStorybookEslint":false,"refCount":0,"monorepo":"Workspaces","packageManager":{"type":"npm","version":"8.19.2"},"storybookVersion":"6.5.15","language":"typescript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.15"},"@storybook/builder-webpack5":{"version":"6.5.15"},"@storybook/jest":{"version":"0.0.10"},"@storybook/manager-webpack5":{"version":"6.5.15"},"@storybook/react":{"version":"6.5.15"},"@storybook/testing-library":{"version":"0.0.13"}},"framework":{"name":"react"},"addons":{"@storybook/addon-links":{"version":"6.5.15"},"@storybook/addon-essentials":{"options":{"docs":false},"version":"6.5.15"},"@storybook/addon-interactions":{"version":"6.5.15"}}} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
# configs | ||
just.config.js | ||
**/.eslintrc.js | ||
**/tsconfig.js | ||
lage.config.js | ||
**/*.config.js | ||
|
||
# generated folders | ||
__snapshots__ | ||
.cache | ||
dist | ||
lib | ||
node_modules | ||
|
||
# template files which actually follow a different language's formatting | ||
_templates |
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,8 @@ | ||
__tests__ | ||
__dev__ | ||
.cache | ||
node_modules | ||
src | ||
.eslintrc | ||
.eslintignore | ||
tsconfig.json |
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,13 @@ | ||
# Utility: Parse Code String | ||
|
||
**Utility functions that receive code as a string and return information about it.** | ||
|
||
## Get Started | ||
|
||
```sh | ||
npm i "@microsoft/arbutus.parse-code-string" | ||
``` | ||
|
||
```ts | ||
import { parseCodeString } from "@microsoft/arbutus.parse-code-string"; | ||
``` |
25 changes: 25 additions & 0 deletions
25
utilities/parse-code-string/__dev__/example-component.raw.ts
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,25 @@ | ||
export default `import { mergeClasses } from '@griffel/react'; | ||
import { Text } from '@microsoft/arbutus.text'; | ||
import { Tile } from '@microsoft/arbutus.tile'; | ||
import { useSpaceStyles } from '@microsoft/arbutus.use-space-styles'; | ||
import * as React from 'react'; | ||
|
||
const ExampleComponent = () => { | ||
const space = useSpaceStyles(); | ||
|
||
return ( | ||
<Tile variant="card" className={mergeClasses(space.py9, space.px7)}> | ||
<Text variant="headline" className={space.mb7} block> | ||
Example Component | ||
</Text> | ||
<Text variant="description" block> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veniam sapiente voluptas | ||
laudantium placeat aliquam eum nesciunt dolorem rerum, quasi ea quisquam natus | ||
repellendus! Laudantium expedita laborum natus, earum tenetur quidem? | ||
</Text> | ||
</Tile> | ||
); | ||
}; | ||
|
||
export default ExampleComponent; | ||
`; |
113 changes: 113 additions & 0 deletions
113
utilities/parse-code-string/__dev__/parse-code-string.stories.tsx
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,113 @@ | ||
import { makeStyles } from '@griffel/react'; | ||
import { CodeSnippet } from '@microsoft/arbutus.code-snippet'; | ||
import { Command } from '@microsoft/arbutus.command'; | ||
import { TableCell, TableList, TableRow } from '@microsoft/arbutus.table-list'; | ||
import { Text } from '@microsoft/arbutus.text'; | ||
import { useSpaceStyles } from '@microsoft/arbutus.use-space-styles'; | ||
import type { Meta, Story } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Centered } from '../../../.storybook/decorators'; | ||
import { getDefaultExportName, getDependencies } from '../src/index'; | ||
import codeStr from './example-component.raw'; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
maxWidth: '860px', | ||
display: 'grid', | ||
gridGap: '16px', | ||
}, | ||
code: { | ||
wordWrap: 'break-word', | ||
maxWidth: '100%', | ||
}, | ||
}); | ||
|
||
const codeExample = `import { getDefaultExportName, getDependencies } from '@microsoft/arbutus.parse-code-string'; | ||
import codeStr from './example-component.raw'; | ||
|
||
const dependencies = getDependencies(codeStr); | ||
const defaultExportName = getDefaultExportName(codeStr); | ||
`; | ||
|
||
const DemoComponent = () => { | ||
const classes = useStyles(); | ||
const space = useSpaceStyles(); | ||
|
||
const dependencies = getDependencies(codeStr); | ||
const defaultExportName = getDefaultExportName(codeStr); | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<Text as="h1" block variant="title"> | ||
Parse Code String utilities | ||
</Text> | ||
<Text as="h2" block variant="headline"> | ||
Usage | ||
</Text> | ||
<Command isCopyable command="npm i @microsoft/arbutus.parse-code-string" /> | ||
<CodeSnippet language="typescript" code={codeExample} /> | ||
<Text as="h2" block variant="headline"> | ||
Example file | ||
</Text> | ||
<CodeSnippet language="javascript" code={codeStr} /> | ||
|
||
<Text variant="description" block> | ||
If you need to generate a string from a file, you can use the{' '} | ||
<Text variant="code">fileToString()</Text> utility from the{' '} | ||
<Text variant="code">@microsoft/arbutus.file-to-string</Text> | ||
package. | ||
</Text> | ||
<Text as="h2" block variant="headline"> | ||
Result | ||
</Text> | ||
<TableList className={space.mb6}> | ||
<TableRow> | ||
<TableCell isHeader>Function</TableCell> | ||
<TableCell isHeader>Output</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell isHeader> | ||
<Text | ||
variant="code" | ||
className={classes.code} | ||
>{`getDependencies(codeStr: string)`}</Text> | ||
</TableCell> | ||
<TableCell> | ||
<Text variant="code" className={classes.code}> | ||
{JSON.stringify(dependencies)} | ||
</Text> | ||
</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell isHeader> | ||
<Text | ||
variant="code" | ||
className={classes.code} | ||
>{`getDefaultExportName(codeStr: string)`}</Text> | ||
</TableCell> | ||
<TableCell> | ||
<Text variant="code" className={classes.code}> | ||
{JSON.stringify(defaultExportName, null, 2)} | ||
</Text> | ||
</TableCell> | ||
</TableRow> | ||
</TableList> | ||
</div> | ||
); | ||
}; | ||
|
||
export default { | ||
title: 'Utilities/ParseCodeString', | ||
decorators: [ | ||
(Story) => ( | ||
<Centered> | ||
<Story /> | ||
</Centered> | ||
), | ||
], | ||
} as Meta; | ||
|
||
const Template: Story = () => <DemoComponent />; | ||
|
||
export const Demo = Template.bind({}) as Story; |
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,23 @@ | ||
{ | ||
"name": "@microsoft/arbutus.parse-code-string", | ||
"version": "0.0.1", | ||
"description": "Utility functions that receive code as a string and return information about it.", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"exports": [ | ||
"./lib/index.js" | ||
], | ||
"files": [ | ||
"lib/**" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "tsc", | ||
"lint": "eslint . --fix" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/arbutus.ts": "0.0.2", | ||
"typescript": "^4.9.4" | ||
} | ||
} |
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,2 @@ | ||
export const getDefaultExportName = (codeStr: string) => | ||
codeStr.match(/export\s+default\s+(\w+)/)?.[1]; |
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,6 @@ | ||
export const getDependencies = (codeStr: string) => { | ||
const regex = /import\s.*\sfrom\s+['"](.*)['"]/g; | ||
const dependencies = [...codeStr.matchAll(regex)].map(([_, result]) => result); | ||
|
||
return dependencies; | ||
}; |
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,2 @@ | ||
export { getDefaultExportName } from './get-default-export-name'; | ||
export { getDependencies } from './get-dependencies'; |
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,10 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@microsoft/arbutus.ts", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"esModuleInterop": true, | ||
"moduleResolution": "nodenext" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data