diff --git a/create-app.ts b/create-app.ts index 2e7f4c6ed6902d91a2017230ab7b7fa50cdc9820..65ff0a9f7cbda75dc85e1f57bd65f5bbc7d04c54 100644 --- a/create-app.ts +++ b/create-app.ts @@ -9,8 +9,8 @@ import { makeDir } from "./helpers/make-dir"; import fs from "fs"; import terminalLink from "terminal-link"; -import type { InstallTemplateArgs } from "./templates"; -import { installTemplate } from "./templates"; +import type { InstallTemplateArgs } from "./helpers"; +import { installTemplate } from "./helpers"; export type InstallAppArgs = Omit< InstallTemplateArgs, @@ -94,7 +94,7 @@ export async function createApp({ }); // copy readme for fullstack await fs.promises.copyFile( - path.join(__dirname, "templates", "README-fullstack.md"), + path.join(__dirname, "..", "templates", "README-fullstack.md"), path.join(root, "README.md"), ); } else { diff --git a/e2e/basic.spec.ts b/e2e/basic.spec.ts index 861f5416c1ff4b34e7871f85104f989c69530d81..3e76f5267859a3ab4bbc0ceab981715734ca6c1d 100644 --- a/e2e/basic.spec.ts +++ b/e2e/basic.spec.ts @@ -8,7 +8,7 @@ import type { TemplateFramework, TemplateType, TemplateUI, -} from "../templates"; +} from "../helpers"; import { createTestDir, runApp, runCreateLlama, type AppType } from "./utils"; const templateTypes: TemplateType[] = ["streaming", "simple"]; diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..e45598cbae2c75c1440d718e6638bd5f0393e618 --- /dev/null +++ b/e2e/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "tsBuildInfoFile": "./lib/.e2e.tsbuildinfo" + }, + "include": ["./**/*.ts"], + "references": [ + { + "path": ".." + } + ] +} diff --git a/templates/index.ts b/helpers/index.ts similarity index 92% rename from templates/index.ts rename to helpers/index.ts index 97a3a4b5fb1c0263224f0ab84e75a370247a3854..e4f3ddfa00859b8ce7749dc6b2c8185af3ccf8ac 100644 --- a/templates/index.ts +++ b/helpers/index.ts @@ -1,14 +1,14 @@ -import { copy } from "../helpers/copy"; -import { callPackageManager } from "../helpers/install"; +import { copy } from "./copy"; +import { callPackageManager } from "./install"; import fs from "fs/promises"; import path from "path"; import { cyan } from "picocolors"; -import { COMMUNITY_OWNER, COMMUNITY_REPO } from "../helpers/constant"; -import { PackageManager } from "../helpers/get-pkg-manager"; -import { downloadAndExtractRepo } from "../helpers/repo"; +import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./constant"; +import { PackageManager } from "./get-pkg-manager"; import { installPythonTemplate } from "./python"; +import { downloadAndExtractRepo } from "./repo"; import { InstallTemplateArgs, TemplateEngine, @@ -71,7 +71,13 @@ const copyTestData = async ( vectorDb?: TemplateVectorDB, ) => { if (engine === "context") { - const srcPath = path.join(__dirname, "components", "data"); + const srcPath = path.join( + __dirname, + "..", + "templates", + "components", + "data", + ); const destPath = path.join(root, "data"); console.log(`\nCopying test data to ${cyan(destPath)}\n`); await copy("**", destPath, { diff --git a/templates/python.ts b/helpers/python.ts similarity index 94% rename from templates/python.ts rename to helpers/python.ts index 9dba187639c0365d26849bf7df932954bf958279..3c631b6ee39603400b33487fb328f9cd6aaed0d2 100644 --- a/templates/python.ts +++ b/helpers/python.ts @@ -2,7 +2,7 @@ import fs from "fs/promises"; import path from "path"; import { cyan } from "picocolors"; import { parse, stringify } from "smol-toml"; -import { copy } from "../helpers/copy"; +import { copy } from "./copy"; import { InstallTemplateArgs, TemplateVectorDB } from "./types"; interface Dependency { @@ -101,7 +101,14 @@ export const installPythonTemplate = async ({ "root" | "framework" | "template" | "engine" | "vectorDb" >) => { console.log("\nInitializing Python project with template:", template, "\n"); - const templatePath = path.join(__dirname, "types", template, framework); + const templatePath = path.join( + __dirname, + "..", + "templates", + "types", + template, + framework, + ); await copy("**", root, { parents: true, cwd: templatePath, @@ -123,7 +130,7 @@ export const installPythonTemplate = async ({ }); if (engine === "context") { - const compPath = path.join(__dirname, "components"); + const compPath = path.join(__dirname, "..", "templates", "components"); const VectorDBPath = path.join( compPath, "vectordbs", diff --git a/templates/types.ts b/helpers/types.ts similarity index 100% rename from templates/types.ts rename to helpers/types.ts diff --git a/templates/typescript.ts b/helpers/typescript.ts similarity index 96% rename from templates/typescript.ts rename to helpers/typescript.ts index df3c0b15b679405ebbb054303c5ab3732834e60b..9d498b406988379b35958e899d17596359825e4b 100644 --- a/templates/typescript.ts +++ b/helpers/typescript.ts @@ -46,7 +46,14 @@ export const installTSTemplate = async ({ * Copy the template files to the target directory. */ console.log("\nInitializing project with template:", template, "\n"); - const templatePath = path.join(__dirname, "types", template, framework); + const templatePath = path.join( + __dirname, + "..", + "templates", + "types", + template, + framework, + ); const copySource = ["**"]; if (!eslint) copySource.push("!eslintrc.json"); @@ -80,7 +87,7 @@ export const installTSTemplate = async ({ * Copy the selected chat engine files to the target directory and reference it. */ let relativeEngineDestPath; - const compPath = path.join(__dirname, "components"); + const compPath = path.join(__dirname, "..", "templates", "components"); if (engine && (framework === "express" || framework === "nextjs")) { console.log("\nUsing chat engine:", engine, "\n"); diff --git a/package.json b/package.json index b115e7014e8c13eda59048647b456a11919cd4fc..495bb2b4e5f6173924eaa00c957926fd14d56d96 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "create-llama": "./dist/index.js" }, "files": [ - "dist" + "./dist/index.js", + "./templates" ], "scripts": { "clean": "rimraf --glob ./dist ./templates/**/__pycache__ ./templates/**/node_modules ./templates/**/poetry.lock", diff --git a/questions.ts b/questions.ts index b144bfd706de19546a888e279fba4784adfcff43..0694d7afbc9a6caa243a01f6ae2d7eca45ac9c15 100644 --- a/questions.ts +++ b/questions.ts @@ -4,9 +4,9 @@ import path from "path"; import { blue, green } from "picocolors"; import prompts from "prompts"; import { InstallAppArgs } from "./create-app"; +import { TemplateFramework } from "./helpers"; import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./helpers/constant"; import { getRepoRootFolders } from "./helpers/repo"; -import { TemplateFramework } from "./templates"; export type QuestionArgs = Omit<InstallAppArgs, "appPath" | "packageManager">; diff --git a/tsconfig.json b/tsconfig.json index e4edad9e127c7de102ca7bdd6b243168a83bbc20..8c2c4944ee39a6253675fd140f35579aab468359 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,19 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { "target": "es2019", "moduleResolution": "node", "strict": true, "resolveJsonModule": true, "esModuleInterop": true, - "skipLibCheck": false + "skipLibCheck": true }, - "exclude": ["templates", "dist"] + "include": [ + "create-app.ts", + "index.ts", + "./helpers", + "questions.ts", + "package.json" + ], + "exclude": ["dist"] }