This is an automated email from the ASF dual-hosted git repository.
robin0716 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/dev by this push:
new 2ff6e7ea feat: Update plugin.js to use humps for pascalizing package
names
2ff6e7ea is described below
commit 2ff6e7eab453b7ad5826ac8a7be93286de1c547d
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);
}