@treeseed/core 0.1.2 → 0.3.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/README.md +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/content-config.d.ts +10 -0
- package/dist/content.js +44 -10
- package/dist/contracts.d.ts +1 -130
- package/dist/deploy/config.d.ts +1 -4
- package/dist/deploy/config.js +4 -148
- package/dist/deploy/runtime.js +4 -0
- package/dist/env.yaml +86 -14
- package/dist/environment.d.ts +2 -130
- package/dist/environment.js +13 -311
- package/dist/index.js +2 -0
- package/dist/plugins/builtin/default-plugin.js +5 -0
- package/dist/plugins/constants.d.ts +1 -21
- package/dist/plugins/constants.js +5 -23
- package/dist/plugins/plugin.d.ts +2 -42
- package/dist/plugins/plugin.js +1 -3
- package/dist/plugins/runtime.d.ts +1 -0
- package/dist/plugins/runtime.js +21 -3
- package/dist/scripts/build-dist.js +5 -1
- package/dist/scripts/release-verify.js +1 -2
- package/dist/scripts/test-smoke.js +14 -3
- package/dist/scripts/workspace-bootstrap.js +153 -0
- package/dist/tenant/config.js +8 -116
- package/dist/utils/books-data.js +7 -75
- package/dist/utils/site-config-schema.js +1 -282
- package/package.json +10 -5
- package/templates/github/deploy.workflow.yml +1 -1
- package/dist/plugins/builtin/default-plugin.d.ts +0 -21
- package/dist/tenant/config.d.ts +0 -9
|
@@ -343,7 +343,7 @@ async function main() {
|
|
|
343
343
|
await compileModule(filePath, srcRoot, distRoot);
|
|
344
344
|
continue;
|
|
345
345
|
}
|
|
346
|
-
if (COPY_EXTENSIONS.has(extension)
|
|
346
|
+
if (COPY_EXTENSIONS.has(extension)) {
|
|
347
347
|
copyAsset(filePath, srcRoot, distRoot);
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -368,7 +368,11 @@ async function main() {
|
|
|
368
368
|
writeFileSync(filePath, rewriteTreeseedStarlightSpecifiers(contents, filePath), 'utf8');
|
|
369
369
|
}
|
|
370
370
|
writeCompatibilityEntrypoint(resolve(distRoot, 'config.js'), "import starlight from './vendor/starlight/index.js';\nimport { createTreeseedSite } from './site.js';\nimport { loadTreeseedManifest } from './tenant/config.js';\n\nexport function createTreeseedTenantSite(manifestPath) {\n\tconst tenant = loadTreeseedManifest(manifestPath);\n\treturn createTreeseedSite(tenant, { starlight });\n}");
|
|
371
|
+
writeCompatibilityEntrypoint(resolve(distRoot, 'config.d.ts'), "export declare function createTreeseedTenantSite(manifestPath?: string): import('astro').AstroUserConfig<never, never, never>;");
|
|
371
372
|
writeCompatibilityEntrypoint(resolve(distRoot, 'content-config.js'), "import { docsLoader } from './vendor/starlight/loaders.js';\nimport { docsSchema } from './vendor/starlight/schema.js';\nimport { createTreeseedCollections } from './content.js';\nimport { loadTreeseedManifest } from './tenant/config.js';\n\nexport function createTreeseedTenantCollections(manifestPath) {\n\tconst tenant = loadTreeseedManifest(manifestPath);\n\treturn createTreeseedCollections(tenant, { docsLoader, docsSchema });\n}");
|
|
373
|
+
writeCompatibilityEntrypoint(resolve(distRoot, 'content-config.d.ts'), "export declare function createTreeseedTenantCollections(manifestPath?: string): {\n\tpages: any;\n\tnotes: any;\n\tquestions: any;\n\tobjectives: any;\n\tpeople: any;\n\tagents: any;\n\tbooks: any;\n\tdocs: any;\n};");
|
|
374
|
+
rmSync(resolve(distRoot, 'config.d.js'), { force: true });
|
|
375
|
+
rmSync(resolve(distRoot, 'content-config.d.js'), { force: true });
|
|
372
376
|
writeCompatibilityEntrypoint(resolve(vendoredStarlightRoot, 'utils', 'routing.js'), "export * from './routing/index.js';");
|
|
373
377
|
copyAsset(resolve(packageRoot, 'tsconfigs/strict.json'), packageRoot, distRoot);
|
|
374
378
|
copyPackageAsset('@astrojs/mdx', 'template/content-module-types.d.ts', 'template/content-module-types.d.ts');
|
|
@@ -43,8 +43,7 @@ function scanDirectory(root) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
run('npm', ['run', '
|
|
47
|
-
run('npm', ['run', 'build:dist']);
|
|
46
|
+
run('npm', ['run', 'lint']);
|
|
48
47
|
scanDirectory(resolve(packageRoot, 'dist'));
|
|
49
48
|
run('npm', ['run', 'test:unit']);
|
|
50
49
|
run('npm', ['run', 'check']);
|
|
@@ -7,12 +7,17 @@ import { createRequire } from 'node:module';
|
|
|
7
7
|
import { packageRoot } from './package-tools.js';
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
const sdkPackageRoot = resolve(dirname(require.resolve('@treeseed/sdk')), '..');
|
|
10
|
+
const npmCacheDir = resolve(tmpdir(), 'treeseed-npm-cache');
|
|
10
11
|
function run(command, args, cwd = packageRoot, capture = false) {
|
|
11
12
|
const result = spawnSync(command, args, {
|
|
12
13
|
cwd,
|
|
13
14
|
stdio: capture ? 'pipe' : 'inherit',
|
|
14
15
|
encoding: 'utf8',
|
|
15
|
-
env:
|
|
16
|
+
env: {
|
|
17
|
+
...process.env,
|
|
18
|
+
npm_config_cache: npmCacheDir,
|
|
19
|
+
NPM_CONFIG_CACHE: npmCacheDir,
|
|
20
|
+
},
|
|
16
21
|
});
|
|
17
22
|
if (result.status !== 0) {
|
|
18
23
|
throw new Error(result.stderr?.trim() || result.stdout?.trim() || `${command} ${args.join(' ')} failed`);
|
|
@@ -61,12 +66,18 @@ function pack(root, outputRoot, fallbackName) {
|
|
|
61
66
|
return bundledTarball;
|
|
62
67
|
}
|
|
63
68
|
mkdirSync(outputRoot, { recursive: true });
|
|
64
|
-
const output = run('npm', ['pack', '--
|
|
69
|
+
const output = run('npm', ['pack', '--ignore-scripts', '--cache', npmCacheDir, '--pack-destination', outputRoot], root, true);
|
|
65
70
|
const filename = output
|
|
66
71
|
.split('\n')
|
|
67
72
|
.map((line) => line.trim())
|
|
68
73
|
.filter(Boolean)
|
|
69
|
-
.at(-1)
|
|
74
|
+
.at(-1)
|
|
75
|
+
?? readdirSync(outputRoot, { withFileTypes: true })
|
|
76
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.tgz'))
|
|
77
|
+
.map((entry) => entry.name)
|
|
78
|
+
.sort((left, right) => left.localeCompare(right, undefined, { numeric: true, sensitivity: 'base' }))
|
|
79
|
+
.at(-1)
|
|
80
|
+
?? fallbackName;
|
|
70
81
|
return resolve(outputRoot, filename);
|
|
71
82
|
}
|
|
72
83
|
function installPackageDirectory(tempRoot, packageRoot, folderName) {
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, symlinkSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { packageRoot } from './package-tools.js';
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const requiredPackages = [
|
|
10
|
+
{ name: '@treeseed/sdk', dir: 'packages/sdk', build: true },
|
|
11
|
+
{ name: '@treeseed/core', dir: 'packages/core', build: true },
|
|
12
|
+
{ name: '@treeseed/agent', dir: 'packages/agent', build: true },
|
|
13
|
+
{ name: '@treeseed/api', dir: 'packages/api', build: true },
|
|
14
|
+
{ name: '@treeseed/cli', dir: 'packages/cli', build: true, binName: 'treeseed' },
|
|
15
|
+
];
|
|
16
|
+
function packageState(root, entry) {
|
|
17
|
+
const dir = resolve(root, entry.dir);
|
|
18
|
+
const packageJsonPath = resolve(dir, 'package.json');
|
|
19
|
+
return {
|
|
20
|
+
...entry,
|
|
21
|
+
dir,
|
|
22
|
+
relativeDir: entry.dir,
|
|
23
|
+
packageJsonPath,
|
|
24
|
+
present: existsSync(dir) && existsSync(packageJsonPath),
|
|
25
|
+
dirExists: existsSync(dir),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function detectTreeseedBootstrapMode(startRoot = process.cwd()) {
|
|
29
|
+
const root = resolve(startRoot);
|
|
30
|
+
const forcedMode = process.env.TREESEED_BOOTSTRAP_MODE;
|
|
31
|
+
if (forcedMode === 'workspace' || forcedMode === 'registry') {
|
|
32
|
+
const packages = requiredPackages.map((entry) => packageState(root, entry));
|
|
33
|
+
return {
|
|
34
|
+
mode: forcedMode,
|
|
35
|
+
packages,
|
|
36
|
+
missing: packages.filter((entry) => !entry.present),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const packages = requiredPackages.map((entry) => packageState(root, entry));
|
|
40
|
+
const present = packages.filter((entry) => entry.present);
|
|
41
|
+
const partial = present.length > 0 && present.length < packages.length;
|
|
42
|
+
if (partial) {
|
|
43
|
+
return {
|
|
44
|
+
mode: 'partial',
|
|
45
|
+
packages,
|
|
46
|
+
missing: packages.filter((entry) => !entry.present),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
mode: present.length === packages.length ? 'workspace' : 'registry',
|
|
51
|
+
packages,
|
|
52
|
+
missing: packages.filter((entry) => !entry.present),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function run(command, args, options = {}) {
|
|
56
|
+
const result = spawnSync(command, args, {
|
|
57
|
+
cwd: options.cwd,
|
|
58
|
+
env: { ...process.env, ...(options.env ?? {}) },
|
|
59
|
+
stdio: 'inherit',
|
|
60
|
+
encoding: 'utf8',
|
|
61
|
+
});
|
|
62
|
+
if (result.status !== 0) {
|
|
63
|
+
const rendered = [command, ...args].join(' ');
|
|
64
|
+
throw new Error(`Command failed: ${rendered}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function resolvePackageBinary(packageName, binName = packageName, root = process.cwd()) {
|
|
68
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`, { paths: [root, packageRoot] });
|
|
69
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
70
|
+
const binField = packageJson.bin;
|
|
71
|
+
const relativePath = typeof binField === 'string' ? binField : binField?.[binName];
|
|
72
|
+
if (!relativePath) {
|
|
73
|
+
throw new Error(`Unable to resolve binary "${binName}" from package "${packageName}".`);
|
|
74
|
+
}
|
|
75
|
+
return resolve(dirname(packageJsonPath), relativePath);
|
|
76
|
+
}
|
|
77
|
+
function runStarlightPatchFromRegistry(root) {
|
|
78
|
+
const corePackageJsonPath = require.resolve('@treeseed/core/package.json', { paths: [root, packageRoot] });
|
|
79
|
+
const coreRoot = dirname(corePackageJsonPath);
|
|
80
|
+
const patchScriptPath = resolve(coreRoot, 'dist', 'scripts', 'patch-starlight-content-path.js');
|
|
81
|
+
if (existsSync(patchScriptPath)) {
|
|
82
|
+
run(process.execPath, [patchScriptPath], { cwd: root });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const treeseedBin = resolvePackageBinary('@treeseed/cli', 'treeseed', root);
|
|
86
|
+
run(process.execPath, [treeseedBin, 'starlight:patch'], { cwd: root });
|
|
87
|
+
}
|
|
88
|
+
function runStarlightPatchFromWorkspace(root, packages) {
|
|
89
|
+
const corePackage = packages.find((entry) => entry.name === '@treeseed/core');
|
|
90
|
+
run(process.execPath, [resolve(corePackage.dir, 'scripts/run-ts.mjs'), resolve(corePackage.dir, 'scripts/patch-starlight-content-path.ts')], { cwd: root });
|
|
91
|
+
}
|
|
92
|
+
function linkWorkspacePackages(root, packages) {
|
|
93
|
+
for (const targetRoot of [root, ...packages.map((entry) => entry.dir)]) {
|
|
94
|
+
const scopeRoot = resolve(targetRoot, 'node_modules/@treeseed');
|
|
95
|
+
mkdirSync(scopeRoot, { recursive: true });
|
|
96
|
+
for (const entry of packages) {
|
|
97
|
+
const linkPath = resolve(scopeRoot, entry.name.replace('@treeseed/', ''));
|
|
98
|
+
if (resolve(linkPath) === resolve(entry.dir)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
rmSync(linkPath, { recursive: true, force: true });
|
|
102
|
+
symlinkSync(entry.dir, linkPath, 'dir');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function printPartialError(state) {
|
|
107
|
+
const missing = state.missing.map((entry) => ` - ${entry.relativeDir}`).join('\n');
|
|
108
|
+
console.error('Treeseed bootstrap found a partial package checkout.');
|
|
109
|
+
console.error('');
|
|
110
|
+
console.error('Either initialize all Treeseed package submodules:');
|
|
111
|
+
console.error(' git submodule update --init --recursive');
|
|
112
|
+
console.error('');
|
|
113
|
+
console.error('Or remove the partial package checkout and use registry mode.');
|
|
114
|
+
console.error('');
|
|
115
|
+
console.error(`Missing package manifests:\n${missing}`);
|
|
116
|
+
}
|
|
117
|
+
export function runTreeseedWorkspaceBootstrap({ root = process.cwd() } = {}) {
|
|
118
|
+
const resolvedRoot = resolve(root);
|
|
119
|
+
const state = detectTreeseedBootstrapMode(resolvedRoot);
|
|
120
|
+
if (state.mode === 'partial') {
|
|
121
|
+
printPartialError(state);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
if (state.mode === 'workspace') {
|
|
125
|
+
console.log('Treeseed bootstrap mode: workspace (using checked-out packages/* submodules)');
|
|
126
|
+
linkWorkspacePackages(resolvedRoot, state.packages);
|
|
127
|
+
for (const entry of state.packages.filter((pkg) => pkg.build)) {
|
|
128
|
+
run('npm', ['--prefix', entry.dir, 'run', 'build:dist'], { cwd: resolvedRoot });
|
|
129
|
+
}
|
|
130
|
+
runStarlightPatchFromWorkspace(resolvedRoot, state.packages);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
console.log('Treeseed bootstrap mode: registry (using published @treeseed/* packages)');
|
|
134
|
+
runStarlightPatchFromRegistry(resolvedRoot);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
function isDirectEntrypoint() {
|
|
138
|
+
if (!process.argv[1]) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const invokedPath = realpathSync(resolve(process.argv[1]));
|
|
142
|
+
const modulePath = realpathSync(fileURLToPath(import.meta.url));
|
|
143
|
+
return modulePath === invokedPath || invokedPath.endsWith('/scripts/workspace-bootstrap.ts');
|
|
144
|
+
}
|
|
145
|
+
if (isDirectEntrypoint()) {
|
|
146
|
+
try {
|
|
147
|
+
process.exitCode = runTreeseedWorkspaceBootstrap();
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
151
|
+
process.exitCode = 1;
|
|
152
|
+
}
|
|
153
|
+
}
|
package/dist/tenant/config.js
CHANGED
|
@@ -1,119 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return resolve(dirname(fileURLToPath(moduleUrl)), "../..");
|
|
11
|
-
}
|
|
12
|
-
const packageRoot = resolvePackageRoot();
|
|
13
|
-
const packageFixtureRoot = resolve(packageRoot, ".fixtures", "treeseed-fixtures", "sites", "working-site");
|
|
14
|
-
const explicitTenantRoot = process.env.TREESEED_TENANT_ROOT ? resolve(process.env.TREESEED_TENANT_ROOT) : null;
|
|
15
|
-
function pathWithin(parent, candidate) {
|
|
16
|
-
const normalizedParent = resolve(parent);
|
|
17
|
-
const normalizedCandidate = resolve(candidate);
|
|
18
|
-
return normalizedCandidate === normalizedParent || normalizedCandidate.startsWith(`${normalizedParent}/`);
|
|
19
|
-
}
|
|
20
|
-
function collectTenantRootCandidates(start) {
|
|
21
|
-
const candidates = [];
|
|
22
|
-
let current = resolve(start);
|
|
23
|
-
while (true) {
|
|
24
|
-
candidates.push(
|
|
25
|
-
current,
|
|
26
|
-
resolve(current, ".fixtures", "treeseed-fixtures", "sites", "working-site"),
|
|
27
|
-
resolve(current, "fixture")
|
|
28
|
-
);
|
|
29
|
-
const parent = resolve(current, "..");
|
|
30
|
-
if (parent === current) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
current = parent;
|
|
34
|
-
}
|
|
35
|
-
return candidates;
|
|
36
|
-
}
|
|
37
|
-
function uniqueCandidates(entries) {
|
|
38
|
-
return [...new Set(entries.map((entry) => resolve(entry)))];
|
|
39
|
-
}
|
|
40
|
-
function tenantRootCandidates() {
|
|
41
|
-
const cwd = resolve(process.cwd());
|
|
42
|
-
const cwdCandidates = collectTenantRootCandidates(cwd);
|
|
43
|
-
const packageCandidates = collectTenantRootCandidates(packageRoot);
|
|
44
|
-
if (explicitTenantRoot) {
|
|
45
|
-
return uniqueCandidates([explicitTenantRoot, ...cwdCandidates, packageFixtureRoot, ...packageCandidates]);
|
|
46
|
-
}
|
|
47
|
-
if (pathWithin(packageRoot, cwd)) {
|
|
48
|
-
return uniqueCandidates([packageFixtureRoot, ...cwdCandidates, ...packageCandidates]);
|
|
49
|
-
}
|
|
50
|
-
return uniqueCandidates([...cwdCandidates, packageFixtureRoot, ...packageCandidates]);
|
|
51
|
-
}
|
|
52
|
-
function resolveTenantPath(manifestPath) {
|
|
53
|
-
if (existsSync(manifestPath)) {
|
|
54
|
-
return resolve(manifestPath);
|
|
55
|
-
}
|
|
56
|
-
const candidates = tenantRootCandidates().map((root) => resolve(root, manifestPath));
|
|
57
|
-
for (const candidate of candidates) {
|
|
58
|
-
if (existsSync(candidate)) {
|
|
59
|
-
return candidate;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Unable to resolve Treeseed tenant manifest at "${manifestPath}" from ${process.cwd()} or ${packageFixtureRoot}.`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function resolveTenantRoot() {
|
|
67
|
-
const candidates = tenantRootCandidates();
|
|
68
|
-
for (const candidate of candidates) {
|
|
69
|
-
if (existsSync(resolve(candidate, "src/manifest.yaml"))) {
|
|
70
|
-
return candidate;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Unable to resolve a Treeseed tenant root from ${process.cwd()} or ${packageFixtureRoot}.`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
function defineTreeseedTenant(tenantConfig) {
|
|
78
|
-
return tenantConfig;
|
|
79
|
-
}
|
|
80
|
-
function loadTreeseedManifest(manifestPath = "./src/manifest.yaml") {
|
|
81
|
-
const resolvedManifestPath = resolveTenantPath(manifestPath);
|
|
82
|
-
const tenantRoot = resolve(dirname(resolvedManifestPath), "..");
|
|
83
|
-
const parsed = parseYaml(readFileSync(resolvedManifestPath, "utf8"));
|
|
84
|
-
const tenantConfig = defineTreeseedTenant({
|
|
85
|
-
...parsed,
|
|
86
|
-
siteConfigPath: resolve(tenantRoot, parsed.siteConfigPath),
|
|
87
|
-
content: Object.fromEntries(
|
|
88
|
-
Object.entries(parsed.content ?? {}).map(([collectionName, rootPath]) => [
|
|
89
|
-
collectionName,
|
|
90
|
-
resolve(tenantRoot, String(rootPath))
|
|
91
|
-
])
|
|
92
|
-
),
|
|
93
|
-
overrides: parsed.overrides ? {
|
|
94
|
-
pagesRoot: parsed.overrides.pagesRoot ? resolve(tenantRoot, parsed.overrides.pagesRoot) : void 0,
|
|
95
|
-
stylesRoot: parsed.overrides.stylesRoot ? resolve(tenantRoot, parsed.overrides.stylesRoot) : void 0,
|
|
96
|
-
componentsRoot: parsed.overrides.componentsRoot ? resolve(tenantRoot, parsed.overrides.componentsRoot) : void 0
|
|
97
|
-
} : void 0
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(tenantConfig, "__tenantRoot", {
|
|
100
|
-
value: tenantRoot,
|
|
101
|
-
enumerable: false
|
|
102
|
-
});
|
|
103
|
-
return tenantConfig;
|
|
104
|
-
}
|
|
105
|
-
const loadTreeseedTenantManifest = loadTreeseedManifest;
|
|
106
|
-
const resolveTreeseedTenantRoot = resolveTenantRoot;
|
|
107
|
-
function getTenantContentRoot(tenantConfig, collectionName) {
|
|
108
|
-
const root = tenantConfig.content[collectionName];
|
|
109
|
-
if (!root) {
|
|
110
|
-
throw new Error(`Unknown tenant content collection: ${collectionName}`);
|
|
111
|
-
}
|
|
112
|
-
return root;
|
|
113
|
-
}
|
|
114
|
-
function tenantFeatureEnabled(tenantConfig, featureName) {
|
|
115
|
-
return tenantConfig.features?.[featureName] !== false;
|
|
116
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
defineTreeseedTenant,
|
|
3
|
+
getTenantContentRoot,
|
|
4
|
+
loadTreeseedManifest,
|
|
5
|
+
loadTreeseedTenantManifest,
|
|
6
|
+
resolveTreeseedTenantRoot,
|
|
7
|
+
tenantFeatureEnabled
|
|
8
|
+
} from "@treeseed/sdk/platform/tenant-config";
|
|
117
9
|
export {
|
|
118
10
|
defineTreeseedTenant,
|
|
119
11
|
getTenantContentRoot,
|
package/dist/utils/books-data.js
CHANGED
|
@@ -1,78 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
function collectMarkdownFiles(rootPath) {
|
|
10
|
-
const stats = statSync(rootPath);
|
|
11
|
-
if (stats.isFile()) {
|
|
12
|
-
return [rootPath];
|
|
13
|
-
}
|
|
14
|
-
return sortPaths(
|
|
15
|
-
readdirSync(rootPath, { withFileTypes: true }).flatMap((entry) => {
|
|
16
|
-
const fullPath = path.join(rootPath, entry.name);
|
|
17
|
-
if (entry.isDirectory()) {
|
|
18
|
-
return collectMarkdownFiles(fullPath);
|
|
19
|
-
}
|
|
20
|
-
if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
21
|
-
return [fullPath];
|
|
22
|
-
}
|
|
23
|
-
return [];
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
function parseFrontmatter(filePath) {
|
|
28
|
-
const raw = readFileSync(filePath, "utf8");
|
|
29
|
-
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
30
|
-
if (!match) {
|
|
31
|
-
throw new Error(`Book content entry is missing frontmatter: ${filePath}`);
|
|
32
|
-
}
|
|
33
|
-
return parseYaml(match[1]);
|
|
34
|
-
}
|
|
35
|
-
function inferDocsLibraryDownload(book) {
|
|
36
|
-
const title = book?.title ? `${book.title} Library` : "Knowledge Library";
|
|
37
|
-
return {
|
|
38
|
-
downloadFileName: "treeseed-knowledge.md",
|
|
39
|
-
downloadHref: "/books/treeseed-knowledge.md",
|
|
40
|
-
downloadTitle: title
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function buildTenantBookRuntime(tenantConfig, options = {}) {
|
|
44
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
45
|
-
const booksContentRoot = path.resolve(projectRoot, getTenantContentRoot(tenantConfig, "books"));
|
|
46
|
-
const books = collectMarkdownFiles(booksContentRoot).map((filePath) => {
|
|
47
|
-
const frontmatter = parseFrontmatter(filePath);
|
|
48
|
-
return {
|
|
49
|
-
...frontmatter,
|
|
50
|
-
id: path.basename(filePath, path.extname(filePath))
|
|
51
|
-
};
|
|
52
|
-
}).sort((left, right) => left.order - right.order);
|
|
53
|
-
const docsHomePath = options.docsHomePath ?? "/knowledge/";
|
|
54
|
-
const docsLibraryDownload = options.docsLibraryDownload ?? inferDocsLibraryDownload(tenantConfig);
|
|
55
|
-
return {
|
|
56
|
-
BOOKS: books,
|
|
57
|
-
BOOKS_LINK: {
|
|
58
|
-
label: "Books",
|
|
59
|
-
link: docsHomePath
|
|
60
|
-
},
|
|
61
|
-
TREESEED_LINKS: {
|
|
62
|
-
home: docsHomePath
|
|
63
|
-
},
|
|
64
|
-
TREESEED_LIBRARY_DOWNLOAD: docsLibraryDownload
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const runtime = buildTenantBookRuntime(RUNTIME_TENANT, {
|
|
68
|
-
projectRoot: RUNTIME_PROJECT_ROOT,
|
|
69
|
-
docsLibraryDownload: {
|
|
70
|
-
downloadFileName: "treeseed-knowledge.md",
|
|
71
|
-
downloadHref: "/books/treeseed-knowledge.md",
|
|
72
|
-
downloadTitle: "TreeSeed Knowledge Library"
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const { BOOKS, BOOKS_LINK, TREESEED_LINKS, TREESEED_LIBRARY_DOWNLOAD } = runtime;
|
|
1
|
+
import {
|
|
2
|
+
BOOKS,
|
|
3
|
+
BOOKS_LINK,
|
|
4
|
+
TREESEED_LIBRARY_DOWNLOAD,
|
|
5
|
+
TREESEED_LINKS,
|
|
6
|
+
buildTenantBookRuntime
|
|
7
|
+
} from "@treeseed/sdk/platform/books-data";
|
|
76
8
|
export {
|
|
77
9
|
BOOKS,
|
|
78
10
|
BOOKS_LINK,
|