[Update] Plugins dev: Apply-able aliases.
This commit is contained in:
@@ -10,12 +10,20 @@ import { useStdoutToPython } from "@logics/useStdoutToPython";
|
|||||||
|
|
||||||
import { transform } from "@babel/standalone";
|
import { transform } from "@babel/standalone";
|
||||||
import { writeFile, createDir, exists, removeDir, readDir, BaseDirectory, readTextFile } from "@tauri-apps/api/fs";
|
import { writeFile, createDir, exists, removeDir, readDir, BaseDirectory, readTextFile } from "@tauri-apps/api/fs";
|
||||||
import { dev_plugins } from "@dev_plugins_path";
|
import { dev_plugins } from "@plugins_index";
|
||||||
|
const imported_dev_plugins = [];
|
||||||
|
dev_plugins.forEach(async ({entry_path}) => {
|
||||||
|
imported_dev_plugins.push({
|
||||||
|
index: await import(`@plugins_path/${entry_path}/index.jsx`),
|
||||||
|
plugin_info: await import(`@plugins_path/${entry_path}/plugin_info.json`),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
|
|
||||||
import { useFetch } from "@logics_common";
|
import { useFetch } from "@logics_common";
|
||||||
import { useSoftwareVersion } from "@logics_configs";
|
import { useSoftwareVersion } from "@logics_configs";
|
||||||
|
|
||||||
import * as logics_configs from "@logics_configs";
|
import * as logics_configs from "@logics_configs";
|
||||||
import * as logics_main from "@logics_main";
|
import * as logics_main from "@logics_main";
|
||||||
import * as logics_common from "@logics_common";
|
import * as logics_common from "@logics_common";
|
||||||
@@ -91,9 +99,8 @@ export const usePlugins = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const asyncLoadAllPlugins = async () => {
|
const asyncLoadAllPlugins = async () => {
|
||||||
if (import.meta.env.DEV) {
|
if (!import.meta.env.DEV) {
|
||||||
// `dev_plugins` を利用してプラグインを登録
|
imported_dev_plugins.forEach(({ index, plugin_info }) => {
|
||||||
dev_plugins.forEach(({ index, plugin_info }) => {
|
|
||||||
if (!index || !plugin_info) {
|
if (!index || !plugin_info) {
|
||||||
console.error("Invalid development plugin detected", index, plugin_info);
|
console.error("Invalid development plugin detected", index, plugin_info);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { initStore, StoreContext } from "./store/store.js";
|
import { initStore, StoreContext } from "@plugin_store";
|
||||||
import { SubtitleSystemContainer } from "./subtitle_system_container/SubtitleSystemContainer";
|
import { SubtitleSystemContainer } from "./subtitle_system_container/SubtitleSystemContainer";
|
||||||
import { SubtitlesController } from "./subtitle_system_container/_controllers/SubtitlesController.jsx";
|
import { SubtitlesController } from "./subtitle_system_container/_controllers/SubtitlesController.jsx";
|
||||||
|
|
||||||
|
|||||||
5
src-ui/plugins/dev_plugin_subtitles/plugin_configs.js
Normal file
5
src-ui/plugins/dev_plugin_subtitles/plugin_configs.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export const configs = {
|
||||||
|
alias: {
|
||||||
|
"@plugin_store": "store/store.js",
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import plugin_index_1 from "./dev_plugin_subtitles/index.jsx";
|
|
||||||
import plugin_info_1 from "./dev_plugin_subtitles/plugin_info.json";
|
|
||||||
|
|
||||||
export const dev_plugins = [
|
|
||||||
{
|
|
||||||
index: { init: plugin_index_1 },
|
|
||||||
plugin_info: plugin_info_1,
|
|
||||||
}
|
|
||||||
];
|
|
||||||
3
src-ui/plugins/plugins_index.js
Normal file
3
src-ui/plugins/plugins_index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const dev_plugins = [
|
||||||
|
{ entry_path: "dev_plugin_subtitles" }
|
||||||
|
];
|
||||||
130
vite.config.js
130
vite.config.js
@@ -3,62 +3,96 @@ import react from "@vitejs/plugin-react";
|
|||||||
import svgr from "vite-plugin-svgr";
|
import svgr from "vite-plugin-svgr";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
|
import { dev_plugins } from "./src-ui/plugins/plugins_index.js";
|
||||||
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig(async () => ({
|
export default defineConfig(async () => {
|
||||||
plugins: [react(), svgr()],
|
const plugin_aliases = await getPluginAliases();
|
||||||
assetsInclude: ["**/*.yml"],
|
|
||||||
|
|
||||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
return {
|
||||||
//
|
plugins: [react(), svgr()],
|
||||||
// 1. prevent vite from obscuring rust errors
|
assetsInclude: ["**/*.yml"],
|
||||||
clearScreen: false,
|
|
||||||
// 2. tauri expects a fixed port, fail if that port is not available
|
|
||||||
server: {
|
|
||||||
port: 1420,
|
|
||||||
strictPort: true,
|
|
||||||
watch: {
|
|
||||||
// 3. tell vite to ignore watching `src-tauri`
|
|
||||||
ignored: ["**/src-tauri/**"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
build: {
|
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||||
outDir: path.resolve(__dirname, "dist"),
|
//
|
||||||
rollupOptions: {
|
// 1. prevent vite from obscuring rust errors
|
||||||
input: {
|
clearScreen: false,
|
||||||
main: path.resolve(__dirname, "index.html"),
|
// 2. tauri expects a fixed port, fail if that port is not available
|
||||||
|
server: {
|
||||||
|
port: 1420,
|
||||||
|
strictPort: true,
|
||||||
|
watch: {
|
||||||
|
// 3. tell vite to ignore watching `src-tauri`
|
||||||
|
ignored: ["**/src-tauri/**"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
resolve: {
|
build: {
|
||||||
alias: {
|
outDir: path.resolve(__dirname, "dist"),
|
||||||
"@root": path.resolve(__dirname),
|
rollupOptions: {
|
||||||
"@test_data": path.resolve(__dirname, "./test_data.js"),
|
input: {
|
||||||
|
main: path.resolve(__dirname, "index.html"),
|
||||||
"@ui_configs": path.resolve(__dirname, "src-ui/ui_configs.js"),
|
},
|
||||||
"@scss_mixins": path.resolve(__dirname, "src-ui/common_css/mixins.scss"),
|
},
|
||||||
"@store": path.resolve(__dirname, "src-ui/store.js"),
|
|
||||||
"@images": path.resolve(__dirname, "src-ui/assets"),
|
|
||||||
"@utils": path.resolve(__dirname, "src-ui/utils.js"),
|
|
||||||
"@logics": path.resolve(__dirname, "src-ui/logics"),
|
|
||||||
"@logics_common": path.resolve(__dirname, "src-ui/logics/common"),
|
|
||||||
"@logics_main": path.resolve(__dirname, "src-ui/logics/main"),
|
|
||||||
"@logics_configs": path.resolve(__dirname, "src-ui/logics/configs"),
|
|
||||||
|
|
||||||
"@setting_box": path.resolve(__dirname, "src-ui/app/config_page/setting_section/setting_box/index.js"),
|
|
||||||
"@common_components": path.resolve(__dirname, "src-ui/common_components/index.js"),
|
|
||||||
|
|
||||||
"@dev_plugins_path": path.resolve(__dirname, "src-ui/plugins/index.js"),
|
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
css: {
|
resolve: {
|
||||||
preprocessorOptions: {
|
alias: {
|
||||||
scss: {
|
"@root": path.resolve(__dirname),
|
||||||
api: "modern-compiler"
|
"@test_data": path.resolve(__dirname, "./test_data.js"),
|
||||||
|
|
||||||
|
"@ui_configs": path.resolve(__dirname, "src-ui/ui_configs.js"),
|
||||||
|
"@scss_mixins": path.resolve(__dirname, "src-ui/common_css/mixins.scss"),
|
||||||
|
"@store": path.resolve(__dirname, "src-ui/store.js"),
|
||||||
|
"@images": path.resolve(__dirname, "src-ui/assets"),
|
||||||
|
"@utils": path.resolve(__dirname, "src-ui/utils.js"),
|
||||||
|
"@logics": path.resolve(__dirname, "src-ui/logics"),
|
||||||
|
"@logics_common": path.resolve(__dirname, "src-ui/logics/common"),
|
||||||
|
"@logics_main": path.resolve(__dirname, "src-ui/logics/main"),
|
||||||
|
"@logics_configs": path.resolve(__dirname, "src-ui/logics/configs"),
|
||||||
|
|
||||||
|
"@setting_box": path.resolve(__dirname, "src-ui/app/config_page/setting_section/setting_box/index.js"),
|
||||||
|
"@common_components": path.resolve(__dirname, "src-ui/common_components/index.js"),
|
||||||
|
|
||||||
|
// Plugins
|
||||||
|
"@plugins_path": path.resolve(__dirname, "src-ui/plugins"),
|
||||||
|
"@plugins_index": path.resolve(__dirname, "src-ui/plugins/plugins_index.js"),
|
||||||
|
...plugin_aliases,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
css: {
|
||||||
|
preprocessorOptions: {
|
||||||
|
scss: {
|
||||||
|
api: "modern-compiler"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
});
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
// 各プラグインのエイリアスを動的に読み込む関数
|
||||||
|
const getPluginAliases = async () => {
|
||||||
|
const aliases = {};
|
||||||
|
// dev_plugins 配列の各プラグインについて処理する
|
||||||
|
for (const plugin of dev_plugins) {
|
||||||
|
const entry_path = plugin.entry_path; // 例: "dev_plugin_subtitles"
|
||||||
|
try {
|
||||||
|
// エイリアス設定ファイルは各プラグインフォルダ内の "configs.js" に記述されている前提
|
||||||
|
const pluginConfig = await import(`./src-ui/plugins/${entry_path}/plugin_configs.js`);
|
||||||
|
if (pluginConfig.configs && pluginConfig.configs.alias) {
|
||||||
|
for (const [alias_key, alias_relative_path] of Object.entries(pluginConfig.configs.alias)) {
|
||||||
|
|
||||||
|
// ホスト側の絶対パスに変換
|
||||||
|
aliases[alias_key] = path.resolve(__dirname, "src-ui/plugins", entry_path, alias_relative_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error loading alias config for plugin ${plugin.plugin_info.plugin_id}:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aliases;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user