@enhansome/core 1.10.0 → 1.10.1
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/dist/github.d.ts +5 -4
- package/dist/github.js +7 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/markdown.d.ts +2 -3
- package/dist/markdown.js +8 -28
- package/dist/orchestrator.d.ts +2 -3
- package/dist/orchestrator.js +2 -2
- package/package.json +1 -1
package/dist/github.d.ts
CHANGED
|
@@ -77,11 +77,12 @@ export interface MakeOctokitOptions {
|
|
|
77
77
|
export declare function makeOctokit(token: string, { log, maxRetries, maxWaitSeconds, throttle, }?: MakeOctokitOptions): GithubClient;
|
|
78
78
|
export declare function getRepoInfo(octokit: GithubClient, owner: string, repo: string): Promise<RepoInfoDetails>;
|
|
79
79
|
/**
|
|
80
|
-
* The repo's
|
|
81
|
-
* node ids on
|
|
82
|
-
* metadata
|
|
80
|
+
* The repo's full info, for the JSON metadata — the numeric id consumers key
|
|
81
|
+
* stable node ids on, plus the stars/language/last_commit the root's own
|
|
82
|
+
* metadata row is built from. Returns null (logged) instead of failing the
|
|
83
|
+
* run: metadata is not a gate; consumers fall back when it is missing.
|
|
83
84
|
*/
|
|
84
|
-
export declare function
|
|
85
|
+
export declare function getRepoInfoOrNull(octokit: GithubClient, owner: string, repo: string): Promise<null | RepoInfoDetails>;
|
|
85
86
|
export declare function getReadme(octokit: GithubClient, owner: string, repo: string, format?: 'html' | 'raw'): Promise<string>;
|
|
86
87
|
/** Root file/directory names — the compile-manifest gate reads them to tell a
|
|
87
88
|
* directory of resources from a repo that IS the deliverable. A `path: ''`
|
package/dist/github.js
CHANGED
|
@@ -83,16 +83,17 @@ export async function getRepoInfo(octokit, owner, repo) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* The repo's
|
|
87
|
-
* node ids on
|
|
88
|
-
* metadata
|
|
86
|
+
* The repo's full info, for the JSON metadata — the numeric id consumers key
|
|
87
|
+
* stable node ids on, plus the stars/language/last_commit the root's own
|
|
88
|
+
* metadata row is built from. Returns null (logged) instead of failing the
|
|
89
|
+
* run: metadata is not a gate; consumers fall back when it is missing.
|
|
89
90
|
*/
|
|
90
|
-
export async function
|
|
91
|
+
export async function getRepoInfoOrNull(octokit, owner, repo) {
|
|
91
92
|
try {
|
|
92
|
-
return
|
|
93
|
+
return await getRepoInfo(octokit, owner, repo);
|
|
93
94
|
}
|
|
94
95
|
catch (error) {
|
|
95
|
-
octokit.log.error(`Failed to fetch repo
|
|
96
|
+
octokit.log.error(`Failed to fetch repo info for ${owner}/${repo}: ${formatRequestError(error)}`);
|
|
96
97
|
return null;
|
|
97
98
|
}
|
|
98
99
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formatRequestError, getLatestCommitSha, getReadme,
|
|
1
|
+
export { formatRequestError, getLatestCommitSha, getReadme, getRepoInfo, getRepoInfoOrNull, getRootEntryNames, makeOctokit, parseGitHubUrl, parseOwnerRepo, } from './github.js';
|
|
2
2
|
export type { GithubClient, MakeOctokitOptions, RepoIdentifier, RepoInfoDetails, ThrottleOptions, } from './github.js';
|
|
3
3
|
export type { Logger } from './logger.js';
|
|
4
4
|
export { consoleLog, silentLog } from './logger.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formatRequestError, getLatestCommitSha, getReadme,
|
|
1
|
+
export { formatRequestError, getLatestCommitSha, getReadme, getRepoInfo, getRepoInfoOrNull, getRootEntryNames, makeOctokit, parseGitHubUrl, parseOwnerRepo, } from './github.js';
|
|
2
2
|
export { consoleLog, silentLog } from './logger.js';
|
|
3
3
|
export { toRepoInfo } from './markdown.js';
|
|
4
4
|
export { enhance } from './orchestrator.js';
|
package/dist/markdown.d.ts
CHANGED
|
@@ -45,8 +45,7 @@ export interface JsonMetadata {
|
|
|
45
45
|
enhanced_repository: null | string;
|
|
46
46
|
enhanced_repository_description: null | string;
|
|
47
47
|
last_updated: string;
|
|
48
|
-
|
|
49
|
-
original_repository_id: null | number;
|
|
48
|
+
original_repository_info: null | RepoInfo;
|
|
50
49
|
original_repository_sha: null | string;
|
|
51
50
|
title: string;
|
|
52
51
|
}
|
|
@@ -55,7 +54,7 @@ export interface JsonSection {
|
|
|
55
54
|
items: JsonNode[];
|
|
56
55
|
title: string;
|
|
57
56
|
}
|
|
58
|
-
export declare function processMarkdownContent(originalContent: string, token: string, replacements
|
|
57
|
+
export declare function processMarkdownContent(originalContent: string, token: string, replacements?: ReplacementRule[], sortOptions?: SortOptions, relativeLinkPrefix?: string, enhancedRepository?: string, enhancedRepositoryDescription?: string, originalRepositorySha?: string, originalRepositoryInfo?: null | RepoInfoDetails, now?: Date, log?: Logger): Promise<{
|
|
59
58
|
finalContent: string;
|
|
60
59
|
jsonData: JsonOutput;
|
|
61
60
|
}>;
|
package/dist/markdown.js
CHANGED
|
@@ -79,7 +79,7 @@ async function fetchTargetData(urls, repos) {
|
|
|
79
79
|
log.info(`Target fetch: ${repoInfoMap.size}/${urls.size} repo-info ok in ${Date.now() - fetchStart}ms (concurrency ${FETCH_CONCURRENCY}).`);
|
|
80
80
|
return repoInfoMap;
|
|
81
81
|
}
|
|
82
|
-
export async function processMarkdownContent(originalContent, token, replacements = [], sortOptions = { by: '', minLinks: 2 },
|
|
82
|
+
export async function processMarkdownContent(originalContent, token, replacements = [], sortOptions = { by: '', minLinks: 2 }, relativeLinkPrefix = '', enhancedRepository, enhancedRepositoryDescription, originalRepositorySha, originalRepositoryInfo, now = new Date(), log = consoleLog) {
|
|
83
83
|
const repos = createRepoInfoLookup(token, log);
|
|
84
84
|
const brandingEnabled = replacements.some(rule => rule.type === 'branding');
|
|
85
85
|
const contentAfterReplacements = applyTextReplacements(originalContent, replacements.filter(rule => rule.type !== 'branding'), log);
|
|
@@ -88,9 +88,7 @@ export async function processMarkdownContent(originalContent, token, replacement
|
|
|
88
88
|
normalizeGitHubUrls(tree);
|
|
89
89
|
const githubUrls = collectGitHubLinks(tree);
|
|
90
90
|
const repoInfoMap = await fetchTargetData(githubUrls, repos);
|
|
91
|
-
|
|
92
|
-
// the enhanced/mirror repo — otherwise the org name doubles into the title.
|
|
93
|
-
const { sections, title: rawTitle, titleHeadingIndex, } = processTree(tree, repoInfoMap, sortOptions, originalRepository);
|
|
91
|
+
const { sections, title: rawTitle, titleHeadingIndex, } = processTree(tree, repoInfoMap, sortOptions, originalRepositoryInfo);
|
|
94
92
|
// Single source of truth for the document title: brand it once and use the
|
|
95
93
|
// same value for the markdown H1 and metadata.title (parity).
|
|
96
94
|
const title = brandingEnabled ? brandTitle(rawTitle) : rawTitle;
|
|
@@ -99,8 +97,9 @@ export async function processMarkdownContent(originalContent, token, replacement
|
|
|
99
97
|
}
|
|
100
98
|
const metadata = {
|
|
101
99
|
last_updated: now.toISOString(),
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
original_repository_info: originalRepositoryInfo
|
|
101
|
+
? toRepoInfo(originalRepositoryInfo)
|
|
102
|
+
: null,
|
|
104
103
|
original_repository_sha: (originalRepositorySha?.trim() ?? '') || null,
|
|
105
104
|
enhanced_repository: (enhancedRepository?.trim() ?? '') || null,
|
|
106
105
|
enhanced_repository_description: (enhancedRepositoryDescription?.trim() ?? '') || null,
|
|
@@ -812,22 +811,6 @@ const INVALID_TITLE_PATTERNS = [
|
|
|
812
811
|
/^video$/i,
|
|
813
812
|
/^science/i,
|
|
814
813
|
];
|
|
815
|
-
function repoNameFromIdentifier(identifier) {
|
|
816
|
-
const trimmed = identifier.trim();
|
|
817
|
-
if (!trimmed) {
|
|
818
|
-
return '';
|
|
819
|
-
}
|
|
820
|
-
if (/^https?:\/\//i.test(trimmed)) {
|
|
821
|
-
const parts = trimmed
|
|
822
|
-
.replace(/\.git$/i, '')
|
|
823
|
-
.replace(/[?#].*$/, '')
|
|
824
|
-
.split('/')
|
|
825
|
-
.filter(Boolean);
|
|
826
|
-
return parts[parts.length - 1] ?? '';
|
|
827
|
-
}
|
|
828
|
-
const slashIndex = trimmed.lastIndexOf('/');
|
|
829
|
-
return slashIndex === -1 ? trimmed : trimmed.slice(slashIndex + 1);
|
|
830
|
-
}
|
|
831
814
|
function formatRepoNameAsTitle(repoName) {
|
|
832
815
|
const cleaned = repoName.replace(/[-_]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
833
816
|
if (/^awesome\s+/i.test(cleaned)) {
|
|
@@ -911,7 +894,7 @@ function applyBrandingToTree(tree, title, titleHeadingIndex) {
|
|
|
911
894
|
tree.children.unshift(heading);
|
|
912
895
|
}
|
|
913
896
|
}
|
|
914
|
-
function processTree(tree, repoInfoMap, sortOptions,
|
|
897
|
+
function processTree(tree, repoInfoMap, sortOptions, originalRepositoryInfo) {
|
|
915
898
|
// Remember the title H1's index so branding replaces the exact same node;
|
|
916
899
|
// scope matches branding/section-building so they can't drift apart.
|
|
917
900
|
const titleHeadingIndex = findTitleHeadingIndex(tree);
|
|
@@ -922,11 +905,8 @@ function processTree(tree, repoInfoMap, sortOptions, originalRepository) {
|
|
|
922
905
|
// Derive a subject from the *source* repository name when no valid H1 is
|
|
923
906
|
// present. Using the source — not the enhanced/mirror repo — keeps the org
|
|
924
907
|
// name out of the title.
|
|
925
|
-
if (documentTitle === '' &&
|
|
926
|
-
|
|
927
|
-
if (repoName) {
|
|
928
|
-
documentTitle = formatRepoNameAsTitle(repoName);
|
|
929
|
-
}
|
|
908
|
+
if (documentTitle === '' && originalRepositoryInfo) {
|
|
909
|
+
documentTitle = formatRepoNameAsTitle(originalRepositoryInfo.repo);
|
|
930
910
|
}
|
|
931
911
|
const sectionDepth = findSectionDepth(tree, titleSlotIndex);
|
|
932
912
|
const gateForSection = sectionGatePasses(tree, titleSlotIndex, sectionDepth, repoInfoMap, sortOptions);
|
package/dist/orchestrator.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from './logger.js';
|
|
2
|
+
import type { RepoInfoDetails } from './github.js';
|
|
2
3
|
import { JsonOutput, ReplacementRule } from './markdown.js';
|
|
3
4
|
export interface EnhanceOptions {
|
|
4
5
|
content: string;
|
|
@@ -8,11 +9,9 @@ export interface EnhanceOptions {
|
|
|
8
9
|
/** Defaults to the console sink; pass your own (e.g. an Actions workflow-command sink) to route diagnostics. */
|
|
9
10
|
log?: Logger;
|
|
10
11
|
now?: Date;
|
|
11
|
-
|
|
12
|
-
originalRepositoryId?: number;
|
|
12
|
+
originalRepositoryInfo?: null | RepoInfoDetails;
|
|
13
13
|
originalRepositorySha?: string;
|
|
14
14
|
relativeLinkPrefix?: string;
|
|
15
|
-
/** Text substitutions applied to the source before it is parsed. */
|
|
16
15
|
replacements?: ReplacementRule[];
|
|
17
16
|
sortBy?: '' | 'last_commit' | 'stars';
|
|
18
17
|
token: string;
|
package/dist/orchestrator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { processMarkdownContent, } from './markdown.js';
|
|
2
2
|
export async function enhance(options) {
|
|
3
|
-
const { content, disableBranding = false, log, now = new Date(),
|
|
3
|
+
const { content, disableBranding = false, log, now = new Date(), originalRepositoryInfo, originalRepositorySha, relativeLinkPrefix = '', replacements = [], sortBy = '', enhancedRepository, enhancedRepositoryDescription, token, } = options;
|
|
4
4
|
// Branding is an internal rule prepended to the caller's own; build a fresh
|
|
5
5
|
// array so the caller's `replacements` is never mutated.
|
|
6
6
|
const branding = { type: 'branding' };
|
|
@@ -9,7 +9,7 @@ export async function enhance(options) {
|
|
|
9
9
|
by: sortBy,
|
|
10
10
|
minLinks: 2,
|
|
11
11
|
};
|
|
12
|
-
const { finalContent, jsonData } = await processMarkdownContent(content, token, rules, sortOptions,
|
|
12
|
+
const { finalContent, jsonData } = await processMarkdownContent(content, token, rules, sortOptions, relativeLinkPrefix, enhancedRepository, enhancedRepositoryDescription, originalRepositorySha, originalRepositoryInfo, now, log);
|
|
13
13
|
return {
|
|
14
14
|
finalContent,
|
|
15
15
|
jsonData,
|