chore: API改为类,成员函数变量增加static关键字 & yarn lint

This commit is contained in:
noe
2022-09-24 11:44:04 +08:00
parent 17436b0e9a
commit cfc10a6aee
25 changed files with 727 additions and 681 deletions

View File

@@ -20,4 +20,4 @@ export default {
},
},
global: [],
}
};

View File

@@ -6,7 +6,7 @@ export default (): string => {
if (!localDataFile) {
localDataFile = process.env.LOCALAPPDATA;
}
const rubickPath = path.join(localDataFile, "rubick")
const rubickPath = path.join(localDataFile, "rubick");
if (!fs.existsSync(rubickPath)) {
fs.mkdirSync(rubickPath);
}

View File

@@ -11,7 +11,8 @@ let registry;
let pluginInstance;
(async () => {
try {
registry = (await API.dbGet({ data: { id: "rubick-localhost-config" } })).data.register;
registry = (await API.dbGet({ data: { id: "rubick-localhost-config" } }))
.data.register;
console.log(registry);
pluginInstance = new PluginHandler({
baseDir,
@@ -31,11 +32,7 @@ global.LOCAL_PLUGINS = {
await pluginInstance.install([plugin.name], { isDev: plugin.isDev });
if (plugin.isDev) {
// 获取 dev 插件信息
const pluginPath = path.resolve(
baseDir,
"node_modules",
plugin.name
);
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
const pluginInfo = JSON.parse(
fs.readFileSync(path.join(pluginPath, "./package.json"), "utf8")
);
@@ -49,11 +46,7 @@ global.LOCAL_PLUGINS = {
},
refreshPlugin(plugin) {
// 获取 dev 插件信息
const pluginPath = path.resolve(
baseDir,
"node_modules",
plugin.name
);
const pluginPath = path.resolve(baseDir, "node_modules", plugin.name);
const pluginInfo = JSON.parse(
fs.readFileSync(path.join(pluginPath, "./package.json"), "utf8")
);
@@ -73,10 +66,7 @@ global.LOCAL_PLUGINS = {
// 存入
global.LOCAL_PLUGINS.PLUGINS = currentPlugins;
fs.writeFileSync(
configPath,
JSON.stringify(currentPlugins)
);
fs.writeFileSync(configPath, JSON.stringify(currentPlugins));
return global.LOCAL_PLUGINS.PLUGINS;
},
getLocalPlugins() {
@@ -102,10 +92,7 @@ global.LOCAL_PLUGINS = {
if (!has) {
currentPlugins.unshift(plugin);
global.LOCAL_PLUGINS.PLUGINS = currentPlugins;
fs.writeFileSync(
configPath,
JSON.stringify(currentPlugins)
);
fs.writeFileSync(configPath, JSON.stringify(currentPlugins));
}
},
updatePlugin(plugin) {
@@ -121,7 +108,9 @@ global.LOCAL_PLUGINS = {
},
async deletePlugin(plugin) {
await pluginInstance.uninstall([plugin.name], { isDev: plugin.isDev });
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.filter((p) => plugin.name !== p.name);
global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.filter(
(p) => plugin.name !== p.name
);
fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS));
return global.LOCAL_PLUGINS.PLUGINS;
},