From c778e4507e0dbc663d54423112a1b5f37d9e83b1 Mon Sep 17 00:00:00 2001 From: Alex Yang <himself65@outlook.com> Date: Fri, 12 Jan 2024 15:36:04 -0600 Subject: [PATCH] fix: cover type check on all ts files (#372) --- create-app.ts | 6 +++--- e2e/basic.spec.ts | 2 +- e2e/tsconfig.json | 12 ++++++++++++ {templates => helpers}/index.ts | 18 ++++++++++++------ {templates => helpers}/python.ts | 13 ++++++++++--- {templates => helpers}/types.ts | 0 {templates => helpers}/typescript.ts | 11 +++++++++-- package.json | 3 ++- questions.ts | 2 +- tsconfig.json | 12 ++++++++++-- 10 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 e2e/tsconfig.json rename {templates => helpers}/index.ts (92%) rename {templates => helpers}/python.ts (94%) rename {templates => helpers}/types.ts (100%) rename {templates => helpers}/typescript.ts (96%) diff --git a/create-app.ts b/create-app.ts index 2e7f4c6e..65ff0a9f 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 861f5416..3e76f526 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 00000000..e45598cb --- /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 97a3a4b5..e4f3ddfa 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 9dba1876..3c631b6e 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 df3c0b15..9d498b40 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 b115e701..495bb2b4 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 b144bfd7..0694d7af 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 e4edad9e..8c2c4944 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"] } -- GitLab