mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-29 13:49:31 +07:00
* refactor: client ipc * refactor: server ipc refactor: update IPC method names for consistency Signed-off-by: Innei <tukon479@gmail.com> fix: cast IPC return type to DesktopIpcServices for type safety Signed-off-by: Innei <tukon479@gmail.com> chore: add new workspace for desktop application in package.json Signed-off-by: Innei <tukon479@gmail.com> fix: export FileMetadata interface for improved accessibility Signed-off-by: Innei <tukon479@gmail.com> refactor: unify IPC mocking across test files for consistency Signed-off-by: Innei <tukon479@gmail.com> feat: enhance type-safe IPC flow with context propagation and service registry - Introduced `getIpcContext()` and `runWithIpcContext()` for improved context management in IPC handlers. - Updated `BrowserWindowsCtr` methods to utilize the new context handling. - Added `McpInstallCtr` to the IPC constructors registry. - Enhanced README with details on the new type-safe IPC features. Signed-off-by: Innei <tukon479@gmail.com> refactor: enhance IPC method registration for improved type safety - Updated `registerMethod` in `IpcHandler` and `IpcService` to accept variable argument types, enhancing flexibility in method signatures. - Simplified the `ExtractMethodSignature` type to support multiple arguments. Signed-off-by: Innei <tukon479@gmail.com> chore: add global type definitions and refactor import statements - Introduced a new global type definition file to support Vite client imports. - Refactored import statements in `App.ts` and `App.test.ts` to remove unnecessary type casting for `import.meta.glob`, improving code clarity. Signed-off-by: Innei <tukon479@gmail.com> * refactor: make groupName in BrowserWindowsCtr readonly for better encapsulation Signed-off-by: Innei <tukon479@gmail.com> * refactor: update IPC method registration and usage for improved type safety and consistency - Replaced `@ipcClientEvent` with `@IpcMethod()` in various controllers to standardize IPC method definitions. - Enhanced the usage of `ensureElectronIpc()` for type-safe IPC calls in service layers. - Updated `BrowserWindowsCtr` and `NotificationCtr` to utilize the new IPC method structure, improving encapsulation and clarity. - Refactored service methods to eliminate manual string concatenation for IPC event names, ensuring better maintainability. Signed-off-by: Innei <tukon479@gmail.com> --------- Signed-off-by: Innei <tukon479@gmail.com>
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { consola } from 'consola';
|
|
import { colors } from 'consola/utils';
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import prettier from "@prettier/sync";
|
|
import i18nConfig from './i18nConfig';
|
|
|
|
let prettierOptions = prettier.resolveConfig(
|
|
resolve(__dirname, '../../.prettierrc.js')
|
|
);
|
|
|
|
export const readJSON = (filePath: string) => {
|
|
const data = readFileSync(filePath, 'utf8');
|
|
return JSON.parse(data);
|
|
};
|
|
|
|
export const writeJSON = (filePath: string, data: any) => {
|
|
const jsonStr = JSON.stringify(data, null, 2);
|
|
writeFileSync(filePath, jsonStr, 'utf8');
|
|
};
|
|
|
|
export const writeJSONWithPrettier = (filePath: string, data: any) => {
|
|
const jsonStr = JSON.stringify(data, null, 2);
|
|
const formatted = prettier.format(jsonStr, {
|
|
...prettierOptions,
|
|
parser: 'json',
|
|
});
|
|
writeFileSync(filePath, formatted, 'utf8');
|
|
};
|
|
|
|
export const genResourcesContent = (locales: string[]) => {
|
|
let index = '';
|
|
let indexObj = '';
|
|
|
|
for (const locale of locales) {
|
|
index += `import ${locale} from "./${locale}";\n`;
|
|
indexObj += ` "${locale.replace('_', '-')}": ${locale},\n`;
|
|
}
|
|
|
|
return `${index}
|
|
const resources = {
|
|
${indexObj}} as const;
|
|
export default resources;
|
|
export const defaultResources = ${i18nConfig.entryLocale};
|
|
export type Resources = typeof resources;
|
|
export type DefaultResources = typeof defaultResources;
|
|
export type Namespaces = keyof DefaultResources;
|
|
export type Locales = keyof Resources;
|
|
`;
|
|
};
|
|
|
|
export const genNamespaceList = (files: string[], locale: string) => {
|
|
return files.map((file) => ({
|
|
name: file.replace('.json', ''),
|
|
path: resolve(i18nConfig.output, locale, file),
|
|
}));
|
|
};
|
|
|
|
export const tagBlue = (text: string) => colors.bgBlueBright(colors.black(` ${text} `));
|
|
export const tagYellow = (text: string) => colors.bgYellowBright(colors.black(` ${text} `));
|
|
export const tagGreen = (text: string) => colors.bgGreenBright(colors.black(` ${text} `));
|
|
export const tagWhite = (text: string) => colors.bgWhiteBright(colors.black(` ${text} `));
|
|
|
|
export const split = (name: string) => {
|
|
consola.log('');
|
|
consola.log(colors.gray(`========================== ${name} ==============================`));
|
|
};
|