chore: Update plugin script

This commit is contained in:
robin 2023-09-25 11:44:11 +08:00
parent 0bfe533afb
commit 7f1186b013
2 changed files with 3 additions and 42 deletions

View File

@ -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/

View File

@ -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),