Skip to content
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

chore(build): add ts definition file by icon #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ fs.writeFileSync(path.join(rootDir, 'src', 'index.js'), '', 'utf-8');
fs.writeFileSync(
path.join(rootDir, 'src', 'index.d.ts'),
initialTypeDefinitions,
'utf-8',
'utf-8'
);

const attrsToString = (attrs) => {
return Object.keys(attrs).map((key) => {
if (key === 'width' || key === 'height' || key === 'stroke') {
return key + '={' + attrs[key] + '}';
}
if (key === 'rest') {
return '{...rest}';
}
return key + '="' + attrs[key] + '"';
}).join(' ');
const attrsToString = attrs => {
return Object.keys(attrs)
.map(key => {
if (key === 'width' || key === 'height' || key === 'stroke') {
return key + '={' + attrs[key] + '}';
}
if (key === 'rest') {
return '{...rest}';
}
return key + '="' + attrs[key] + '"';
})
.join(' ');
};

icons.forEach((i) => {
const location = path.join(rootDir, 'src/icons', `${i}.js`);
const ComponentName = (i === 'github') ? 'GitHub' : upperCamelCase(i);
icons.forEach(icon => {
const location = path.join(rootDir, 'src/icons', `${icon}.js`);
const ComponentName = icon === 'github' ? 'GitHub' : upperCamelCase(icon);
const defaultAttrs = {
xmlns: 'http://www.w3.org/2000/svg',
width: 'size',
Expand All @@ -69,7 +71,7 @@ icons.forEach((i) => {
const ${ComponentName} = forwardRef(({ color = 'currentColor', size = 24, ...rest }, ref) => {
return (
<svg ref={ref} ${attrsToString(defaultAttrs)}>
${featherIcons[i]}
${featherIcons[icon]}
</svg>
)
});
Expand Down Expand Up @@ -103,17 +105,29 @@ icons.forEach((i) => {

console.log('Successfully built', ComponentName);

const exportString = `export { default as ${ComponentName} } from './icons/${i}';\r\n`;
const exportString = `export { default as ${ComponentName} } from './icons/${icon}';\r\n`;
fs.appendFileSync(
path.join(rootDir, 'src', 'index.js'),
exportString,
'utf-8',
'utf-8'
);

const exportTypeString = `export const ${ComponentName}: Icon;\n`;
fs.appendFileSync(
path.join(rootDir, 'src', 'index.d.ts'),
exportTypeString,
'utf-8',
'utf-8'
);

const iconTypeDefinition = `import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
`;
fs.writeFileSync(
path.join(rootDir, 'src/icons', `${icon}.d.ts`),
iconTypeDefinition,
'utf-8'
);
});
5 changes: 5 additions & 0 deletions src/icons/activity.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/airplay.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/alert-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/alert-octagon.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/alert-triangle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/align-center.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/align-justify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/align-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/align-right.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/anchor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/aperture.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/archive.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-down-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-down-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-down-right.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-down.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-left-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-right-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-right.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-up-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-up-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-up-right.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/arrow-up.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/at-sign.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/award.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bar-chart-2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bar-chart.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/battery-charging.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/battery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bell-off.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bell.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bluetooth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bold.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/book-open.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/book.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/bookmark.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/box.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/briefcase.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/calendar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/camera-off.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/camera.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/cast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/check-circle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/check-square.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/check.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevron-down.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevron-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevron-right.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevron-up.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevrons-down.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
5 changes: 5 additions & 0 deletions src/icons/chevrons-left.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Icon as IconType } from '../';

declare const Icon: IconType

export default Icon;
Loading