Skip to content

Commit

Permalink
🐛 bug: data is null will work (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 authored Apr 8, 2020
1 parent 9b9c5c7 commit 4bc468c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ export interface MenuDataItem {
[key: string]: any;
}
function toHump(name: string) {
return name.replace(/\-(\w)/g, function (all, letter) {
return name.replace(/\-(\w)/g, function(all, letter) {
return letter.toUpperCase();
});
}

function formatter(data: MenuDataItem[]): MenuDataItem[] {
data.forEach((item = { path: '/' }) => {
if (Array.isArray(data)) {
return data;
}
(data || []).forEach((item = { path: '/' }) => {
if (item.icon) {
const { icon } = item;
const v4IconName = toHump(icon.replace(icon[0], icon[0].toUpperCase()));
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ export interface MenuDataItem {
}

function toHump(name: string) {
return name.replace(/\-(\w)/g, function (all, letter) {
return name.replace(/\-(\w)/g, function(all, letter) {
return letter.toUpperCase();
});
}

function formatter(data: MenuDataItem[]): MenuDataItem[] {
if (Array.isArray(data)) {
return [];
}
let icons = [];
data.forEach((item = { path: '/' }) => {
(data || []).forEach((item = { path: '/' }) => {
if (item.icon) {
const { icon } = item;
const v4IconName = toHump(icon.replace(icon[0], icon[0].toUpperCase()));
Expand All @@ -41,12 +44,12 @@ function formatter(data: MenuDataItem[]): MenuDataItem[] {
return Array.from(new Set(icons));
}

export default function (api: IApi) {
export default function(api: IApi) {
api.onGenerateFiles(() => {
const { userConfig } = api;
const icons = formatter(userConfig.routes);
let iconsString = icons.map(
(iconName) => `import ${iconName} from '@ant-design/icons/${iconName}'`,
iconName => `import ${iconName} from '@ant-design/icons/${iconName}'`,
);
api.writeTmpFile({
path: './plugin-antd-icon/icons.ts',
Expand Down

0 comments on commit 4bc468c

Please sign in to comment.