1- import { readFile , writeFile } from 'node:fs/promises'
2- import path from 'node:path'
3- import process from 'node:process'
4- import { findWorkspaceDir } from '@pnpm/find-workspace-dir'
5- import { findWorkspacePackages } from '@pnpm/find-workspace-packages'
1+ import { mkdir , readFile , rm , writeFile } from 'node:fs/promises'
2+ import { basename , resolve } from 'node:path'
3+ import { fileURLToPath } from 'node:url'
64import camelcase from 'camelcase'
7- import chalk from 'chalk'
85import consola from 'consola'
9- import glob from 'fast-glob'
10- import { emptyDir , ensureDir } from 'fs-extra'
116import { format , type BuiltInParserName } from 'prettier'
12- import { pathComponents } from './paths '
7+ import { glob } from 'tinyglobby '
138
14- consola . info ( chalk . blue ( 'generating vue components' ) )
15- await ensureDir ( pathComponents )
16- await emptyDir ( pathComponents )
9+ consola . info ( 'generating vue components' )
10+ const pathComponents = resolve ( import . meta. dirname , '../src/components' )
11+ await rm ( pathComponents , { recursive : true , force : true } )
12+ await mkdir ( pathComponents , { recursive : true } )
1713const files = await getSvgFiles ( )
1814
19- consola . info ( chalk . blue ( 'generating vue files' ) )
15+ consola . info ( 'generating vue files' )
2016await Promise . all ( files . map ( ( file ) => transformToVueComponent ( file ) ) )
2117
22- consola . info ( chalk . blue ( 'generating entry file' ) )
18+ consola . info ( 'generating entry file' )
2319await generateEntry ( files )
2420
25- async function getSvgFiles ( ) {
26- const pkgs = await findWorkspacePackages (
27- ( await findWorkspaceDir ( process . cwd ( ) ) ) ! ,
21+ function getSvgFiles ( ) {
22+ const svgPackageJson = fileURLToPath (
23+ import . meta . resolve ( '@element-plus/icons-svg/package.json' ) ,
2824 )
29- const pkg = pkgs . find (
30- ( pkg ) => pkg . manifest . name === '@element-plus/icons-svg' ,
31- ) !
32- return glob ( '*.svg' , { cwd : pkg . dir , absolute : true } )
25+ return glob ( '*.svg' , {
26+ cwd : resolve ( svgPackageJson , '..' ) ,
27+ absolute : true ,
28+ } )
3329}
3430
3531function getName ( file : string ) {
36- const filename = path . basename ( file ) . replace ( '.svg' , '' )
32+ const filename = basename ( file ) . replace ( '.svg' , '' )
3733 const componentName = camelcase ( filename , { pascalCase : true } )
3834 return {
3935 filename,
@@ -64,7 +60,7 @@ defineOptions({
6460</script>` ,
6561 'vue' ,
6662 )
67- writeFile ( path . resolve ( pathComponents , `${ filename } .vue` ) , vue , 'utf8' )
63+ writeFile ( resolve ( pathComponents , `${ filename } .vue` ) , vue , 'utf8' )
6864}
6965
7066async function generateEntry ( files : string [ ] ) {
@@ -76,5 +72,5 @@ async function generateEntry(files: string[]) {
7672 } )
7773 . join ( '\n' ) ,
7874 )
79- await writeFile ( path . resolve ( pathComponents , 'index.ts' ) , code , 'utf8' )
75+ await writeFile ( resolve ( pathComponents , 'index.ts' ) , code , 'utf8' )
8076}
0 commit comments