-
Notifications
You must be signed in to change notification settings - Fork 16
feat(*): automate parser listing #200
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
Draft
AllanMichay
wants to merge
1
commit into
master
Choose a base branch
from
feat/automate-parser-listing
base: master
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.
Draft
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
This file contains hidden or 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,40 @@ | ||
| name: 'Parser Listing' | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| types: ['ready_for_review', 'opened', 'synchronize', 'reopened'] | ||
| env: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| jobs: | ||
| list: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.pull_request.draft == false | ||
| steps: | ||
| - uses: actions/checkout@main | ||
| - name: Extract branch name | ||
| shell: bash | ||
| run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | ||
| id: extract_branch | ||
| - name: Install | ||
| run: yarn install --frozen-lockfile | ||
| - name: Create Listing | ||
| run: yarn list-parsers | ||
| - uses: technote-space/get-diff-action@v6 | ||
| id: diff | ||
| with: | ||
| FILES: | | ||
| SUMMARY.md | ||
| - name: Pushes parser list | ||
| uses: dmnemec/copy_file_to_another_repo_action@main | ||
| if: steps.diff.outputs.diff | ||
| env: | ||
| API_TOKEN_GITHUB: ${{ secrets.GH_PARSERS_TOKEN }} | ||
| with: | ||
| source_file: 'output/parsers.md' | ||
| destination_repo: 'Specifyapp/Documentation' | ||
| destination_folder: 'concepts' | ||
| user_email: 'allan.michay@gmail.com' | ||
| user_name: 'AllanMichay' | ||
| commit_message: 'feat(parsers): update parsers list' |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const directoryPath = path.join(__dirname, '../', 'parsers'); | ||
| let parsers = []; | ||
| const fileNames = fs.readdirSync(directoryPath); | ||
|
|
||
| const directories = fileNames.filter(fileName => !fileName.includes('.ts')); | ||
|
|
||
| parsers = directories.map(directory => { | ||
| const readmeParserPath = path.join(__dirname, '../', 'parsers', directory, 'README.md'); | ||
| const parserContent = fs.readFileSync(readmeParserPath, { encoding: 'utf8', flag: 'r' }); | ||
|
|
||
| const parserDescription = parserContent.match(/This parser helps you (.*)/)[1]; | ||
| const capitalizedParserDescription = | ||
| parserDescription.charAt(0).toUpperCase() + parserDescription.slice(1); | ||
| const exampleLink = `https://github.com/Specifyapp/parsers/blob/master/parsers/${directory}/README.md#usage`; | ||
| const parserLink = `https://github.com/Specifyapp/parsers/blob/master/parsers/${directory}`; | ||
|
|
||
| return { | ||
| title: directory, | ||
| description: capitalizedParserDescription, | ||
| parserLink, | ||
| exampleLink, | ||
| }; | ||
| }); | ||
|
|
||
| const markdownFullPage = `--- | ||
| description: >- | ||
| Parsers are functions allowing you to transform design tokens and assets | ||
| coming from Specify to fit your needs and company standards. | ||
| --- | ||
|
|
||
| # Parsers | ||
|
|
||
| ## Why you need parsers | ||
|
|
||
| <figure><img src="../front/documentation/.gitbook/assets/where-parsers-happen-dark.jpg" alt=""><figcaption><p>Parsers help you transform raw design tokens and assets returned by Specify to match your company standards</p></figcaption></figure> | ||
|
|
||
| By default, without any parsers, Specify will return your design data as raw data: | ||
|
|
||
| * Design tokens are returned in JSON | ||
| * Assets are returned as files | ||
|
|
||
| There are high chances you need to transform those design data to fit your needs. Parsers help you do just that. | ||
|
|
||
| ## What are parsers? | ||
|
|
||
| Parsers are functions allowing you to transform design tokens and assets coming from Specify to fit your needs and company standards. | ||
|
|
||
| <figure><img src="../front/documentation/.gitbook/assets/how-parsers-work.jpg" alt=""><figcaption><p>An example output pipeline that pulls colors from Specify, sorts them alphabetically and transforms them as CSS Custom Properties</p></figcaption></figure> | ||
|
|
||
| A parser does the following job: | ||
|
|
||
| 1. Receives design data as input | ||
| 2. Transforms this design data | ||
| 3. Returns the transformed data | ||
|
|
||
| The data returned by a parser can either be: | ||
|
|
||
| * Design data that can be used by another parser coming next in your transformation pipeline | ||
| * A file so it can be used by people, frameworks, or scripts | ||
|
|
||
| {% hint style="info" %} | ||
| Parsers are what make Specify powerful and flexible. They help you be in total control of the design data you pull from Specify. | ||
| {% endhint %} | ||
|
|
||
| Parsers are ordered and takes specific input to generate specific output. This way, we can easily test the input coming from the previous parser to check if the whole parsers process will work. | ||
|
|
||
| ## Categories | ||
|
|
||
| Parsers are classified in 2 categories: technology and utility. | ||
|
|
||
| ### Technology | ||
|
|
||
| Technology parsers help you transform your design tokens to specific technologies and formats (CSS Custom properties, SCSS, Tailwind, a Javascript theme object compatible with React Native...) | ||
|
|
||
| Some examples: | ||
|
|
||
| * [to-react-native](https://github.com/Specifyapp/parsers/tree/master/parsers/to-react-native) | ||
| * [to-css-custom-properties](https://github.com/Specifyapp/parsers/tree/master/parsers/to-css-custom-properties) | ||
| * [to-scss-variables](https://github.com/Specifyapp/parsers/tree/master/parsers/to-scss-variables) | ||
| * [to-tailwind](https://github.com/Specifyapp/parsers/tree/master/parsers/to-tailwind) | ||
|
|
||
| ### Utility | ||
|
|
||
| Utility parsers take care of "smaller" transformation. Like converting a pixel value to \`rem\` or transforming a string to kebabcase. | ||
|
|
||
| Some examples: | ||
|
|
||
| * [convert-font](https://github.com/Specifyapp/parsers/tree/master/parsers/convert-font) | ||
| * [kebabcasify](https://github.com/Specifyapp/parsers/tree/master/parsers/kebabcasify) | ||
| * [px-to-rem](https://github.com/Specifyapp/parsers/tree/master/parsers/px-to-rem) | ||
|
|
||
| ## All parsers available | ||
|
|
||
| All parsers are open source and available on [the following GitHub repository](https://github.com/Specifyapp/parsers). | ||
|
|
||
| `; | ||
|
|
||
| const markdownHeader = `| Parser | Description | Usage Example | | ||
| |---|---|---|`; | ||
|
|
||
| const parsersMarkdown = parsers.reduce((acc, currentParser) => { | ||
| const { title, description, exampleLink, parserLink } = currentParser; | ||
| if (!acc) { | ||
| return `${markdownHeader} | ||
| | [${title}](${parserLink}) | ${description} | [Example](${exampleLink}) |`; | ||
| } | ||
| return `${acc} | ||
| | [${title}](${parserLink}) | ${description} | [Example](${exampleLink}) |`; | ||
| }, ''); | ||
|
|
||
| const summaryFilePath = path.join(__dirname, '../output/', 'parsers.md'); | ||
| fs.writeFileSync(summaryFilePath, markdownFullPage + parsersMarkdown, { | ||
| encoding: 'utf8', | ||
| flag: 'w', | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.