Skip to content

Commit 6512dbf

Browse files
committed
export as ./templates.exported
1 parent 516a96c commit 6512dbf

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

packages/inference/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
src/snippets/templates.generated.ts
1+
src/snippets/templates.exported.ts

packages/inference/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
},
4141
"type": "module",
4242
"scripts": {
43-
"prebuild": "tsx scripts/generate-templates.ts",
44-
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
43+
"build": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
4544
"dts": "tsx scripts/generate-dts.ts && tsc --noEmit dist/index.d.ts",
4645
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
4746
"lint:check": "eslint --ext .cjs,.ts .",
@@ -52,7 +51,8 @@
5251
"test": "vitest run --config vitest.config.mts",
5352
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest.config.mts",
5453
"check": "tsc",
55-
"dev": "tsup src/index.ts --format cjs,esm --watch"
54+
"dev": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --watch",
55+
"export-templates": "tsx scripts/export-templates.ts"
5656
},
5757
"dependencies": {
5858
"@huggingface/tasks": "workspace:^",

packages/inference/scripts/generate-templates.ts renamed to packages/inference/scripts/export-templates.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
/* Script that export all jinja files from packages/inference/src/snippets/templates into a TS module.
2+
3+
Templates are exported in packages/inference/src/snippets/templates.exported.ts.
4+
*/
15
import { readFileSync, writeFileSync, readdirSync } from "node:fs";
26
import path from "node:path";
37

48
const TEMPLATES_DIR = path.join(process.cwd(), "src", "snippets", "templates");
59

6-
function generateTemplatesCode(): string {
10+
function exportTemplatesAsCode(): string {
711
/// language -> client -> templateName -> templateContent
812
const templates: Record<string, Record<string, Record<string, string>>> = {};
913

@@ -44,7 +48,7 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
4448
}
4549

4650
// Generate and write the templates file
47-
const output = generateTemplatesCode();
48-
const outputPath = path.join(process.cwd(), "src", "snippets", "templates.generated.ts")
51+
const output = exportTemplatesAsCode();
52+
const outputPath = path.join(process.cwd(), "src", "snippets", "templates.exported.ts");
4953
writeFileSync(outputPath, output);
50-
console.log("Templates generated successfully! 🚀");
54+
console.log("Templates exported successfully! 🚀");

packages/inference/src/snippets/getInferenceSnippets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import type { InferenceProvider, InferenceTask, RequestArgs } from "../types";
1111
import { Template } from "@huggingface/jinja";
1212
import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions";
13-
import { templates } from "./templates.generated";
13+
import { templates } from "./templates.exported";
1414

1515
const PYTHON_CLIENTS = ["huggingface_hub", "fal_client", "requests", "openai"] as const;
1616
const JS_CLIENTS = ["fetch", "huggingface.js", "openai"] as const;

0 commit comments

Comments
 (0)