@figma-export/output-components-as-svgr
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -8,2 +8,3 @@ import * as FigmaExport from '@figma-export/types'; | ||
getFileExtension?: (options: FigmaExport.ComponentOutputterParamOption) => string; | ||
getExportTemplate?: (options: FigmaExport.ComponentOutputterParamOption) => string; | ||
/** | ||
@@ -15,4 +16,4 @@ * SVGR ships with a handful of customizable options, usable in both the CLI and API. | ||
}; | ||
declare const _default: ({ output, getDirname, getComponentName, getFileExtension, getSvgrConfig, }: Options) => FigmaExport.ComponentOutputter; | ||
declare const _default: ({ output, getDirname, getComponentName, getFileExtension, getSvgrConfig, getExportTemplate, }: Options) => FigmaExport.ComponentOutputter; | ||
export = _default; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,5 +15,9 @@ "use strict"; | ||
const path = require("path"); | ||
module.exports = ({ output, getDirname = (options) => `${options.pageName}${path.sep}${options.dirname}`, getComponentName = (options) => `${(0, utils_1.pascalCase)(options.basename)}`, getFileExtension = () => '.jsx', getSvgrConfig = () => ({}), }) => { | ||
module.exports = ({ output, getDirname = (options) => `${options.pageName}${path.sep}${options.dirname}`, getComponentName = (options) => `${(0, utils_1.pascalCase)(options.basename)}`, getFileExtension = () => '.jsx', getSvgrConfig = () => ({}), getExportTemplate = (options) => { | ||
const reactComponentName = getComponentName(options); | ||
const reactComponentFilename = `${reactComponentName}${getFileExtension(options)}`; | ||
return `export { default as ${reactComponentName} } from './${reactComponentFilename}';`; | ||
}, }) => { | ||
fs.mkdirSync(output, { recursive: true }); | ||
const indexJs = {}; | ||
const indexFile = {}; | ||
return (pages) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -25,14 +29,17 @@ pages.forEach(({ name: pageName, components }) => { | ||
const reactComponentName = getComponentName(options); | ||
const basename = `${reactComponentName}${getFileExtension(options)}`; | ||
const reactComponentFilename = `${reactComponentName}${getFileExtension(options)}`; | ||
const filePath = path.resolve(output, getDirname(options)); | ||
fs.mkdirSync(filePath, { recursive: true }); | ||
indexJs[filePath] = indexJs[filePath] || []; | ||
indexJs[filePath].push(`export { default as ${reactComponentName} } from './${basename}';`); | ||
indexFile[filePath] = indexFile[filePath] || { | ||
ext: getFileExtension(options) === '.tsx' ? '.ts' : '.js', | ||
exports: [], | ||
}; | ||
indexFile[filePath].exports.push(getExportTemplate(options)); | ||
const svgrConfig = getSvgrConfig(options); | ||
const svgrState = { componentName: reactComponentName }; | ||
const jsCode = core_1.transform.sync(svg, svgrConfig, svgrState); | ||
fs.writeFileSync(path.resolve(filePath, basename), jsCode); | ||
fs.writeFileSync(path.resolve(filePath, reactComponentFilename), jsCode); | ||
}); | ||
Object.entries(indexJs).forEach(([filePath, exports]) => { | ||
fs.writeFileSync(path.resolve(filePath, 'index.js'), exports.join('\n')); | ||
Object.entries(indexFile).forEach(([filePath, index]) => { | ||
fs.writeFileSync(path.resolve(filePath, `index${index.ext}`), index.exports.join('\n')); | ||
}); | ||
@@ -39,0 +46,0 @@ }); |
{ | ||
"name": "@figma-export/output-components-as-svgr", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Outputter for @figma-export that exports components as React components using svgr", | ||
@@ -28,3 +28,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@figma-export/types": "^4.0.1", | ||
"@figma-export/types": "^4.2.0", | ||
"@figma-export/utils": "^4.0.0", | ||
@@ -36,3 +36,3 @@ "@svgr/core": "~6.2.1" | ||
}, | ||
"gitHead": "94f98dae88c77176e5e2b560f6bbb22caede3c4d" | ||
"gitHead": "b0502c1ceedab1c44d262cc7ff028f8057e742ce" | ||
} |
@@ -54,3 +54,3 @@ # @figma-export/output-components-as-svgr | ||
`getDirname`, `getComponentName`, `getFileExtension` and `getSvgrConfig` are **optional**. | ||
`getDirname`, `getComponentName`, `getFileExtension`, `getExportTemplate` and `getSvgrConfig` are **optional**. | ||
@@ -69,2 +69,7 @@ ```js | ||
getSvgrConfig: (options) => ({}), | ||
getExportTemplate = (options): string => { | ||
const reactComponentName = getComponentName(options); | ||
const reactComponentFilename = `${reactComponentName}${getFileExtension(options)}`; | ||
return `export { default as ${reactComponentName} } from './${reactComponentFilename}';`; | ||
}, | ||
}) | ||
@@ -71,0 +76,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11422
62
93
Updated@figma-export/types@^4.2.0