This is an automated email from the ASF dual-hosted git repository. robin0716 pushed a commit to branch chore/update-plugin-script in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 9272e3544d208f4d22f052e0c45db57def8cf9e1 Author: robin <[email protected]> AuthorDate: Thu Jul 4 16:56:24 2024 +0800 feat: Update plugin.js to use humps for pascalizing package names --- ui/scripts/plugin.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ui/scripts/plugin.js b/ui/scripts/plugin.js index cdd84d17..a0d31e0c 100644 --- a/ui/scripts/plugin.js +++ b/ui/scripts/plugin.js @@ -19,15 +19,11 @@ const path = require('path'); const fs = require('fs'); +const humps = require('humps'); const pluginPath = path.join(__dirname, '../src/plugins'); const pluginFolders = fs.readdirSync(pluginPath); -function pascalize(str) { - return str.replace(/\b\w/g, (match) => match.toUpperCase()) - .replace(/[-_\s]+/g, ''); -} - function resetPackageJson() { const packageJsonPath = path.join(__dirname, '..', 'package.json'); const packageJsonContent = require(packageJsonPath); @@ -63,7 +59,7 @@ function addPluginToIndexTs(packageName) { const indexTsPath = path.join(pluginPath, 'index.ts'); const indexTsContent = fs.readFileSync(indexTsPath, 'utf-8'); const lines = indexTsContent.split('\n'); - const ComponentName = pascalize(packageName); + const ComponentName = humps.pascalize(packageName); const importLine = `export { default as ${ComponentName} } from '${packageName}';`; if (!lines.includes(importLine)) { lines.push(importLine); @@ -94,7 +90,6 @@ pluginFolders.forEach((folder) => { const packageJson = require(path.join(pluginFolder, 'package.json')); const packageName = packageJson.name; - addPluginToPackageJson(packageName); addPluginToIndexTs(packageName); }
