-
Notifications
You must be signed in to change notification settings - Fork 720
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
1 parent
aa5deb1
commit 1098790
Showing
12 changed files
with
2,431 additions
and
3 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
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
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,78 @@ | ||
import path from 'path' | ||
import fs from 'fs-extra' | ||
import inquirer from 'inquirer' | ||
import chalk from 'chalk' | ||
import pkg from '../package.json' | ||
|
||
interface Icon { | ||
name: string | ||
prefix: string | ||
icons: string[] | ||
} | ||
|
||
async function generateIcon() { | ||
const dir = path.resolve(process.cwd(), 'node_modules/@iconify/json') | ||
|
||
const raw = await fs.readJSON(path.join(dir, 'collections.json')) | ||
|
||
const collections = Object.entries(raw).map(([id, v]) => ({ | ||
...(v as any), | ||
id | ||
})) | ||
|
||
const choices = collections.map((item) => ({ key: item.id, value: item.id, name: item.name })) | ||
|
||
inquirer | ||
.prompt([ | ||
// { | ||
// type: 'list', | ||
// name: 'useType', | ||
// choices: [ | ||
// { key: 'local', value: 'local', name: 'Local' }, | ||
// { key: 'onLine', value: 'onLine', name: 'OnLine' }, | ||
// ], | ||
// message: 'How to use icons?', | ||
// }, | ||
{ | ||
type: 'list', | ||
name: 'iconSet', | ||
choices: choices, | ||
message: 'Select the icon set that needs to be generated?' | ||
} | ||
// { | ||
// type: 'input', | ||
// name: 'output', | ||
// message: 'Select the icon set that needs to be generated?', | ||
// default: 'src/components/Icon/data', | ||
// }, | ||
]) | ||
// ↓命令行问答的答案 | ||
.then(async (answers) => { | ||
const { iconSet } = answers | ||
const outputDir = path.resolve(process.cwd(), 'src/components/IconPicker/src/data') | ||
fs.ensureDir(outputDir) | ||
const genCollections = collections.filter((item) => [iconSet].includes(item.id)) | ||
const prefixSet: string[] = [] | ||
for (const info of genCollections) { | ||
const data = await fs.readJSON(path.join(dir, 'json', `${info.id}.json`)) | ||
if (data) { | ||
const { prefix } = data | ||
const icons = Object.keys(data.icons).map((item) => `${prefix}:${item}`) | ||
|
||
await fs.writeFileSync( | ||
path.join('src/components/IconPicker/src/data', `icons.${prefix}.ts`), | ||
`export default ${JSON.stringify({ name: info.name, prefix, icons })}` | ||
) | ||
// ↓分类处理完成,push类型名称 | ||
prefixSet.push(prefix) | ||
} | ||
} | ||
// 将vite的缓存清空 | ||
// fs.emptyDir(path.join(process.cwd(), 'node_modules/.vite')) | ||
console.log( | ||
`✨ ${chalk.cyan(`[${pkg.name}]`)}` + ' - Icon generated successfully:' + `[${prefixSet}]` | ||
) | ||
}) | ||
} | ||
|
||
generateIcon() |
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,3 @@ | ||
import IconPicker from './src/IconPicker.vue' | ||
|
||
export { IconPicker } |
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,11 @@ | ||
<script setup lang="ts"> | ||
import epIcons from './data/icons.ep' | ||
import antIcons from './data/icons.ant-design' | ||
import tIcons from './data/icons.tdesign' | ||
console.log(epIcons, antIcons, tIcons) | ||
</script> | ||
|
||
<template> | ||
<div> 2222 </div> | ||
</template> |
Oops, something went wrong.