@gitpagedocs/cli 1.1.44
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/README.md +169 -0
- package/ai/application/ai-command.ts +24 -0
- package/ai/application/ai-provider-factory.ts +22 -0
- package/ai/application/run-ai-cli-command.ts +136 -0
- package/ai/config.ts +22 -0
- package/ai/core/models/ai-cli-config.ts +31 -0
- package/ai/core/ports/illm-provider.ts +32 -0
- package/ai/infrastructure/ai-config-file.ts +32 -0
- package/ai/infrastructure/file-system-adapter.ts +83 -0
- package/ai/infrastructure/llm/tools-llm-provider.ts +54 -0
- package/ai/presentation/ai-prompts.ts +239 -0
- package/application/config-only/handler.mjs +55 -0
- package/application/home/handler.mjs +83 -0
- package/application/ports/cli-runtime-ports.ts +87 -0
- package/application/report/config-only-reporter.mjs +62 -0
- package/application/use-cases/dispatch-mode.ts +18 -0
- package/builders/config-orchestrator.mjs +40 -0
- package/builders/root-config-builder.mjs +54 -0
- package/builders/route-builders.mjs +111 -0
- package/builders/source-viewer.mjs +330 -0
- package/builders/theme-template.mjs +75 -0
- package/builders/version-config-builder.mjs +151 -0
- package/content/docs-en.mjs +542 -0
- package/content/docs-es.mjs +459 -0
- package/content/docs-pt.mjs +459 -0
- package/content/docs.mjs +9 -0
- package/contracts/doc-versions.mjs +1 -0
- package/contracts/index.mjs +1 -0
- package/data/default-site-config.mjs +312 -0
- package/data/i18n-langmenu.mjs +122 -0
- package/data/i18n-translations.mjs +20 -0
- package/data/layouts.mjs +353 -0
- package/data/path-mappings.mjs +34 -0
- package/data/route-metas.mjs +73 -0
- package/data/theme-colors.mjs +387 -0
- package/data/urls.mjs +7 -0
- package/data/version-constants.mjs +3 -0
- package/domain/models/cli-options.ts +18 -0
- package/domain/services/sanitize-segment.mjs +7 -0
- package/home/constants.mjs +4 -0
- package/home/home-file-writer.mjs +20 -0
- package/home/templates.mjs +48 -0
- package/index.mjs +26 -0
- package/infrastructure/config-only/runtime.mjs +17 -0
- package/infrastructure/home/runtime.mjs +37 -0
- package/package.json +60 -0
- package/presentation/commands/ai-info.ts +57 -0
- package/presentation/commands/config-info.ts +24 -0
- package/presentation/commands/diagnostics.ts +70 -0
- package/presentation/commands/docs.ts +37 -0
- package/presentation/commands/mcp.ts +20 -0
- package/presentation/commands/pages.ts +91 -0
- package/presentation/commands/run-command.ts +62 -0
- package/presentation/index.ts +108 -0
- package/presentation/options/parser.ts +104 -0
- package/presentation/options/resolver.ts +25 -0
- package/presentation/options/schema.ts +10 -0
- package/presentation/ui/banner.ts +13 -0
- package/presentation/ui/clack.ts +74 -0
- package/presentation/ui/prompts.ts +64 -0
- package/runtime/doc-path-resolver.mjs +57 -0
- package/runtime/git-ops.mjs +110 -0
- package/runtime/output.mjs +122 -0
- package/runtime/workflow.mjs +144 -0
- package/start.mjs +12 -0
- package/ui/logger.mjs +9 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin, cancellation-aware wrappers over @clack/prompts. Centralizes the
|
|
3
|
+
* isCancel handling so prompt modules stay declarative and a Ctrl-C exits
|
|
4
|
+
* cleanly (mirroring the previous inquirer behaviour).
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
text,
|
|
8
|
+
confirm,
|
|
9
|
+
select,
|
|
10
|
+
multiselect,
|
|
11
|
+
isCancel,
|
|
12
|
+
cancel,
|
|
13
|
+
} from "@clack/prompts";
|
|
14
|
+
|
|
15
|
+
function exitIfCancelled<T>(value: T | symbol): T {
|
|
16
|
+
if (isCancel(value)) {
|
|
17
|
+
cancel("Operation cancelled.");
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
return value as T;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AskTextOptions {
|
|
24
|
+
message: string;
|
|
25
|
+
defaultValue?: string;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
validate?: (value: string) => string | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function askText(options: AskTextOptions): Promise<string> {
|
|
31
|
+
const result = await text({
|
|
32
|
+
message: options.message,
|
|
33
|
+
placeholder: options.placeholder,
|
|
34
|
+
defaultValue: options.defaultValue,
|
|
35
|
+
initialValue: undefined,
|
|
36
|
+
validate: options.validate
|
|
37
|
+
? (value) => options.validate?.(value ?? "")
|
|
38
|
+
: undefined,
|
|
39
|
+
});
|
|
40
|
+
return exitIfCancelled(result);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function askConfirm(message: string, initialValue = false): Promise<boolean> {
|
|
44
|
+
const result = await confirm({ message, initialValue });
|
|
45
|
+
return exitIfCancelled(result);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Choice<T extends string> {
|
|
49
|
+
value: T;
|
|
50
|
+
label: string;
|
|
51
|
+
hint?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function askSelect<T extends string>(
|
|
55
|
+
message: string,
|
|
56
|
+
options: Choice<T>[],
|
|
57
|
+
initialValue?: T,
|
|
58
|
+
): Promise<T> {
|
|
59
|
+
// clack's Option<Value> is a conditional type TS can't match against a generic
|
|
60
|
+
// Choice<T> (identical shape); cast at the boundary, inference flows from initialValue.
|
|
61
|
+
const result = await select<T>({ message, options: options as never, initialValue });
|
|
62
|
+
return exitIfCancelled(result);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function askMultiSelect<T extends string>(
|
|
66
|
+
message: string,
|
|
67
|
+
options: Choice<T>[],
|
|
68
|
+
initialValues?: T[],
|
|
69
|
+
): Promise<T[]> {
|
|
70
|
+
const result = await multiselect<T>({ message, options: options as never, initialValues, required: true });
|
|
71
|
+
return exitIfCancelled(result);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { intro, outro, note, spinner } from "@clack/prompts";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CliOptions } from "../../domain/models/cli-options";
|
|
2
|
+
import { DEFAULTS } from "../options/schema";
|
|
3
|
+
import { askText, askConfirm } from "./clack";
|
|
4
|
+
|
|
5
|
+
function isCiOrNonTty(): boolean {
|
|
6
|
+
if (process.env.CI === "true") return true;
|
|
7
|
+
if (process.env.GITHUB_ACTIONS === "true") return true;
|
|
8
|
+
if (process.stdin && !process.stdin.isTTY) return true;
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function shouldRunInteractive(argv: string[]): boolean {
|
|
13
|
+
if (isCiOrNonTty()) return false;
|
|
14
|
+
const args = argv.slice(2);
|
|
15
|
+
if (args.includes("--interactive") || args.includes("-i")) return true;
|
|
16
|
+
if (args.length === 0) return true;
|
|
17
|
+
if (args.length === 1 && args[0] === "--home") return true;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function promptHomeOptions(parsed: CliOptions): Promise<CliOptions> {
|
|
22
|
+
const outputDir = await askText({
|
|
23
|
+
message: "Output directory:",
|
|
24
|
+
defaultValue: parsed.outputDir ?? DEFAULTS.home.outputDir,
|
|
25
|
+
validate: (v) => (v && v.trim() ? undefined : "Required"),
|
|
26
|
+
});
|
|
27
|
+
const repositorySearch = await askConfirm(
|
|
28
|
+
"Enable repository search home?",
|
|
29
|
+
parsed.repositorySearch ?? DEFAULTS.repositorySearch,
|
|
30
|
+
);
|
|
31
|
+
const basePath = await askText({
|
|
32
|
+
message: "Base path (e.g. git-page-docs, empty for root):",
|
|
33
|
+
defaultValue: parsed.basePath ?? DEFAULTS.basePath,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...parsed,
|
|
38
|
+
outputDir: outputDir.trim(),
|
|
39
|
+
repositorySearch,
|
|
40
|
+
basePath: basePath?.trim() ?? "",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function promptConfigOnlyOptions(parsed: CliOptions): Promise<CliOptions> {
|
|
45
|
+
const useLocalLayoutConfig = await askConfirm(
|
|
46
|
+
"Generate local layout templates?",
|
|
47
|
+
parsed.useLocalLayoutConfig ?? false,
|
|
48
|
+
);
|
|
49
|
+
const githubOwner = await askText({
|
|
50
|
+
message: "GitHub owner (optional):",
|
|
51
|
+
defaultValue: parsed.githubOwner ?? "",
|
|
52
|
+
});
|
|
53
|
+
const githubRepo = await askText({
|
|
54
|
+
message: "GitHub repo (optional):",
|
|
55
|
+
defaultValue: parsed.githubRepo ?? "",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...parsed,
|
|
60
|
+
useLocalLayoutConfig,
|
|
61
|
+
githubOwner: githubOwner?.trim() ?? "",
|
|
62
|
+
githubRepo: githubRepo?.trim() ?? "",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Map doc paths to content keys and apply version badges */
|
|
2
|
+
|
|
3
|
+
export function parseDocFileToKey(fileName) {
|
|
4
|
+
if (fileName === "index.md") return "index";
|
|
5
|
+
if (fileName === "getting-started.md") return "gettingStarted";
|
|
6
|
+
if (fileName === "configuration.md") return "configuration";
|
|
7
|
+
if (fileName === "deployment.md") return "deployment";
|
|
8
|
+
if (fileName === "architecture.md") return "architecture";
|
|
9
|
+
if (fileName === "themes.md") return "themes";
|
|
10
|
+
if (fileName === "faq.md") return "faq";
|
|
11
|
+
if (fileName === "project-overview.md") return "projectOverview";
|
|
12
|
+
if (fileName === "functionalities.md") return "functionalities";
|
|
13
|
+
if (fileName === "github-issues-projects.md") return "githubIssuesProjects";
|
|
14
|
+
if (fileName === "git-introduction.md") return "gitIntroduction";
|
|
15
|
+
if (fileName === "authorized-routes.md") return "authorizedRoutes";
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function parseHtmlFileToKey(fileName) {
|
|
20
|
+
const base = fileName.replace(/\.html$/, "");
|
|
21
|
+
if (base === "source-viewer") return "sourceViewer";
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function extractLanguageFromPath(docPath) {
|
|
26
|
+
const match = docPath.match(/\/(pt|en|es)\//);
|
|
27
|
+
return match?.[1];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function withVersionBadge(content, versionId, language) {
|
|
31
|
+
const normalized = typeof content === "string" ? content : "";
|
|
32
|
+
if (!normalized.trim()) {
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const alreadyTagged =
|
|
37
|
+
normalized.includes(`Version: ${versionId}`) ||
|
|
38
|
+
normalized.includes(`Versao: ${versionId}`) ||
|
|
39
|
+
normalized.includes(`Version (ES): ${versionId}`);
|
|
40
|
+
if (alreadyTagged) {
|
|
41
|
+
return normalized;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const label =
|
|
45
|
+
language === "pt"
|
|
46
|
+
? `> Versao: ${versionId}`
|
|
47
|
+
: language === "es"
|
|
48
|
+
? `> Version (ES): ${versionId}`
|
|
49
|
+
: `> Version: ${versionId}`;
|
|
50
|
+
|
|
51
|
+
return `${normalized.trimEnd()}\n\n${label}\n`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function normalizeToOutputPath(outputDir, configPath) {
|
|
55
|
+
const normalized = configPath.replace(/^gitpagedocs\//, "");
|
|
56
|
+
return `${outputDir}/${normalized}`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
/** Detect { owner, repo } from the git `origin` remote URL, or null. */
|
|
6
|
+
export function detectRepoFromGit(root) {
|
|
7
|
+
try {
|
|
8
|
+
const url = execSync("git remote get-url origin", { cwd: root, stdio: "pipe" }).toString().trim();
|
|
9
|
+
const match = url.match(/[:/]([^/:]+)\/([^/]+?)(?:\.git)?$/);
|
|
10
|
+
if (match) return { owner: match[1], repo: match[2] };
|
|
11
|
+
} catch {
|
|
12
|
+
// no remote / not a repo
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function tryConfigurePagesToGitHubActions(owner, repo, branch, root) {
|
|
18
|
+
try {
|
|
19
|
+
execSync("gh --version", { cwd: root, stdio: "ignore" });
|
|
20
|
+
} catch {
|
|
21
|
+
console.warn(
|
|
22
|
+
"GitHub CLI (gh) not found. Could not auto-configure Pages source. Set GitHub Pages source to 'GitHub Actions' manually in repository settings.",
|
|
23
|
+
);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const candidates = [
|
|
28
|
+
`gh api -X PUT "repos/${owner}/${repo}/pages" -f build_type=workflow`,
|
|
29
|
+
`gh api -X POST "repos/${owner}/${repo}/pages" -f build_type=workflow`,
|
|
30
|
+
`gh api -X POST "repos/${owner}/${repo}/pages" -f source[branch]=${branch} -f source[path]=/`,
|
|
31
|
+
`gh api -X PUT "repos/${owner}/${repo}/pages" -f source[branch]=${branch} -f source[path]=/ -f build_type=workflow`,
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
for (const command of candidates) {
|
|
35
|
+
try {
|
|
36
|
+
execSync(command, { cwd: root, stdio: "ignore" });
|
|
37
|
+
console.log("GitHub Pages source configured for GitHub Actions.");
|
|
38
|
+
return;
|
|
39
|
+
} catch {
|
|
40
|
+
// Try next candidate endpoint.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.warn(
|
|
45
|
+
"Could not auto-configure Pages source through GitHub API. Set repository Pages source to 'GitHub Actions' manually.",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getCurrentGitBranch(root) {
|
|
50
|
+
try {
|
|
51
|
+
const branch = execSync("git branch --show-current", { cwd: root, stdio: "pipe" }).toString().trim();
|
|
52
|
+
return branch || "main";
|
|
53
|
+
} catch {
|
|
54
|
+
return "main";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function runGitPushForGeneratedArtifacts(options, root, sanitizeSegment) {
|
|
59
|
+
const owner = sanitizeSegment(options.githubOwner);
|
|
60
|
+
const repo = sanitizeSegment(options.githubRepo);
|
|
61
|
+
if (!owner || !repo) {
|
|
62
|
+
throw new Error("`--push` requires owner and repo. Use `--owner <owner> --repo <repo>` or `--<owner> --<repo>`.");
|
|
63
|
+
}
|
|
64
|
+
if (!existsSync(path.join(root, ".git"))) {
|
|
65
|
+
throw new Error("Current directory is not a git repository. Initialize git before using --push.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const repoUrl = `https://github.com/${owner}/${repo}.git`;
|
|
69
|
+
try {
|
|
70
|
+
execSync("git remote get-url origin", { cwd: root, stdio: "ignore" });
|
|
71
|
+
} catch {
|
|
72
|
+
execSync(`git remote add origin "${repoUrl}"`, { cwd: root, stdio: "inherit" });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
execSync('git add "gitpagedocs" ".github/workflows/gitpagedocs-pages.yml"', { cwd: root, stdio: "inherit" });
|
|
76
|
+
|
|
77
|
+
let hasStagedChanges = false;
|
|
78
|
+
try {
|
|
79
|
+
execSync("git diff --cached --quiet", { cwd: root, stdio: "ignore" });
|
|
80
|
+
hasStagedChanges = false;
|
|
81
|
+
} catch {
|
|
82
|
+
hasStagedChanges = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!hasStagedChanges) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
execSync('git commit -m "chore: setup gitpagedocs pages workflow"', { cwd: root, stdio: "inherit" });
|
|
90
|
+
|
|
91
|
+
const currentBranch = getCurrentGitBranch(root);
|
|
92
|
+
try {
|
|
93
|
+
execSync(`git push -u origin ${currentBranch}`, { cwd: root, stdio: "inherit" });
|
|
94
|
+
tryConfigurePagesToGitHubActions(owner, repo, currentBranch, root);
|
|
95
|
+
return;
|
|
96
|
+
} catch {
|
|
97
|
+
console.warn("Initial push failed. Trying automatic rebase with remote branch...");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
execSync(`git pull --rebase origin ${currentBranch}`, { cwd: root, stdio: "inherit" });
|
|
102
|
+
execSync(`git push -u origin ${currentBranch}`, { cwd: root, stdio: "inherit" });
|
|
103
|
+
} catch {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Failed to push after automatic rebase on branch '${currentBranch}'. Resolve conflicts and run 'git push -u origin ${currentBranch}' manually.`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
tryConfigurePagesToGitHubActions(owner, repo, currentBranch, root);
|
|
110
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { existsSync, rmSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
parseDocFileToKey,
|
|
6
|
+
parseHtmlFileToKey,
|
|
7
|
+
extractLanguageFromPath,
|
|
8
|
+
withVersionBadge,
|
|
9
|
+
normalizeToOutputPath,
|
|
10
|
+
} from "./doc-path-resolver.mjs";
|
|
11
|
+
|
|
12
|
+
/** True when `child` is the same as, or nested inside, `parent` (path-safe). */
|
|
13
|
+
function isWithin(parent, child) {
|
|
14
|
+
const rel = path.relative(parent, child);
|
|
15
|
+
return !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DEFAULT_ICON_SVG = `<?xml version="1.0" encoding="utf-8"?>
|
|
19
|
+
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
20
|
+
<path opacity="0.1" fill-rule="evenodd" clip-rule="evenodd" d="M12 3C4.5885 3 3 4.5885 3 12C3 19.4115 4.5885 21 12 21C19.4115 21 21 19.4115 21 12C21 4.5885 19.4115 3 12 3ZM14.2695 9.03471C15.1872 8.34452 15.7204 8.25293 15.9299 8.25017C16.1326 8.86788 16.1588 9.54654 16.0042 10.1835C15.9945 10.2234 15.9842 10.263 15.9731 10.3025C15.941 10.4168 15.9647 10.5393 16.0366 10.6333L16.0377 10.6347C16.0521 10.6537 16.0664 10.6728 16.0805 10.6922C16.5194 11.2949 16.7603 12.0687 16.7497 12.8714L16.7496 12.8747C16.7496 14.5738 16.3076 15.5644 15.6994 16.1583C15.0859 16.7572 14.2627 16.9938 13.4137 17.0968L13.3898 17.0997L13.3777 17.1014C12.443 17.2601 11.5456 17.2688 10.6078 17.1286L10.604 17.1281L10.5687 17.1233C9.72415 17.0085 8.90483 16.7616 8.29455 16.1566C7.68912 15.5564 7.25036 14.5643 7.25038 12.8747L7.25034 12.8714C7.23972 12.0687 7.48056 11.2949 7.91949 10.6922C7.93482 10.6711 7.9504 10.6503 7.96621 10.6297C8.03648 10.538 8.05962 10.4184 8.02812 10.3068L8.02599 10.2993C8.01523 10.2608 8.00513 10.2222 7.99569 10.1834C7.84087 9.54684 7.86561 8.86863 8.0659 8.25016C8.27679 8.2528 8.81228 8.34432 9.73045 9.03473C9.76619 9.0616 9.80249 9.08937 9.83937 9.11807C9.93139 9.19 10.0529 9.21205 10.1644 9.17703L10.1657 9.17661C10.2268 9.15768 10.2882 9.13972 10.3496 9.12272C11.4349 8.82255 12.5651 8.82255 13.6504 9.12272C13.7088 9.13888 13.7671 9.15592 13.8253 9.17382L13.8277 9.17457C13.9431 9.21015 14.0704 9.18836 14.1678 9.11252C14.2022 9.08578 14.2361 9.05985 14.2695 9.03471Z" fill="#323232"/>
|
|
21
|
+
<path d="M13.717 8.88177C12.5881 8.56954 11.4119 8.56954 10.283 8.88177C10.2637 8.8871 10.2444 8.89254 10.2252 8.89808C10.1067 8.93218 9.97923 8.909 9.8807 8.83491V8.83491C8.69311 7.94193 8.07278 7.98181 7.91927 8.01161V8.01161C7.8946 8.0164 7.87585 8.03481 7.86732 8.05844C7.86516 8.06441 7.86303 8.07038 7.8609 8.07636C7.61639 8.76505 7.57904 9.52813 7.75277 10.2425C7.76289 10.2841 7.77371 10.3255 7.78525 10.3667C7.78601 10.3694 7.78677 10.3721 7.78753 10.3748C7.79754 10.4102 7.7902 10.4483 7.7678 10.4776V10.4776C7.75074 10.4998 7.73394 10.5223 7.71741 10.545C7.24479 11.1939 6.98907 12.0213 7.00036 12.8747C7.00036 16.3399 8.80396 17.1358 10.535 17.3711L10.5708 17.3758C11.5347 17.5199 12.4587 17.511 13.4195 17.3479L13.4438 17.345C15.1832 17.1339 16.9996 16.3587 16.9996 12.8747C17.0109 12.0213 16.7552 11.1939 16.2826 10.545C16.2674 10.5242 16.252 10.5035 16.2364 10.483C16.236 10.4825 16.2356 10.482 16.2352 10.4815C16.211 10.4498 16.203 10.4085 16.2138 10.3701V10.3701C16.2257 10.3277 16.2368 10.2852 16.2471 10.2425C16.421 9.52611 16.3815 8.76076 16.1329 8.07176C16.1313 8.06753 16.1298 8.06331 16.1283 8.05909C16.1195 8.03503 16.1004 8.01628 16.0752 8.01142V8.01142C15.921 7.98164 15.3041 7.94381 14.1193 8.83491V8.83491C14.0208 8.90896 13.8933 8.93197 13.7748 8.89804C13.7556 8.89252 13.7363 8.8871 13.717 8.88177Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
22
|
+
<path d="M3 12C3 4.5885 4.5885 3 12 3C19.4115 3 21 4.5885 21 12C21 19.4115 19.4115 21 12 21C4.5885 21 3 19.4115 3 12Z" stroke="#323232" stroke-width="2"/>
|
|
23
|
+
</svg>
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
async function writeJson(root, relativePath, data) {
|
|
27
|
+
const absolutePath = path.join(root, relativePath);
|
|
28
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
29
|
+
await writeFile(absolutePath, `${JSON.stringify(data, null, 2)}\n`, "utf-8");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function writeText(root, relativePath, data) {
|
|
33
|
+
const absolutePath = path.join(root, relativePath);
|
|
34
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
35
|
+
await writeFile(absolutePath, data, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function writeConfigOnlyOutput(options) {
|
|
39
|
+
const {
|
|
40
|
+
root,
|
|
41
|
+
pkgRoot,
|
|
42
|
+
outputDir,
|
|
43
|
+
artifacts,
|
|
44
|
+
useLocalLayoutConfig,
|
|
45
|
+
layouts,
|
|
46
|
+
createThemeTemplate,
|
|
47
|
+
} = options;
|
|
48
|
+
|
|
49
|
+
// Keep only versioned docs output in docs/, removing legacy root language folders.
|
|
50
|
+
for (const legacyLanguageDir of ["en", "pt", "es"]) {
|
|
51
|
+
const legacyPath = path.join(root, outputDir, "docs", legacyLanguageDir);
|
|
52
|
+
if (existsSync(legacyPath)) {
|
|
53
|
+
rmSync(legacyPath, { recursive: true, force: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await writeJson(root, `${outputDir}/config.json`, artifacts.rootConfig);
|
|
58
|
+
await writeText(root, `${outputDir}/icon.svg`, DEFAULT_ICON_SVG);
|
|
59
|
+
const layoutsPath = path.join(root, outputDir, "layouts");
|
|
60
|
+
if (useLocalLayoutConfig) {
|
|
61
|
+
await writeJson(root, `${outputDir}/layouts/layoutsConfig.json`, artifacts.layoutsConfig);
|
|
62
|
+
await writeJson(root, `${outputDir}/layouts/layoutsFallbackConfig.json`, artifacts.fallbackLayoutsConfig);
|
|
63
|
+
for (const layout of layouts) {
|
|
64
|
+
const template = createThemeTemplate(layout);
|
|
65
|
+
await writeJson(root, `${outputDir}/layouts/${layout.file}`, template);
|
|
66
|
+
}
|
|
67
|
+
} else if (existsSync(layoutsPath) && !isWithin(root, pkgRoot)) {
|
|
68
|
+
// Only clean a stale local layouts/ when the CLI runs from OUTSIDE the
|
|
69
|
+
// project (a real install) — never when pkgRoot is inside the project being
|
|
70
|
+
// generated (the gitpagedocs source repo), so committed layouts survive.
|
|
71
|
+
rmSync(layoutsPath, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const [versionId, versionConfig] of Object.entries(artifacts.versionConfigs)) {
|
|
75
|
+
await writeJson(root, `${outputDir}/docs/versions/${versionId}/config.json`, versionConfig);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const [versionId, versionConfig] of Object.entries(artifacts.versionConfigs)) {
|
|
79
|
+
const versionRoutesMd = versionConfig["routes-md"] ?? versionConfig.routes ?? [];
|
|
80
|
+
for (const route of versionRoutesMd) {
|
|
81
|
+
for (const docPath of Object.values(route.path ?? {})) {
|
|
82
|
+
const fileName = path.basename(docPath);
|
|
83
|
+
const key = parseDocFileToKey(fileName);
|
|
84
|
+
const language = extractLanguageFromPath(docPath);
|
|
85
|
+
const content = key && language ? artifacts.docs?.[language]?.[key] : undefined;
|
|
86
|
+
if (!content) continue;
|
|
87
|
+
const versionedContent = withVersionBadge(content, versionId, language);
|
|
88
|
+
await writeText(root, normalizeToOutputPath(outputDir, docPath), versionedContent);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const versionRoutesHtml = versionConfig["routes-html"] ?? [];
|
|
93
|
+
const docsHtml = artifacts.docsHtml ?? {};
|
|
94
|
+
for (const route of versionRoutesHtml) {
|
|
95
|
+
if (route.url) continue;
|
|
96
|
+
for (const docPath of Object.values(route.path ?? {})) {
|
|
97
|
+
const fileName = path.basename(docPath);
|
|
98
|
+
const key = parseHtmlFileToKey(fileName);
|
|
99
|
+
const language = extractLanguageFromPath(docPath);
|
|
100
|
+
const content = key && language ? docsHtml[key]?.[language] : undefined;
|
|
101
|
+
if (!content) continue;
|
|
102
|
+
const normalizedHtmlPath = normalizeToOutputPath(outputDir, docPath);
|
|
103
|
+
await writeText(root, normalizedHtmlPath, content);
|
|
104
|
+
// Backward-compatible alias for tools or users that still expect ".html".
|
|
105
|
+
if (!path.extname(docPath)) {
|
|
106
|
+
await writeText(root, `${normalizedHtmlPath}.html`, content);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Ensure version folders always include an index file.
|
|
112
|
+
for (const language of ["pt", "en", "es"]) {
|
|
113
|
+
const fallbackIndex = artifacts.docs?.[language]?.index;
|
|
114
|
+
if (!fallbackIndex) continue;
|
|
115
|
+
const versionIndexPath = `${outputDir}/docs/versions/${versionId}/${language}/index.md`;
|
|
116
|
+
if (!existsSync(path.join(root, versionIndexPath))) {
|
|
117
|
+
const versionedFallbackIndex = withVersionBadge(fallbackIndex, versionId, language);
|
|
118
|
+
await writeText(root, versionIndexPath, versionedFallbackIndex);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
function sanitizeDocsPath(docsPath) {
|
|
2
|
+
if (!docsPath || typeof docsPath !== "string") return "";
|
|
3
|
+
const segment = docsPath.replace(/^\/+|\/+$/g, "").trim();
|
|
4
|
+
return /^[A-Za-z0-9._-]+$/.test(segment) ? segment : "";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function ensureGitHubPagesWorkflow(getCurrentGitBranch, writeText, docsPath = "") {
|
|
8
|
+
const pathSegment = sanitizeDocsPath(docsPath);
|
|
9
|
+
const buildStepsBlock =
|
|
10
|
+
pathSegment
|
|
11
|
+
? ` - name: Build static site with target repository path
|
|
12
|
+
run: pnpm exec next build frontend && mv frontend/out out
|
|
13
|
+
working-directory: .gitpagedocs-runtime
|
|
14
|
+
env:
|
|
15
|
+
GITHUB_ACTIONS: "true"
|
|
16
|
+
GITHUB_REPOSITORY: \${{ github.repository }}
|
|
17
|
+
GITPAGEDOCS_PATH: "${pathSegment}"
|
|
18
|
+
|
|
19
|
+
- name: Relocate output to custom docs path
|
|
20
|
+
run: |
|
|
21
|
+
mkdir -p .gitpagedocs-runtime/out_new/${pathSegment}
|
|
22
|
+
mv .gitpagedocs-runtime/out/* .gitpagedocs-runtime/out_new/${pathSegment}/
|
|
23
|
+
rm -rf .gitpagedocs-runtime/out
|
|
24
|
+
mv .gitpagedocs-runtime/out_new .gitpagedocs-runtime/out`
|
|
25
|
+
: ` - name: Build static site with target repository path
|
|
26
|
+
run: pnpm exec next build frontend && mv frontend/out out
|
|
27
|
+
working-directory: .gitpagedocs-runtime
|
|
28
|
+
env:
|
|
29
|
+
GITHUB_ACTIONS: "true"
|
|
30
|
+
GITHUB_REPOSITORY: \${{ github.repository }}`;
|
|
31
|
+
const currentBranch = getCurrentGitBranch();
|
|
32
|
+
const workflowPath = ".github/workflows/gitpagedocs-pages.yml";
|
|
33
|
+
const workflowContent = `name: Deploy GitPageDocs
|
|
34
|
+
|
|
35
|
+
on:
|
|
36
|
+
push:
|
|
37
|
+
branches: ["${currentBranch}"]
|
|
38
|
+
workflow_dispatch:
|
|
39
|
+
|
|
40
|
+
permissions:
|
|
41
|
+
contents: read
|
|
42
|
+
pages: write
|
|
43
|
+
id-token: write
|
|
44
|
+
|
|
45
|
+
concurrency:
|
|
46
|
+
group: "pages"
|
|
47
|
+
cancel-in-progress: true
|
|
48
|
+
|
|
49
|
+
jobs:
|
|
50
|
+
build:
|
|
51
|
+
runs-on: ubuntu-latest
|
|
52
|
+
steps:
|
|
53
|
+
- name: Checkout target repository
|
|
54
|
+
uses: actions/checkout@v4
|
|
55
|
+
|
|
56
|
+
- name: Setup pnpm
|
|
57
|
+
uses: pnpm/action-setup@v4
|
|
58
|
+
|
|
59
|
+
- name: Setup Node
|
|
60
|
+
uses: actions/setup-node@v4
|
|
61
|
+
with:
|
|
62
|
+
node-version: "20"
|
|
63
|
+
|
|
64
|
+
- name: Setup Pages
|
|
65
|
+
uses: actions/configure-pages@v5
|
|
66
|
+
|
|
67
|
+
- name: Prepare runtime source
|
|
68
|
+
run: |
|
|
69
|
+
git clone --depth 1 https://github.com/Vidigal-code/git-page-docs.git .gitpagedocs-runtime
|
|
70
|
+
cp .gitpagedocs-runtime/gitpagedocs/icon.svg /tmp/default-icon.svg 2>/dev/null || true
|
|
71
|
+
if [ -d gitpagedocs ]; then
|
|
72
|
+
rm -rf .gitpagedocs-runtime/gitpagedocs
|
|
73
|
+
cp -R gitpagedocs .gitpagedocs-runtime/gitpagedocs
|
|
74
|
+
fi
|
|
75
|
+
mkdir -p .gitpagedocs-runtime/public
|
|
76
|
+
if [ -f icon.svg ]; then
|
|
77
|
+
cp icon.svg .gitpagedocs-runtime/public/icon.svg
|
|
78
|
+
elif [ -f gitpagedocs/icon.svg ]; then
|
|
79
|
+
cp gitpagedocs/icon.svg .gitpagedocs-runtime/public/icon.svg
|
|
80
|
+
elif [ -f /tmp/default-icon.svg ]; then
|
|
81
|
+
cp /tmp/default-icon.svg .gitpagedocs-runtime/public/icon.svg
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
- name: Install runtime dependencies
|
|
85
|
+
run: pnpm install --frozen-lockfile
|
|
86
|
+
working-directory: .gitpagedocs-runtime
|
|
87
|
+
|
|
88
|
+
${buildStepsBlock}
|
|
89
|
+
|
|
90
|
+
- name: Force root URL to docs entrypoint
|
|
91
|
+
env:
|
|
92
|
+
GITHUB_REPOSITORY: \${{ github.repository }}
|
|
93
|
+
run: |
|
|
94
|
+
node <<'NODE'
|
|
95
|
+
const fs = require('fs');
|
|
96
|
+
const path = require('path');
|
|
97
|
+
const pathSegment = ${JSON.stringify(pathSegment)};
|
|
98
|
+
const repoName = (process.env.GITHUB_REPOSITORY || '').split('/')[1] || '';
|
|
99
|
+
const isUserPage = repoName.toLowerCase().endsWith('.github.io');
|
|
100
|
+
const rootRedirectBase = pathSegment;
|
|
101
|
+
const cfgPath = path.join('.gitpagedocs-runtime', 'gitpagedocs', 'config.json');
|
|
102
|
+
if (!fs.existsSync(cfgPath)) process.exit(0);
|
|
103
|
+
const cfg = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
|
|
104
|
+
const defaultVersion = cfg?.site?.docsVersion || cfg?.VersionControl?.versions?.[0]?.id || '1.1.0';
|
|
105
|
+
const defaultLang = cfg?.site?.defaultLanguage || 'en';
|
|
106
|
+
const redirectTargetRoot = rootRedirectBase
|
|
107
|
+
? './' + rootRedirectBase + '/v/' + defaultVersion + '/?lang=' + defaultLang
|
|
108
|
+
: './v/' + defaultVersion + '/?lang=' + defaultLang;
|
|
109
|
+
const redirectTargetProject = './v/' + defaultVersion + '/?lang=' + defaultLang;
|
|
110
|
+
const rootHtml = '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=' + redirectTargetRoot + '"/><script>window.location.replace("' + redirectTargetRoot + '" + (window.location.search || ""));</script></head><body>Redirecting...</body></html>';
|
|
111
|
+
fs.writeFileSync(path.join('.gitpagedocs-runtime', 'out', 'index.html'), rootHtml);
|
|
112
|
+
const projectPathSegments = [];
|
|
113
|
+
if (repoName && !isUserPage) projectPathSegments.push(repoName);
|
|
114
|
+
if (pathSegment) projectPathSegments.push(pathSegment);
|
|
115
|
+
if (projectPathSegments.length > 0) {
|
|
116
|
+
const projectIndexPath = path.join('.gitpagedocs-runtime', 'out', ...projectPathSegments, 'index.html');
|
|
117
|
+
if (fs.existsSync(path.dirname(projectIndexPath))) {
|
|
118
|
+
const projectHtml = '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=' + redirectTargetProject + '"/><script>window.location.replace("' + redirectTargetProject + '" + (window.location.search || ""));</script></head><body>Redirecting...</body></html>';
|
|
119
|
+
fs.writeFileSync(projectIndexPath, projectHtml);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
NODE
|
|
123
|
+
|
|
124
|
+
- name: Add .nojekyll
|
|
125
|
+
run: touch .gitpagedocs-runtime/out/.nojekyll 2>/dev/null || mkdir -p .gitpagedocs-runtime/out && touch .gitpagedocs-runtime/out/.nojekyll
|
|
126
|
+
|
|
127
|
+
- name: Upload artifact
|
|
128
|
+
uses: actions/upload-pages-artifact@v3
|
|
129
|
+
with:
|
|
130
|
+
path: ./.gitpagedocs-runtime/out
|
|
131
|
+
|
|
132
|
+
deploy:
|
|
133
|
+
environment:
|
|
134
|
+
name: github-pages
|
|
135
|
+
url: \${{ steps.deployment.outputs.page_url }}
|
|
136
|
+
runs-on: ubuntu-latest
|
|
137
|
+
needs: build
|
|
138
|
+
steps:
|
|
139
|
+
- name: Deploy to GitHub Pages
|
|
140
|
+
id: deployment
|
|
141
|
+
uses: actions/deploy-pages@v4
|
|
142
|
+
`;
|
|
143
|
+
await writeText(workflowPath, workflowContent);
|
|
144
|
+
}
|
package/start.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
|
|
4
|
+
const env = { ...process.env, GITPAGEDOCS_REPOSITORY_SEARCH: "false" };
|
|
5
|
+
// The Next app lives in frontend/, so `next build` emits to frontend/.next —
|
|
6
|
+
// point `next start` at the same directory (matches `next build frontend`).
|
|
7
|
+
const child = spawn("npx", ["next", "start", "frontend"], {
|
|
8
|
+
stdio: "inherit",
|
|
9
|
+
env,
|
|
10
|
+
shell: true,
|
|
11
|
+
});
|
|
12
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|