diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 952a0dc8..037c66b3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -4,13 +4,11 @@ module.exports = { 'airbnb', 'airbnb-typescript', 'plugin:tailwindcss/recommended', - 'plugin:prettier/recommended', 'plugin:import/recommended', 'prettier', ], parser: '@typescript-eslint/parser', rules: { - 'prettier/prettier': 'error', 'import/extensions': 'off', 'react/jsx-props-no-spreading': 'off', 'react/react-in-jsx-scope': 'off', diff --git a/packages/icons/package.json b/packages/icons/package.json index a2bc9b7a..5b496de7 100644 --- a/packages/icons/package.json +++ b/packages/icons/package.json @@ -12,15 +12,15 @@ "lint": "eslint .", "lint-staged": "lint-staged", "build": "pnpm renew && tsup", - "generate": "pnpm svgo:emoji && pnpm svgo:outline && pnpm svgo:solid && pnpm svgr:emoji && pnpm svgr:outline && pnpm svgr:solid && pnpm generate", + "generate": "pnpm svgo:emoji && pnpm svgo:outline && pnpm svgo:solid && pnpm svgr:emoji && pnpm svgr:outline && pnpm svgr:solid && pnpm export", "renew": "pnpm svgo:emoji && pnpm svgo:outline && pnpm svgo:solid && pnpm update:emoji && pnpm update:outline && pnpm update:solid && pnpm export", - "export": "ts-node ./scripts/generateExports.ts && eslint --fix .", + "export": "tsx ./scripts/generateExports.ts && prettier --write . --ignore-unknown", "svgo:emoji": "svgo -f ./src/emoji/svg --config=svgo.emoji.mjs", "svgo:outline": "svgo -f ./src/outline/svg --config=svgo.outline.mjs", "svgo:solid": "svgo -f ./src/solid/svg --config=svgo.solid.mjs", - "svgr:emoji": "svgr --no-index --template ./svgr-template.js --no-prettier --icon --typescript --out-dir src/emoji/react src/emoji/svg", - "svgr:outline": "svgr --no-index --template ./svgr-template.js --no-prettier --icon --typescript --out-dir src/outline/react src/outline/svg", - "svgr:solid": "svgr --no-index --template ./svgr-template.js --no-prettier --icon --typescript --out-dir src/solid/react src/solid/svg", + "svgr:emoji": "svgr --no-index --template svgr-template.cjs --no-prettier --icon --typescript --out-dir src/emoji/react src/emoji/svg", + "svgr:outline": "svgr --no-index --template svgr-template.cjs --no-prettier --icon --typescript --out-dir src/outline/react src/outline/svg", + "svgr:solid": "svgr --no-index --template svgr-template.cjs --no-prettier --icon --typescript --out-dir src/solid/react src/solid/svg", "update:emoji": "pnpm svgr:emoji --ignore-existing", "update:outline": "pnpm svgr:outline --ignore-existing", "update:solid": "pnpm svgr:solid --ignore-existing" @@ -31,7 +31,8 @@ "devDependencies": { "@attraction/config": "workspace:^", "@svgr/cli": "^8.1.0", - "svgo": "^3.3.2" + "svgo": "^3.3.2", + "tsx": "^4.16.2" }, "peerDependencies": { "react": "^18.2.0", diff --git a/packages/icons/scripts/generateExports.ts b/packages/icons/scripts/generateExports.ts index 38144277..1db8efa4 100644 --- a/packages/icons/scripts/generateExports.ts +++ b/packages/icons/scripts/generateExports.ts @@ -1,8 +1,13 @@ /* eslint-disable @typescript-eslint/no-shadow */ /* eslint-disable no-console */ -const fs = require('fs') -const path = require('path') +import { promises as fs } from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' + +// __dirname 을 ESM 에서 사용할 수 있도록 변환 +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) // 관리할 디렉토리 const directories = [ @@ -13,32 +18,24 @@ const directories = [ const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1) -directories.forEach(({ dir, subDir }) => { - const directoryPath = path.join(__dirname, '..', 'src', dir, subDir) - const outputPath = path.join(__dirname, '..', 'src', dir, 'index.ts') - - fs.readdir(directoryPath, (err: NodeJS.ErrnoException, files: string[]) => { - if (err) { - console.error('Error reading directory', err) +directories.forEach(async ({ dir, subDir }) => { + const directoryPath = path.join(dirname, '..', 'src', dir, subDir) + const outputPath = path.join(dirname, '..', 'src', dir, 'index.ts') - return - } + try { + const files = await fs.readdir(directoryPath) const exportStatements = files .filter((file) => file.endsWith('.tsx')) .map((file) => { const componentName = file.replace('.tsx', '') - return `export { default as ${componentName}${capitalize(dir)} } from './${subDir}/${componentName}';\n` }) .join('') - fs.writeFile(outputPath, exportStatements, (err: NodeJS.ErrnoException) => { - if (err) { - console.error('Error writing to file', err) - return - } - console.log(`Exports generated successfully for ${dir}.`) - }) - }) + await fs.writeFile(outputPath, exportStatements) + console.log(`Exports generated successfully for ${dir}.`) + } catch (err) { + console.error('Error processing directory', err) + } }) diff --git a/packages/icons/svgr-template.js b/packages/icons/svgr-template.cjs similarity index 100% rename from packages/icons/svgr-template.js rename to packages/icons/svgr-template.cjs diff --git a/packages/icons/tsconfig.json b/packages/icons/tsconfig.json index a5117ab1..f0f63568 100644 --- a/packages/icons/tsconfig.json +++ b/packages/icons/tsconfig.json @@ -20,6 +20,6 @@ "@/*": ["./*"] } }, - "include": ["**/*.ts", "**/*.tsx", "tailwind.config.js", "svgr-template.js"], + "include": ["**/*.ts", "**/*.tsx", "tailwind.config.js", "svgr-template.cjs"], "exclude": ["node_modules"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a4fa185..2d37f430 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -307,6 +307,9 @@ importers: svgo: specifier: ^3.3.2 version: 3.3.2 + tsx: + specifier: ^4.16.2 + version: 4.16.2 packages: @@ -7347,6 +7350,11 @@ packages: peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' + tsx@4.16.2: + resolution: {integrity: sha512-C1uWweJDgdtX2x600HjaFaucXTilT7tgUZHbOE4+ypskZ1OP8CRCSDkCxG6Vya9EwaFIVagWwpaVAn5wzypaqQ==} + engines: {node: '>=18.0.0'} + hasBin: true + tween-functions@1.2.0: resolution: {integrity: sha512-PZBtLYcCLtEcjL14Fzb1gSxPBeL7nWvGhO5ZFPGqziCcr8uvHp0NDmdjBchp6KHL+tExcg0m3NISmKxhU394dA==} @@ -16369,6 +16377,13 @@ snapshots: tslib: 1.14.1 typescript: 5.4.5 + tsx@4.16.2: + dependencies: + esbuild: 0.21.5 + get-tsconfig: 4.7.5 + optionalDependencies: + fsevents: 2.3.3 + tween-functions@1.2.0: {} type-check@0.4.0: