This is an automated email from the ASF dual-hosted git repository.
robin0716 pushed a commit to branch feat/1.3.5/embed
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.5/embed by this push:
new 5459507b chore: update plugin.js
5459507b is described below
commit 5459507b0940006efaf2f3d092891bb08ec5f905
Author: robin <[email protected]>
AuthorDate: Thu Jun 6 15:22:36 2024 +0800
chore: update plugin.js
---
ui/scripts/plugin.js | 81 +++++++++++++++++++++++++++++++++++-----------------
1 file changed, 55 insertions(+), 26 deletions(-)
diff --git a/ui/scripts/plugin.js b/ui/scripts/plugin.js
index 48a37ef5..d26dbcdc 100644
--- a/ui/scripts/plugin.js
+++ b/ui/scripts/plugin.js
@@ -20,44 +20,73 @@
const path = require('path');
const fs = require('fs');
+const pluginPath = path.join(__dirname, '../src/plugins');
+const pluginFolders = fs.readdirSync(pluginPath);
+
function pascalize(str) {
- str = str.replace(/[-_\s]+/g, '');
- return str.charAt(0).toUpperCase() + str.slice(1);
+ return str.replace(/\b\w/g, (match) => match.toUpperCase())
+ .replace(/[-_\s]+/g, '');
}
-const pluginPath = path.join(__dirname, '../src/plugins');
-const pluginFolders = fs.readdirSync(pluginPath);
+function resetPackageJson() {
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
+ const packageJsonContent = require(packageJsonPath);
+ const dependencies = packageJsonContent.dependencies;
+ for (const key in dependencies) {
+ if (dependencies[key].startsWith('workspace')) {
+ delete dependencies[key];
+ }
+ }
+ fs.writeFileSync(
+ packageJsonPath,
+ JSON.stringify(packageJsonContent, null, 2),
+ );
+}
+
+function resetIndexTs() {
+ const indexTsPath = path.join(pluginPath, 'index.ts');
+ fs.writeFileSync(indexTsPath, '');
+}
+function addPluginToPackageJson(packageName) {
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
+ const packageJsonContent = require(packageJsonPath);
+ packageJsonContent.dependencies[packageName] = 'workspace:*';
+
+ fs.writeFileSync(
+ packageJsonPath,
+ JSON.stringify(packageJsonContent, null, 2),
+ );
+}
+
+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 importLine = `export { default as ${ComponentName} } from
'${packageName}';`;
+ if (!lines.includes(importLine)) {
+ lines.push(importLine);
+ }
+ fs.writeFileSync(indexTsPath, lines.join('\n'));
+}
+
+
+resetPackageJson();
+resetIndexTs();
pluginFolders.forEach((folder) => {
const pluginFolder = path.join(pluginPath, folder);
const stat = fs.statSync(pluginFolder);
+
if (stat.isDirectory() && folder !== 'builtin') {
if (!fs.existsSync(path.join(pluginFolder, 'index.ts'))) {
return;
}
-
- // add plugin to package.json
const packageJson = require(path.join(pluginFolder, 'package.json'));
const packageName = packageJson.name;
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
- const packageJsonContent = require(packageJsonPath);
- packageJsonContent.dependencies[packageName] = 'workspace:*';
-
- fs.writeFileSync(
- packageJsonPath,
- JSON.stringify(packageJsonContent, null, 2),
- );
-
-
- // add plugin to index.ts last line
- const indexTsPath = path.join(pluginPath, 'index.ts');
- const indexTsContent = fs.readFileSync(indexTsPath, 'utf-8');
- const lines = indexTsContent.split('\n');
- const ComponentName = pascalize(packageName);
- const importLine = `export { default as ${ComponentName} } from
'${packageName}';`;
- if (!lines.includes(importLine)) {
- lines.push(importLine);
- }
- fs.writeFileSync(indexTsPath, lines.join('\n'));
+
+
+ addPluginToPackageJson(packageName);
+ addPluginToIndexTs(packageName);
}
});