Skip to content

Commit

Permalink
fix: dts
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 27, 2023
1 parent 532db02 commit dea5d0b
Show file tree
Hide file tree
Showing 6 changed files with 1,374 additions and 1,040 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@element-plus/icons-monorepo",
"version": "2.2.0",
"private": true,
"packageManager": "pnpm@8.6.2",
"packageManager": "pnpm@8.11.0",
"type": "module",
"license": "MIT",
"scripts": {
Expand All @@ -14,10 +14,10 @@
"release": "bumpp -r"
},
"devDependencies": {
"@sxzz/eslint-config": "^3.0.0",
"bumpp": "^9.1.1",
"eslint": "^8.43.0",
"prettier": "^2.8.8",
"typescript": "^5.1.3"
"@sxzz/eslint-config": "^3.7.5",
"bumpp": "^9.2.0",
"eslint": "^8.54.0",
"prettier": "^3.1.0",
"typescript": "^5.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/svg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"optimize": "svgo -f . -o ."
},
"devDependencies": {
"svgo": "^3.0.2"
"svgo": "^3.0.4"
}
}
47 changes: 24 additions & 23 deletions packages/vue/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ import { findWorkspaceDir } from '@pnpm/find-workspace-dir'
import { findWorkspacePackages } from '@pnpm/find-workspace-packages'
import { pathComponents } from './paths'

const getSvgFiles = async () => {
consola.info(chalk.blue('generating vue components'))
await ensureDir(pathComponents)
await emptyDir(pathComponents)
const files = await getSvgFiles()

consola.info(chalk.blue('generating vue files'))
await Promise.all(files.map((file) => transformToVueComponent(file)))

consola.info(chalk.blue('generating entry file'))
await generateEntry(files)

async function getSvgFiles() {
const pkgs = await findWorkspacePackages(
(await findWorkspaceDir(process.cwd()))!
(await findWorkspaceDir(process.cwd()))!,
)
const pkg = pkgs.find(
(pkg) => pkg.manifest.name === '@element-plus/icons-svg'
(pkg) => pkg.manifest.name === '@element-plus/icons-svg',
)!
return glob('*.svg', { cwd: pkg.dir, absolute: true })
}

const getName = (file: string) => {
function getName(file: string) {
const filename = path.basename(file).replace('.svg', '')
const componentName = camelcase(filename, { pascalCase: true })
return {
Expand All @@ -29,17 +40,18 @@ const getName = (file: string) => {
}
}

const formatCode = (code: string, parser: BuiltInParserName = 'typescript') =>
format(code, {
function formatCode(code: string, parser: BuiltInParserName = 'typescript') {
return format(code, {
parser,
semi: false,
singleQuote: true,
})
}

const transformToVueComponent = async (file: string) => {
async function transformToVueComponent(file: string) {
const content = await readFile(file, 'utf-8')
const { filename, componentName } = getName(file)
const vue = formatCode(
const vue = await formatCode(
`
<template>
${content}
Expand All @@ -50,30 +62,19 @@ export default ({
name: "${componentName}",
}) as DefineComponent
</script>`,
'vue'
'vue',
)
writeFile(path.resolve(pathComponents, `${filename}.vue`), vue, 'utf-8')
}

const generateEntry = async (files: string[]) => {
const code = formatCode(
async function generateEntry(files: string[]) {
const code = await formatCode(
files
.map((file) => {
const { filename, componentName } = getName(file)
return `export { default as ${componentName} } from './${filename}.vue'`
})
.join('\n')
.join('\n'),
)
await writeFile(path.resolve(pathComponents, 'index.ts'), code, 'utf-8')
}

consola.info(chalk.blue('generating vue components'))
await ensureDir(pathComponents)
await emptyDir(pathComponents)
const files = await getSvgFiles()

consola.info(chalk.blue('generating vue files'))
await Promise.all(files.map((file) => transformToVueComponent(file)))

consola.info(chalk.blue('generating entry file'))
await generateEntry(files)
28 changes: 14 additions & 14 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@
"@pnpm/find-workspace-dir": "^6.0.2",
"@pnpm/find-workspace-packages": "^6.0.9",
"@pnpm/logger": "^5.0.0",
"@types/fs-extra": "^11.0.1",
"@types/node": "^20.3.1",
"@types/prettier": "^2.7.3",
"camelcase": "^7.0.1",
"chalk": "^5.2.0",
"consola": "^3.1.0",
"esbuild": "^0.18.4",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.10.0",
"@types/prettier": "^3.0.0",
"camelcase": "^8.0.0",
"chalk": "^5.3.0",
"consola": "^3.2.3",
"esbuild": "^0.19.8",
"esbuild-plugin-globals": "^0.2.0",
"fast-glob": "^3.2.12",
"fast-glob": "^3.3.2",
"fs-extra": "^11.1.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"tsx": "^3.12.7",
"typescript": "^5.1.3",
"unplugin-vue": "^4.2.1",
"vue": "^3.3.4",
"vue-tsc": "^1.8.0"
"prettier": "^3.1.0",
"tsx": "^4.5.0",
"typescript": "^5.3.2",
"unplugin-vue": "^4.5.0",
"vue": "^3.3.9",
"vue-tsc": "^1.8.22"
}
}
8 changes: 4 additions & 4 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"dependencies": {
"@element-plus/icons-svg": "workspace:*",
"@element-plus/icons-vue": "workspace:*",
"vue": "^3.3.4"
"vue": "^3.3.9"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.1.3",
"vite": "^4.3.9"
"@vitejs/plugin-vue": "^4.5.0",
"typescript": "^5.3.2",
"vite": "^5.0.2"
}
}
Loading

0 comments on commit dea5d0b

Please sign in to comment.