-
Notifications
You must be signed in to change notification settings - Fork 368
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
1 parent
fc82476
commit 33304e5
Showing
5 changed files
with
927 additions
and
1,066 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,48 @@ | ||
name: Get Figma Images | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: | ||
- labeled | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
findNodeReferences: | ||
if: ${{ github.event.label.name == 'update figma images' || github.event_name == 'push' }} | ||
runs-on: ubuntu-latest | ||
env: | ||
FilesToScan: '**/*.mdx' | ||
ImageUrlFile: figmaImageNodeUrls.json | ||
ImageOutputDir: content/images/figma | ||
FigmaToken: ${{ secrets.FIGMA_TOKEN }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: Install dependencies | ||
run: yarn | ||
- name: Get Figma Images | ||
run: node scripts/getFigmaImages.js "${{env.FilesToScan}}" > ${{env.ImageUrlFile}} | ||
- name: Log file content | ||
run: cat ${{env.ImageUrlFile}} | ||
- name: Download images from figma | ||
run: npx @primer/figma-images --figmaToken ${{env.FigmaToken}} --nodeURLsFile ${{env.ImageUrlFile}} --outputDir ${{env.ImageOutputDir}} | ||
- name: Log output dir content | ||
run: ls ${{env.ImageOutputDir}} | ||
- uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: github-actions[bot] Update figma images | ||
- uses: actions-ecosystem/action-remove-labels@v1 | ||
if: always() | ||
with: | ||
labels: 'update figma images' |
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,42 @@ | ||
// Import necessary modules | ||
const fs = require('fs').promises; | ||
const fastGlob = require('fast-glob'); | ||
|
||
const isFigmaLink = (match) => { | ||
return match.startsWith('https://www.figma.com/design/') | ||
} | ||
|
||
const findMatches = async (regexPattern, files) => { | ||
const matches = await Promise.all( | ||
files.map(async (filePath) => { | ||
// read file content | ||
const content = await fs.readFile(filePath, { encoding: 'utf8' }) | ||
// try to find all matches in the file content | ||
const matches = [...content.matchAll(regexPattern)] | ||
// for each match, return the first group | ||
return matches.map((match) => match[1]).filter(isFigmaLink); | ||
}) | ||
) | ||
// | ||
return matches.flat() | ||
} | ||
|
||
const run = async () => { | ||
// get arguments | ||
const [fileGlob] = process.argv.slice(2) | ||
if(!fileGlob) { | ||
console.error('❌ Please provide a file glob as the argument. It needs to be wrapped in quotes.') | ||
return | ||
} | ||
// get all files that match the file glob | ||
const files = await fastGlob([fileGlob]) | ||
// define the regex pattern to search | ||
const pattern = /<FigmaImage\s+[^>]*src="([^"]+)"[^>]*>/g | ||
// find matches in find | ||
const matches = await findMatches(pattern, files) | ||
// output result | ||
console.log(JSON.stringify(matches, null, 2)) | ||
|
||
} | ||
|
||
run() |
Oops, something went wrong.