@openmnemo/report 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chunk-RCUFIYQZ.js +14 -0
- package/dist/github-pages-XPQKYB2E.js +102 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +3235 -0
- package/dist/webhook-6KVPOX3O.js +162 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openmnemo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/log.ts
|
|
2
|
+
function getLogger() {
|
|
3
|
+
const prefix = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
4
|
+
return {
|
|
5
|
+
debug: (m) => console.debug(`${prefix()} [DEBUG] ${m}`),
|
|
6
|
+
info: (m) => console.info(`${prefix()} [INFO] ${m}`),
|
|
7
|
+
warn: (m) => console.warn(`${prefix()} [WARN] ${m}`),
|
|
8
|
+
error: (m) => console.error(`${prefix()} [ERROR] ${m}`)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
getLogger
|
|
14
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLogger
|
|
3
|
+
} from "./chunk-RCUFIYQZ.js";
|
|
4
|
+
|
|
5
|
+
// src/deploy/github-pages.ts
|
|
6
|
+
import { cpSync, existsSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { tmpdir } from "os";
|
|
9
|
+
import { execFileSync } from "child_process";
|
|
10
|
+
var COMMIT_MESSAGE = "chore: publish memorytree report";
|
|
11
|
+
var COMMITTER_NAME = "MemoryTree";
|
|
12
|
+
var COMMITTER_EMAIL = "memorytree@local.invalid";
|
|
13
|
+
var BRANCH_RE = /^[a-zA-Z0-9._/-]+$/;
|
|
14
|
+
async function deployGithubPages(options) {
|
|
15
|
+
const { repoRoot, outputDir, branch, cname } = options;
|
|
16
|
+
const logger = getLogger();
|
|
17
|
+
if (!branch) return;
|
|
18
|
+
if (!BRANCH_RE.test(branch)) {
|
|
19
|
+
logger.warn(`[gh-pages] Invalid branch name, skipping deploy: "${branch}"`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!existsSync(outputDir)) {
|
|
23
|
+
logger.warn(`[gh-pages] Output directory does not exist, skipping deploy: ${outputDir}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
if (cname) {
|
|
28
|
+
const cnamePath = join(outputDir, "CNAME");
|
|
29
|
+
writeFileSync(cnamePath, cname + "\n", "utf-8");
|
|
30
|
+
logger.info(`[gh-pages] CNAME written: ${cname}`);
|
|
31
|
+
}
|
|
32
|
+
const remoteUrl = git(repoRoot, "remote", "get-url", "origin").trim();
|
|
33
|
+
if (!remoteUrl) {
|
|
34
|
+
logger.warn("[gh-pages] No origin remote configured, skipping deploy.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const publishRoot = mkdtempSync(join(tmpdir(), "mt-gh-pages-"));
|
|
38
|
+
try {
|
|
39
|
+
git(publishRoot, "init");
|
|
40
|
+
git(publishRoot, "remote", "add", "origin", remoteUrl);
|
|
41
|
+
if (remoteBranchExists(publishRoot, branch)) {
|
|
42
|
+
logger.info(`[gh-pages] Updating existing origin/${branch} branch.`);
|
|
43
|
+
git(publishRoot, "fetch", "--depth", "1", "origin", branch);
|
|
44
|
+
git(publishRoot, "checkout", "-B", branch, "FETCH_HEAD");
|
|
45
|
+
} else {
|
|
46
|
+
logger.info(`[gh-pages] Branch '${branch}' not found, creating orphan publish branch.`);
|
|
47
|
+
git(publishRoot, "checkout", "--orphan", branch);
|
|
48
|
+
}
|
|
49
|
+
clearDirectory(publishRoot);
|
|
50
|
+
copyDirectoryContents(outputDir, publishRoot);
|
|
51
|
+
git(publishRoot, "add", "--all");
|
|
52
|
+
if (!hasPendingChanges(publishRoot)) {
|
|
53
|
+
logger.info(`[gh-pages] No changes to publish for origin/${branch}.`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
git(
|
|
57
|
+
publishRoot,
|
|
58
|
+
"-c",
|
|
59
|
+
`user.name=${COMMITTER_NAME}`,
|
|
60
|
+
"-c",
|
|
61
|
+
`user.email=${COMMITTER_EMAIL}`,
|
|
62
|
+
"commit",
|
|
63
|
+
"-m",
|
|
64
|
+
COMMIT_MESSAGE
|
|
65
|
+
);
|
|
66
|
+
git(publishRoot, "push", "origin", `HEAD:${branch}`);
|
|
67
|
+
logger.info(`[gh-pages] Successfully pushed report to origin/${branch}`);
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(publishRoot, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
logger.warn(`[gh-pages] Deploy failed: ${String(err)}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function remoteBranchExists(cwd, branch) {
|
|
76
|
+
try {
|
|
77
|
+
git(cwd, "ls-remote", "--exit-code", "--heads", "origin", branch);
|
|
78
|
+
return true;
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function clearDirectory(root) {
|
|
84
|
+
for (const entry of readdirSync(root)) {
|
|
85
|
+
if (entry === ".git") continue;
|
|
86
|
+
rmSync(join(root, entry), { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function copyDirectoryContents(source, destination) {
|
|
90
|
+
for (const entry of readdirSync(source)) {
|
|
91
|
+
cpSync(join(source, entry), join(destination, entry), { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function hasPendingChanges(cwd) {
|
|
95
|
+
return git(cwd, "status", "--short").trim().length > 0;
|
|
96
|
+
}
|
|
97
|
+
function git(cwd, ...args) {
|
|
98
|
+
return execFileSync("git", args, { cwd, stdio: "pipe" }).toString();
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
deployGithubPages
|
|
102
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the report generation subsystem.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
interface BuildReportOptions {
|
|
6
|
+
root: string;
|
|
7
|
+
output: string;
|
|
8
|
+
noAi?: boolean;
|
|
9
|
+
model?: string;
|
|
10
|
+
/** Build-time locale (e.g. 'en', 'zh-CN'). Default: 'en'. */
|
|
11
|
+
locale?: string;
|
|
12
|
+
/** gh-pages branch name. Empty string = skip deploy. Default: ''. */
|
|
13
|
+
ghPagesBranch?: string;
|
|
14
|
+
/** Custom domain for CNAME file. Empty string = skip. Default: ''. */
|
|
15
|
+
cname?: string;
|
|
16
|
+
/** Webhook URL for post-build notifications. Empty string = skip. Default: ''. */
|
|
17
|
+
webhookUrl?: string;
|
|
18
|
+
/** Session IDs newly imported in this heartbeat cycle (for webhook). */
|
|
19
|
+
newSessionIds?: string[];
|
|
20
|
+
/** Absolute base URL for RSS/OG links (e.g. 'https://memory.example.com'). Empty = skip. */
|
|
21
|
+
reportBaseUrl?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Report build orchestrator.
|
|
26
|
+
* Generates a self-contained multi-page HTML website in Memory/07_reports/.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
declare function buildReport(options: BuildReportOptions): Promise<void>;
|
|
30
|
+
|
|
31
|
+
export { type BuildReportOptions, buildReport };
|