Skip to content

docs(docs-infra): generate llms-full at build time #61864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion adev/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ APPLICATION_ASSETS = [
]

APPLICATION_DEPS = [
"//adev/scripts/shared:generate_llms_full",
"@npm//@angular/docs",
"@npm//@angular/build",
"@npm//@angular-devkit/build-angular",
Expand Down Expand Up @@ -161,6 +162,7 @@ architect(
chdir = "$(RULEDIR)",
data = ensure_local_package_deps(APPLICATION_DEPS) + APPLICATION_ASSETS + [
":application_files_bin",
"//adev/scripts/shared:generate_llms_full",
],
env = config_based_architect_env,
# Network is required to inline fonts.
Expand All @@ -178,7 +180,9 @@ http_server(
],
enable_dev_ui = True,
relax_cors = True,
deps = [":build"],
deps = [
":build",
],
)

architect_test(
Expand Down
34 changes: 34 additions & 0 deletions adev/scripts/shared/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load("//tools:defaults2.bzl", "ts_config", "ts_project")

package(default_visibility = ["//visibility:public"])

ts_config(
name = "tsconfig_build",
src = "tsconfig.json",
deps = ["//tools:tsconfig_build"],
)

filegroup(
name = "llms_src",
srcs = ["llms-list.md"],
visibility = ["//visibility:public"],
)

ts_project(
name = "llms_lib",
srcs = ["llms.mts"],
tsconfig = ":tsconfig_build",
deps = [":llms_src"],
)

js_binary(
name = "generate_llms_full",
data = [
"llms.mjs",
"llms-list.md",
":llms_lib_rjs",
"//adev/src/content:guide_files",
],
entry_point = ":llms.mjs",
)
36 changes: 19 additions & 17 deletions adev/scripts/shared/llms.mjs → adev/scripts/shared/llms.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
// Run with `node adev/scripts/shared/llms.mjs` to generate llms-full.txt from the list in llms-list.md

//tslint:disable:no-console
import fs from 'fs/promises';
import path from 'path';
import {readFile, writeFile} from 'fs/promises';
import {resolve, dirname} from 'path';

const INPUT_MD_FILENAME = 'adev/scripts/shared/llms-list.md';
const OUTPUT_FILENAME = 'adev/src/llms-full.txt';

function postProcessOutputContent(content) {
function postProcessOutputContent(content: string) {
// Helper to map custom languages to standard Markdown languages
const mapLanguage = (lang) => {
const mapLanguage = (lang: string) => {
if (!lang) return ''; // For code blocks without a specified language
const lowerLang = lang.trim().toLowerCase();
if (lowerLang === 'angular-ts') return 'typescript';
Expand Down Expand Up @@ -88,21 +88,21 @@ function postProcessOutputContent(content) {
}

async function main() {
const inputFilePath = path.resolve(process.cwd(), INPUT_MD_FILENAME);
const baseDirForIncludes = path.dirname(inputFilePath);
const inputFilePath = resolve(process.cwd(), INPUT_MD_FILENAME);
const baseDirForIncludes = dirname(inputFilePath);

console.log(`Starting processing of: ${inputFilePath}`);

let mainFileContent;
let mainFileContent: string;
try {
mainFileContent = await fs.readFile(inputFilePath, 'utf-8');
} catch (error) {
mainFileContent = await readFile(inputFilePath, 'utf-8');
} catch (error: any) {
console.error(`Error: Failed to read input file "${inputFilePath}".`);
console.error(error.message);
process.exit(1); // Exit with error code
}

let processedContent = mainFileContent;
let processedContent: string = mainFileContent;
const matches = [...mainFileContent.matchAll(/(.*\.md)/g)];

console.log(`Found ${matches.length} files`);
Expand All @@ -111,26 +111,28 @@ async function main() {

for (const match of matches) {
const filePath = match[0];
const absolutePathToIncludeFile = path.resolve(filePath);
const absolutePathToIncludeFile = resolve(filePath);

try {
console.log(` Including content from: ${absolutePathToIncludeFile}`);
const includedFileContent = await fs.readFile(absolutePathToIncludeFile, 'utf-8');
const includedFileContent = await readFile(absolutePathToIncludeFile, 'utf-8');
const processedFile = postProcessOutputContent(includedFileContent);
resultString += processedFile; // Append the content of the included file
} catch (fileReadError) {
console.warn(` Warning: Could not read file "${absolutePathToIncludeFile}"`);
} catch (fileReadError: any) {
console.warn(
` Warning: Could not read file "${absolutePathToIncludeFile}" - ${fileReadError.message}`,
);
}
}

// Basic cleanup of blank lines
processedContent = resultString.replace(/(?:\s*\n){3,}/g, '\n');

const outputFilePath = path.resolve(process.cwd(), OUTPUT_FILENAME);
const outputFilePath = resolve(process.cwd(), OUTPUT_FILENAME);
try {
await fs.writeFile(outputFilePath, processedContent, 'utf-8');
await writeFile(outputFilePath, processedContent, 'utf-8');
console.log(`Successfully generated combined file: ${outputFilePath}`);
} catch (error) {
} catch (error: any) {
console.error(`Error: Failed to write output file "${outputFilePath}".`);
console.error(error.message);
process.exit(1); // Exit with error code
Expand Down
13 changes: 13 additions & 0 deletions adev/scripts/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"declaration": true,
"sourceMap": true,
"module": "esnext",
"moduleResolution": "node",
"target": "esnext",
"types": ["node"],
"paths": {}
}
}
13 changes: 13 additions & 0 deletions adev/src/content/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "content",
Expand All @@ -8,3 +9,15 @@ generate_guides(
data = [],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = [
"//adev/src/content/best-practices:guide_files",
"//adev/src/content/ecosystem:guide_files",
"//adev/src/content/guide:guide_files",
"//adev/src/content/introduction:guide_files",
"//adev/src/content/reference:guide_files",
] + glob(["**/*.md"]),
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions adev/src/content/best-practices/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//adev/shared-docs:index.bzl", "generate_guides")

generate_guides(
Expand All @@ -11,3 +12,9 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/ecosystem/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "ecosystem",
Expand All @@ -7,3 +8,9 @@ generate_guides(
]),
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = ["//adev/src/content/ecosystem/rxjs-interop:guide_files"] + glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/ecosystem/rxjs-interop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "rxjs-interop",
Expand All @@ -7,3 +8,9 @@ generate_guides(
]),
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
20 changes: 20 additions & 0 deletions adev/src/content/guide/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "guide",
Expand All @@ -10,3 +11,22 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = [
"//adev/src/content/guide/animations:guide_files",
"//adev/src/content/guide/components:guide_files",
"//adev/src/content/guide/di:guide_files",
"//adev/src/content/guide/directives:guide_files",
"//adev/src/content/guide/forms:guide_files",
"//adev/src/content/guide/http:guide_files",
"//adev/src/content/guide/i18n:guide_files",
"//adev/src/content/guide/performance:guide_files",
"//adev/src/content/guide/routing:guide_files",
"//adev/src/content/guide/signals:guide_files",
"//adev/src/content/guide/templates:guide_files",
"//adev/src/content/guide/testing:guide_files",
] + glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/animations/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "animations",
Expand All @@ -10,3 +11,9 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/components/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "components",
Expand All @@ -11,3 +12,9 @@ generate_guides(
mermaid_blocks = True,
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/di/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "di",
Expand All @@ -12,3 +13,9 @@ generate_guides(
mermaid_blocks = True,
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/directives/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "directives",
Expand All @@ -11,3 +12,9 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/forms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "forms",
Expand All @@ -12,3 +13,9 @@ generate_guides(
mermaid_blocks = True,
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/http/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "http",
Expand All @@ -7,3 +8,9 @@ generate_guides(
]),
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/i18n/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "i18n",
Expand All @@ -10,3 +11,9 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
7 changes: 7 additions & 0 deletions adev/src/content/guide/ngmodules/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//adev/shared-docs:index.bzl", "generate_guides")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

generate_guides(
name = "ngmodules",
Expand All @@ -9,3 +10,9 @@ generate_guides(
],
visibility = ["//adev:__subpackages__"],
)

js_library(
name = "guide_files",
srcs = glob(["**/*.md"]),
visibility = ["//adev:__subpackages__"],
)
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy