refactor: move updatePluginContent to subWikiPlugin

This commit is contained in:
林一二 2021-06-03 20:57:32 +08:00
parent 255342a643
commit 88d4e3e078
5 changed files with 18 additions and 4 deletions

View file

@ -8,7 +8,7 @@ import { useTranslation } from 'react-i18next';
import { usePromiseValue, usePromiseValueAndSetter } from '@/helpers/useServiceValue'; import { usePromiseValue, usePromiseValueAndSetter } from '@/helpers/useServiceValue';
import { useStorageServiceUserInfoObservable } from '@services/auth/hooks'; import { useStorageServiceUserInfoObservable } from '@services/auth/hooks';
import { SupportedStorageServices } from '@services/types'; import { SupportedStorageServices } from '@services/types';
import { ISubWikiPluginContent } from '@services/wiki/updatePluginContent'; import { ISubWikiPluginContent } from '@services/wiki/plugin/subWikiPlugin';
import { INewWorkspaceConfig, IWorkspace } from '@services/workspaces/interface'; import { INewWorkspaceConfig, IWorkspace } from '@services/workspaces/interface';
export function useIsCreateMainWorkspace(): [boolean, React.Dispatch<React.SetStateAction<boolean>>] { export function useIsCreateMainWorkspace(): [boolean, React.Dispatch<React.SetStateAction<boolean>>] {

View file

@ -19,7 +19,7 @@ import {
import { Autocomplete } from '@material-ui/lab'; import { Autocomplete } from '@material-ui/lab';
import defaultIcon from '../../images/default-icon.png'; import defaultIcon from '../../images/default-icon.png';
import type { ISubWikiPluginContent } from '@services/wiki/updatePluginContent'; import type { ISubWikiPluginContent } from '@services/wiki/plugin/subWikiPlugin';
import { WindowNames, WindowMeta } from '@services/windows/WindowProperties'; import { WindowNames, WindowMeta } from '@services/windows/WindowProperties';
import { usePromiseValue } from '@/helpers/useServiceValue'; import { usePromiseValue } from '@/helpers/useServiceValue';
import { useWorkspaceObservable } from '@services/workspaces/hooks'; import { useWorkspaceObservable } from '@services/workspaces/hooks';

View file

@ -23,7 +23,7 @@ import { logger, wikiOutputToFile, refreshOutputFile } from '@services/libs/log'
import i18n from '@services/libs/i18n'; import i18n from '@services/libs/i18n';
import { lazyInject } from '@services/container'; import { lazyInject } from '@services/container';
import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/paths'; import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/paths';
import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './updatePluginContent'; import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './plugin/subWikiPlugin';
import { IWikiService, WikiControlActions } from './interface'; import { IWikiService, WikiControlActions } from './interface';
import { WikiChannel } from '@/constants/channels'; import { WikiChannel } from '@/constants/channels';
import { CopyWikiTemplateError, DoubleWikiInstanceError } from './error'; import { CopyWikiTemplateError, DoubleWikiInstanceError } from './error';

View file

@ -2,7 +2,7 @@ import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common';
import { WikiChannel } from '@/constants/channels'; import { WikiChannel } from '@/constants/channels';
import { IWorkspace } from '@services/workspaces/interface'; import { IWorkspace } from '@services/workspaces/interface';
import { IGitUserInfos } from '@services/git/interface'; import { IGitUserInfos } from '@services/git/interface';
import type { ISubWikiPluginContent } from './updatePluginContent'; import type { ISubWikiPluginContent } from './plugin/subWikiPlugin';
export type IWikiMessage = IWikiLogMessage | IWikiControlMessage; export type IWikiMessage = IWikiLogMessage | IWikiControlMessage;
export interface IWikiLogMessage { export interface IWikiLogMessage {

View file

@ -9,6 +9,11 @@ const getPathPart = (folderToPlace: string): string => `addprefix[/]addprefix[${
const getTagNameFromMatchPart = (matchPart: string): string => matchPart.replace('[!is[system]kin::to[', '').replace(/].*/, ''); const getTagNameFromMatchPart = (matchPart: string): string => matchPart.replace('[!is[system]kin::to[', '').replace(/].*/, '');
const getFolderNamePathPart = (pathPart: string): string => pathPart.replace(']addprefix[/]addprefix[subwiki]]', '').replace(/.+addprefix\[/, ''); const getFolderNamePathPart = (pathPart: string): string => pathPart.replace(']addprefix[/]addprefix[subwiki]]', '').replace(/.+addprefix\[/, '');
/**
* We have a tiddler in the sub-wiki plugin that overwrite the system tiddler $:/config/FileSystemPaths
* @param mainWikiPath subwiki's main wiki's absolute path.
* @returns
*/
function getFileSystemPathsTiddlerPath(mainWikiPath: string): string { function getFileSystemPathsTiddlerPath(mainWikiPath: string): string {
const pluginPath = path.join(mainWikiPath, 'plugins', 'linonetwo', 'sub-wiki'); const pluginPath = path.join(mainWikiPath, 'plugins', 'linonetwo', 'sub-wiki');
return path.join(pluginPath, 'FileSystemPaths.tid'); return path.join(pluginPath, 'FileSystemPaths.tid');
@ -75,10 +80,19 @@ export function updateSubWikiPluginContent(
fs.writeFileSync(FileSystemPathsTiddlerPath, newFileSystemPathsFile); fs.writeFileSync(FileSystemPathsTiddlerPath, newFileSystemPathsFile);
} }
/**
* "Sub-Wiki Plugin"'s content. Not about plugin content of a sub-wiki, sorry.
* This is about tag-subwiki pair, we put tiddler with certain tag into a subwiki according to these pairs.
*/
export interface ISubWikiPluginContent { export interface ISubWikiPluginContent {
tagName: string; tagName: string;
folderName: string; folderName: string;
} }
/**
* Get "Sub-Wiki Plugin"'s content
* @param mainWikiPath subwiki's main wiki's absolute path.
* @returns ISubWikiPluginContent
*/
export async function getSubWikiPluginContent(mainWikiPath: string): Promise<ISubWikiPluginContent[]> { export async function getSubWikiPluginContent(mainWikiPath: string): Promise<ISubWikiPluginContent[]> {
if (mainWikiPath.length === 0) return []; if (mainWikiPath.length === 0) return [];
const FileSystemPathsTiddlerPath = getFileSystemPathsTiddlerPath(mainWikiPath); const FileSystemPathsTiddlerPath = getFileSystemPathsTiddlerPath(mainWikiPath);