From 7f1186b01322d41148410901e7a76a68fdfc677e Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 25 Sep 2023 11:44:11 +0800 Subject: [PATCH] chore: Update plugin script --- ui/.env.development | 2 +- ui/scripts/plugin.js | 43 ++----------------------------------------- 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/ui/.env.development b/ui/.env.development index c78ae289..a634cee2 100644 --- a/ui/.env.development +++ b/ui/.env.development @@ -1,2 +1,2 @@ PUBLIC_URL -REACT_APP_API_URL = http://127.0.0.1 +REACT_APP_API_URL = http://10.0.20.84:8080/ diff --git a/ui/scripts/plugin.js b/ui/scripts/plugin.js index 873b19c5..823b6b6b 100644 --- a/ui/scripts/plugin.js +++ b/ui/scripts/plugin.js @@ -1,29 +1,5 @@ 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); @@ -36,28 +12,13 @@ pluginFolders.forEach((folder) => { 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'; + // add plugin to package.json 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); - const packageName = packageJson.name; - // update package.json dependencies const packageJsonPath = path.join(__dirname, 'package.json'); const packageJsonContent = require(packageJsonPath); packageJsonContent.dependencies[packageName] = 'workspace:*'; + fs.writeFileSync( packageJsonPath, JSON.stringify(packageJsonContent, null, 2),