feat: 完成 v0.6.0 墨呈品牌迁移
This commit is contained in:
@@ -3,14 +3,25 @@ import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
interface PackageManifest {
|
||||
version?: string;
|
||||
productName?: string;
|
||||
scripts?: Record<string, string>;
|
||||
}
|
||||
|
||||
interface ProductBrand {
|
||||
appId: string;
|
||||
englishName: string;
|
||||
displayName: string;
|
||||
windowTitle: string;
|
||||
executableName: string;
|
||||
artifactPrefix: string;
|
||||
}
|
||||
|
||||
const desktopRoot = fileURLToPath(new URL("../", import.meta.url));
|
||||
const projectRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
|
||||
function readManifest(path: string): PackageManifest {
|
||||
return JSON.parse(readFileSync(path, "utf8")) as PackageManifest;
|
||||
function readManifest<T = PackageManifest>(path: string): T {
|
||||
return JSON.parse(readFileSync(path, "utf8")) as T;
|
||||
}
|
||||
|
||||
describe("桌面发行构建链", () => {
|
||||
@@ -58,6 +69,49 @@ describe("桌面发行构建链", () => {
|
||||
expect(builderConfig).toContain('to: "samples"');
|
||||
});
|
||||
|
||||
it("保持安装身份并从统一配置生成 MorphDoc 发行名称", () => {
|
||||
const brand = readManifest<ProductBrand>(
|
||||
`${projectRoot}/product.json`
|
||||
);
|
||||
const desktopManifest = readManifest(
|
||||
`${desktopRoot}/package.json`
|
||||
);
|
||||
const builderConfig = readFileSync(
|
||||
`${desktopRoot}/electron-builder.config.cjs`,
|
||||
"utf8"
|
||||
);
|
||||
const installerInclude = readFileSync(
|
||||
`${desktopRoot}/build/installer.nsh`,
|
||||
"utf8"
|
||||
);
|
||||
|
||||
expect(brand).toMatchObject({
|
||||
appId: "com.md-to-pdf.desktop",
|
||||
englishName: "MorphDoc",
|
||||
displayName: "墨呈",
|
||||
windowTitle: "墨呈 · MorphDoc",
|
||||
executableName: "MorphDoc",
|
||||
artifactPrefix: "MorphDoc"
|
||||
});
|
||||
expect(desktopManifest).toMatchObject({
|
||||
version: "0.6.0",
|
||||
productName: "MorphDoc"
|
||||
});
|
||||
expect(builderConfig).toContain("appId: brand.appId");
|
||||
expect(builderConfig).toContain("productName: brand.englishName");
|
||||
expect(builderConfig).toContain("executableName: brand.executableName");
|
||||
expect(builderConfig).toContain("shortcutName: brand.displayName");
|
||||
expect(installerInclude).toContain(
|
||||
'!define MORPHDOC_EXECUTABLE "MorphDoc.exe"'
|
||||
);
|
||||
expect(installerInclude).toContain(
|
||||
'!define MORPHDOC_DISPLAY_NAME "墨呈"'
|
||||
);
|
||||
expect(installerInclude).toContain(
|
||||
"Software\\Classes\\Applications\\${MORPHDOC_LEGACY_EXECUTABLE}"
|
||||
);
|
||||
});
|
||||
|
||||
it("仅在组合构建时接入经过哈希校验的同目录字体包", () => {
|
||||
const builderConfig = readFileSync(
|
||||
`${desktopRoot}/electron-builder.config.cjs`,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { mkdtemp, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { migrateLegacyUserData } from "../src/user-data-migration.js";
|
||||
|
||||
const temporaryDirectories: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryDirectories.splice(0).map((directory) =>
|
||||
rm(directory, { recursive: true, force: true })
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
async function createRoot() {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "morphdoc-migration-"));
|
||||
temporaryDirectories.push(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
describe("品牌升级用户数据迁移", () => {
|
||||
it("首次启动时复制状态、主题和浏览器本地存储但保留旧目录", async () => {
|
||||
const root = await createRoot();
|
||||
const legacy = path.join(root, "Markdown PDF 导出器");
|
||||
const target = path.join(root, "MorphDoc");
|
||||
await mkdir(path.join(legacy, "themes", "custom"), {
|
||||
recursive: true
|
||||
});
|
||||
await mkdir(path.join(legacy, "Local Storage"), {
|
||||
recursive: true
|
||||
});
|
||||
await writeFile(
|
||||
path.join(legacy, "window-state.json"),
|
||||
'{"width":1280}',
|
||||
"utf8"
|
||||
);
|
||||
await writeFile(
|
||||
path.join(legacy, "themes", "custom", "theme.css"),
|
||||
"#write{}",
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const result = await migrateLegacyUserData([legacy], target);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
migrated: true,
|
||||
sourceDirectory: legacy,
|
||||
copiedEntries: ["window-state.json", "themes", "Local Storage"]
|
||||
});
|
||||
expect(
|
||||
await readFile(path.join(target, "window-state.json"), "utf8")
|
||||
).toBe('{"width":1280}');
|
||||
expect(
|
||||
await readFile(
|
||||
path.join(target, "themes", "custom", "theme.css"),
|
||||
"utf8"
|
||||
)
|
||||
).toBe("#write{}");
|
||||
expect(
|
||||
await readFile(path.join(legacy, "window-state.json"), "utf8")
|
||||
).toBe('{"width":1280}');
|
||||
});
|
||||
|
||||
it("目标目录已经存在时不覆盖新版本数据", async () => {
|
||||
const root = await createRoot();
|
||||
const legacy = path.join(root, "Markdown PDF 导出器");
|
||||
const target = path.join(root, "MorphDoc");
|
||||
await mkdir(legacy, { recursive: true });
|
||||
await mkdir(target, { recursive: true });
|
||||
await writeFile(path.join(legacy, "window-state.json"), "legacy", "utf8");
|
||||
await writeFile(path.join(target, "window-state.json"), "current", "utf8");
|
||||
|
||||
expect(await migrateLegacyUserData([legacy], target)).toEqual({
|
||||
migrated: false,
|
||||
copiedEntries: []
|
||||
});
|
||||
expect(
|
||||
await readFile(path.join(target, "window-state.json"), "utf8")
|
||||
).toBe("current");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user