-
Notifications
You must be signed in to change notification settings - Fork 2
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
6 changed files
with
119 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const axios = require('axios'); | ||
|
||
module.exports = async (config) => { | ||
try { | ||
|
||
const { | ||
token, | ||
file | ||
} = config; | ||
|
||
const requestHeaders = { | ||
'X-Figma-Token': token | ||
}; | ||
|
||
const requestConfig = { | ||
method: 'GET', | ||
headers: requestHeaders, | ||
url: file | ||
}; | ||
|
||
const figmaJson = await axios.request(requestConfig); | ||
|
||
return figmaJson.data; | ||
|
||
} catch (e) { | ||
throw new Error('figmaApi.js: ' + e.message); | ||
} | ||
} |
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,51 @@ | ||
const shell = require('shelljs'); | ||
// const fs = require('fs'); | ||
const figmaApi = require('./figmaApi'); | ||
const getFigmaFrames = require('./figmaFrames'); | ||
|
||
require('dotenv').config(); | ||
|
||
// general configuration | ||
// const config = { | ||
// destinationFileName: './figma_extractor/figma.json' | ||
// }; | ||
|
||
(async () => { | ||
|
||
try { | ||
|
||
const apiConfig = { | ||
token: process.env.FIGMA_ACCESS_TOKEN, | ||
file: process.env.FIGMA_FILE_URL | ||
}; | ||
|
||
const figmaData = await figmaApi(apiConfig); | ||
const figmaFrames = getFigmaFrames(figmaData); | ||
|
||
console.log(figmaFrames); | ||
// const figmaJson = await getFigmaJSON(); | ||
|
||
// const figmaStyles = getFigmaStyles(figmaJson); | ||
// const fillStyleOfWhiteBox = figmaFrames[0].children[1].styles.fill; | ||
// console.log(getFigmaStyleNameForId(fillStyleOfWhiteBox, figmaStyles)); | ||
|
||
// console.log(figmaFrames[0].children[1].fills[0]); | ||
|
||
/* | ||
// write .json file | ||
fs.mkdirSync(deploymentsDir); | ||
fs.writeFileSync(`./${deploymentsDir}/${config.deploymentsJsonName}`, JSON.stringify(json)); | ||
// write index file | ||
fs.writeFileSync(`./${deploymentsDir}/index.html`, '<html><body><p>This space is empty. It is only serving deployments.json for lyne-design-system. <a href="/deployments.json">deployments.json</a></p></body></html>'); | ||
console.log(`-->> NETLIFY DEPLOYMENTS: Successfully created ${config.deploymentsJsonName}`); | ||
shell.exit(0); | ||
*/ | ||
} catch (error) { | ||
console.log(error); | ||
shell.exit(0); | ||
} | ||
})(); |
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,39 @@ | ||
// Get frames from 1st page of the Figma file | ||
module.exports = (figmaData) => { | ||
|
||
// make sure that file is not empty | ||
const figmaDocument = figmaData.document; | ||
|
||
if (!figmaDocument) { | ||
throw new Error('ERROR: Figma file seems to be empty'); | ||
} | ||
|
||
// make sure that file has pages | ||
const figmaPages = figmaDocument.children; | ||
|
||
if (!figmaPages || figmaPages.length < 1) { | ||
throw new Error('ERROR: Figma file seems not to have any pages'); | ||
} | ||
|
||
// get the first page. By convention, we put all definitions on | ||
// the first page | ||
const figmaPage = figmaPages[0]; | ||
|
||
// make sure that 1st page has regions | ||
let figmaChildren = figmaPage.children; | ||
|
||
if (!figmaChildren || figmaChildren.length < 1) { | ||
throw new Error('ERROR: 1st page of the Figma file does not have any children'); | ||
} | ||
|
||
const figmaFrames = figmaChildren.filter((frame) => { | ||
return frame.type === 'FRAME'; | ||
}); | ||
|
||
if (figmaFrames.length < 1) { | ||
throw new Error('ERROR: 1st page of the Figma file does not have any frames'); | ||
} | ||
|
||
return figmaFrames; | ||
|
||
} |
Empty file.
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