81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
import { copyFile, mkdir, readFile } from "node:fs/promises";
|
|
import { spawn } from "node:child_process";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { createDesktopCompanionInclude } from "../packages/font-pack-builder/dist/index.js";
|
|
|
|
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const desktopRoot = join(repositoryRoot, "apps", "desktop");
|
|
const desktopManifest = JSON.parse(
|
|
await readFile(join(desktopRoot, "package.json"), "utf8")
|
|
);
|
|
const fontInstallerName =
|
|
"MorphDoc-FontPack-mdtp-serif-sc-1.0.0-x86_64-Setup.exe";
|
|
const fontArchiveName = "MorphDoc-FontPack-mdtp-serif-sc-1.0.0.zip";
|
|
const fontInstallerPath = join(
|
|
repositoryRoot,
|
|
"output",
|
|
"font-packs",
|
|
"windows",
|
|
fontInstallerName
|
|
);
|
|
const generatedInclude = join(
|
|
repositoryRoot,
|
|
"output",
|
|
"font-packs",
|
|
"desktop-companion.nsh"
|
|
);
|
|
const fontArchivePath = join(
|
|
repositoryRoot,
|
|
"output",
|
|
"font-packs",
|
|
"release",
|
|
fontArchiveName
|
|
);
|
|
|
|
await createDesktopCompanionInclude({
|
|
installerPath: fontInstallerPath,
|
|
baseIncludePath: join(desktopRoot, "build", "installer.nsh"),
|
|
outputPath: generatedInclude,
|
|
displayName: "MdTP 中文宋体兼容包 1.0.0"
|
|
});
|
|
|
|
const npmCli =
|
|
process.env.npm_execpath ||
|
|
join(dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
|
|
await new Promise((resolvePromise, reject) => {
|
|
const child = spawn(
|
|
process.execPath,
|
|
[npmCli, "run", "make", "-w", "@md-to-pdf/desktop"],
|
|
{
|
|
cwd: repositoryRoot,
|
|
env: {
|
|
...process.env,
|
|
MD_TO_PDF_NSIS_INCLUDE: generatedInclude
|
|
},
|
|
stdio: "inherit",
|
|
windowsHide: true
|
|
}
|
|
);
|
|
child.once("error", reject);
|
|
child.once("exit", (code, signal) => {
|
|
if (code === 0) {
|
|
resolvePromise();
|
|
} else {
|
|
reject(
|
|
new Error(
|
|
`桌面安装器构建失败:${signal ? `signal ${signal}` : `exit ${code ?? "unknown"}`}`
|
|
)
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
const desktopOutput = join(desktopRoot, "out", `v${desktopManifest.version}`);
|
|
await mkdir(desktopOutput, { recursive: true });
|
|
await copyFile(fontInstallerPath, join(desktopOutput, fontInstallerName));
|
|
await copyFile(fontArchivePath, join(desktopOutput, fontArchiveName));
|
|
process.stdout.write(
|
|
`主安装器、字体包伴随安装器与 ZIP 附件已生成:${desktopOutput}\n`
|
|
);
|