Skip to content

Commit

Permalink
feat: add replaceExports function
Browse files Browse the repository at this point in the history
  • Loading branch information
洛竹 authored and fwh1990 committed Aug 18, 2021
1 parent d5d3e60 commit d539545
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libs/generateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
replaceCases,
replaceComponentName,
replaceImports,
replaceExports,
replaceNames,
replaceNamesArray,
replaceSingleIconContent,
Expand Down Expand Up @@ -150,6 +151,7 @@ export const generateComponent = (data: XmlData, localSvg: ILocalSvg[], config:
iconFile = replaceCases(iconFile, cases);
iconFile = replaceSvgComponents(iconFile, svgComponents);
iconFile = replaceImports(iconFile, imports);
iconFile = replaceExports(iconFile, imports);

if (config.use_typescript) {
iconFile = replaceNames(iconFile, names);
Expand All @@ -158,6 +160,7 @@ export const generateComponent = (data: XmlData, localSvg: ILocalSvg[], config:

let typeDefinitionFile = getTemplate('Icon.d.ts');

typeDefinitionFile = replaceExports(typeDefinitionFile, imports);
typeDefinitionFile = replaceNames(typeDefinitionFile, names);
fs.writeFileSync(path.join(saveDir, 'index.d.ts'), typeDefinitionFile);
}
Expand Down
5 changes: 5 additions & 0 deletions src/libs/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const replaceImports = (content: string, imports: string[]) => {
return content.replace(/#imports#/g, imports.map((item) => `import ${item} from './${item}';`).join('\n'));
};

export const replaceExports = (content: string, exports: string[]) => {
return content.replace(/#exports#/g, exports.map((item) => `export { default as ${item} } from './${item}';`).join('\n'));
};


export const replaceHelper = (content: string) => {
return content.replace(
/#helper#/g,
Expand Down
2 changes: 2 additions & 0 deletions src/templates/Icon.d.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FunctionComponent } from 'react';
import { ViewProps } from 'react-native';
import { GProps } from 'react-native-svg';

#exports#

interface Props extends GProps, ViewProps {
name: '#names#';
size?: number;
Expand Down
1 change: 1 addition & 0 deletions src/templates/Icon.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
#svgComponents#
#imports#
#exports#

let IconFont = ({ name, ...rest }) => {
switch (name) {
Expand Down
1 change: 1 addition & 0 deletions src/templates/Icon.tsx.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { FunctionComponent } from 'react';
import { ViewProps } from 'react-native';
#svgComponents#
#imports#
#exports#

export type IconNames = '#names#';

Expand Down

0 comments on commit d539545

Please sign in to comment.