Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

chore: Update project configuration

robin7b3a1b00de68
diff --git a/ui/.eslintignore b/ui/.eslintignore
index a93b8236..0f13ec44 100644
--- a/ui/.eslintignore
+++ b/ui/.eslintignore
@@ -5,3 +5,4 @@ build
.eslintrc.js
node_modules/
src/types/
+scripts/
diff --git a/ui/.gitignore b/ui/.gitignore
index e6a74037..a73983ee 100644
--- a/ui/.gitignore
+++ b/ui/.gitignore
@@ -38,3 +38,4 @@ package-lock.json
!/src/plugins/Demo
!/src/plugins/answer-chart
!/src/plugins/answer-formula
+/src/plugins/*/*.go
diff --git a/ui/package.json b/ui/package.json
index d07bca70..649f0fe6 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -75,6 +75,7 @@
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
+ "humps": "^2.0.1",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"postcss": "^8.0.0",
diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml
index 4e8b3301..16d1ddc3 100644
--- a/ui/pnpm-lock.yaml
+++ b/ui/pnpm-lock.yaml
@@ -46,6 +46,7 @@ importers:
eslint-plugin-promise: ^6.0.0
eslint-plugin-react: ^7.30.1
eslint-plugin-react-hooks: ^4.6.0
+ humps: ^2.0.1
husky: ^8.0.1
i18next: ^21.9.0
lint-staged: ^13.0.3
@@ -132,6 +133,7 @@ importers:
eslint-plugin-promise: [email protected]
eslint-plugin-react: [email protected]
eslint-plugin-react-hooks: [email protected]
+ humps: 2.0.1
husky: 8.0.1
lint-staged: 13.0.3
postcss: 8.4.16
@@ -7331,6 +7333,10 @@ packages:
engines: {node: '>=12.20.0'}
dev: true
+ /humps/2.0.1:
+ resolution: {integrity: sha512-E0eIbrFWUhwfXJmsbdjRQFQPrl5pTEoKlz163j1mTqqUnU9PgR4AgB8AIITzuB3vLBdxZXyZ9TDIrwB2OASz4g==}
+ dev: true
+
/husky/8.0.1:
resolution: {integrity: sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==}
engines: {node: '>=14'}
diff --git a/ui/scripts/plugin.js b/ui/scripts/plugin.js
new file mode 100644
index 00000000..8d0952c0
--- /dev/null
+++ b/ui/scripts/plugin.js
@@ -0,0 +1,55 @@
+const path = require('path');
+const fs = require('fs');
+const humps = require('humps');
+
+const template = `
+package {{slugName}}
+
+import "github.com/answerdev/answer/plugin"
+
+type {{pluginName}} struct {
+}
+
+func init() {
+ plugin.Register(&{{pluginName}}{})
+}
+
+func (d {{pluginName}}) Info() plugin.Info {
+ return plugin.Info{
+ Name: plugin.MakeTranslator("i18n.{{slugName}}.name"),
+ SlugName: "{{slugName}}",
+ Description: plugin.MakeTranslator("i18n.{{slugName}}.description"),
+ Author: "{{author}}",
+ Version: "{{version}}",
+ }
+}
+`;
+
+const pluginPath = path.join(__dirname, '../src/plugins');
+const pluginFolders = fs.readdirSync(pluginPath);
+
+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;
+ }
+
+ const tsFile = fs.readFileSync(
+ path.join(pluginFolder, 'index.ts'),
+ 'utf-8',
+ );
+ const slugName = tsFile.match(/slug_name: '(.*)'/)[1];
+ const pluginName = humps.pascalize(slugName) + 'Plugin';
+ const packageJson = require(path.join(pluginFolder, 'package.json'));
+ const author = packageJson.author;
+ const version = packageJson.version;
+ const content = template
+ .replace(/{{slugName}}/g, slugName)
+ .replace(/{{pluginName}}/g, pluginName)
+ .replace(/{{author}}/g, author)
+ .replace(/{{version}}/g, version);
+ fs.writeFileSync(path.join(pluginFolder, `${slugName}.go`), content);
+ }
+});
diff --git a/ui/scripts/preinstall.js b/ui/scripts/preinstall.js
index 2faddacf..595b5a97 100644
--- a/ui/scripts/preinstall.js
+++ b/ui/scripts/preinstall.js
@@ -1,4 +1,7 @@
// There is a bug when using npm to install: the execution of preinstall is after install, so when this prompt is displayed, the dependent packages have already been installed.
+
+require('./plugin');
+
if (!/pnpm/.test(process.env.npm_execpath)) {
console.warn(
`\u001b[33mThis repository requires using pnpm as the package manager for scripts to work properly.\u001b[39m\n`,