From 3df7fd6dd1bb068a91d4e8f882bb2994b8991525 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Thu, 26 Oct 2023 16:49:26 +0700
Subject: [PATCH] remove import alias and src folder rewrite

---
 packages/create-llama/create-app.ts      |   6 --
 packages/create-llama/index.ts           |  44 ----------
 packages/create-llama/templates/index.ts | 102 +----------------------
 packages/create-llama/templates/types.ts |   8 --
 4 files changed, 1 insertion(+), 159 deletions(-)

diff --git a/packages/create-llama/create-app.ts b/packages/create-llama/create-app.ts
index 8efef515f..901723640 100644
--- a/packages/create-llama/create-app.ts
+++ b/packages/create-llama/create-app.ts
@@ -16,15 +16,11 @@ export async function createApp({
   appPath,
   packageManager,
   eslint,
-  srcDir,
-  importAlias,
 }: {
   framework: TemplateFramework;
   appPath: string;
   packageManager: PackageManager;
   eslint: boolean;
-  srcDir: boolean;
-  importAlias: string;
 }): Promise<void> {
   const template: TemplateType = "simple";
 
@@ -67,8 +63,6 @@ export async function createApp({
     packageManager,
     isOnline,
     eslint,
-    srcDir,
-    importAlias,
   });
 
   if (tryGitInit(root)) {
diff --git a/packages/create-llama/index.ts b/packages/create-llama/index.ts
index 9ff2ee674..21eda3b7a 100644
--- a/packages/create-llama/index.ts
+++ b/packages/create-llama/index.ts
@@ -179,10 +179,6 @@ async function run(): Promise<void> {
   const defaults: typeof preferences = {
     framework: "nextjs",
     eslint: true,
-    app: true,
-    srcDir: false,
-    importAlias: "@/*",
-    customizeImportAlias: false,
   };
   const getPrefOrDefault = (field: string) =>
     preferences[field] ?? defaults[field];
@@ -236,51 +232,11 @@ async function run(): Promise<void> {
     }
   }
 
-  if (typeof program.importAlias !== "string" || !program.importAlias.length) {
-    if (ciInfo.isCI) {
-      // We don't use preferences here because the default value is @/* regardless of existing preferences
-      program.importAlias = defaults.importAlias;
-    } else {
-      const styledImportAlias = blue("import alias");
-
-      const { customizeImportAlias } = await prompts({
-        onState: onPromptState,
-        type: "toggle",
-        name: "customizeImportAlias",
-        message: `Would you like to customize the default ${styledImportAlias} (${defaults.importAlias})?`,
-        initial: getPrefOrDefault("customizeImportAlias"),
-        active: "Yes",
-        inactive: "No",
-      });
-
-      if (!customizeImportAlias) {
-        // We don't use preferences here because the default value is @/* regardless of existing preferences
-        program.importAlias = defaults.importAlias;
-      } else {
-        const { importAlias } = await prompts({
-          onState: onPromptState,
-          type: "text",
-          name: "importAlias",
-          message: `What ${styledImportAlias} would you like configured?`,
-          initial: getPrefOrDefault("importAlias"),
-          validate: (value) =>
-            /.+\/\*/.test(value)
-              ? true
-              : "Import alias must follow the pattern <prefix>/*",
-        });
-        program.importAlias = importAlias;
-        preferences.importAlias = importAlias;
-      }
-    }
-  }
-
   await createApp({
     framework: program.framework,
     appPath: resolvedProjectPath,
     packageManager,
     eslint: program.eslint,
-    srcDir: program.srcDir,
-    importAlias: program.importAlias,
   });
   conf.set("preferences", preferences);
 }
diff --git a/packages/create-llama/templates/index.ts b/packages/create-llama/templates/index.ts
index d9de01f8d..a6cb26d61 100644
--- a/packages/create-llama/templates/index.ts
+++ b/packages/create-llama/templates/index.ts
@@ -1,29 +1,13 @@
 import { copy } from "../helpers/copy";
 import { install } from "../helpers/install";
-import { makeDir } from "../helpers/make-dir";
 
-import { Sema } from "async-sema";
-import { async as glob } from "fast-glob";
 import fs from "fs/promises";
 import os from "os";
 import path from "path";
 import { bold, cyan } from "picocolors";
 import { version } from "../package.json";
 
-import { GetTemplateFileArgs, InstallTemplateArgs } from "./types";
-
-/**
- * Get the file path for a given file in a template, e.g. "next.config.js".
- */
-export const getTemplateFile = ({
-  template,
-  framework,
-  file,
-}: GetTemplateFileArgs): string => {
-  return path.join(__dirname, template, framework, file);
-};
-
-export const SRC_DIR_NAMES = ["app", "pages", "styles"];
+import { InstallTemplateArgs } from "./types";
 
 /**
  * Install a LlamaIndex internal template to a given `root` directory.
@@ -36,8 +20,6 @@ export const installTemplate = async ({
   template,
   framework,
   eslint,
-  srcDir,
-  importAlias,
 }: InstallTemplateArgs) => {
   console.log(bold(`Using ${packageManager}.`));
 
@@ -70,88 +52,6 @@ export const installTemplate = async ({
     },
   });
 
-  const tsconfigFile = path.join(root, "tsconfig.json");
-  await fs.writeFile(
-    tsconfigFile,
-    (await fs.readFile(tsconfigFile, "utf8"))
-      .replace(
-        `"@/*": ["./*"]`,
-        srcDir ? `"@/*": ["./src/*"]` : `"@/*": ["./*"]`,
-      )
-      .replace(`"@/*":`, `"${importAlias}":`),
-  );
-
-  // update import alias in any files if not using the default
-  if (importAlias !== "@/*") {
-    const files = await glob("**/*", {
-      cwd: root,
-      dot: true,
-      stats: false,
-    });
-    const writeSema = new Sema(8, { capacity: files.length });
-    await Promise.all(
-      files.map(async (file) => {
-        // We don't want to modify compiler options in [ts/js]config.json
-        if (file === "tsconfig.json" || file === "jsconfig.json") return;
-        await writeSema.acquire();
-        const filePath = path.join(root, file);
-        if ((await fs.stat(filePath)).isFile()) {
-          await fs.writeFile(
-            filePath,
-            (await fs.readFile(filePath, "utf8")).replace(
-              `@/`,
-              `${importAlias.replace(/\*/g, "")}`,
-            ),
-          );
-        }
-        await writeSema.release();
-      }),
-    );
-  }
-
-  if (srcDir) {
-    await makeDir(path.join(root, "src"));
-    await Promise.all(
-      SRC_DIR_NAMES.map(async (file) => {
-        await fs
-          .rename(path.join(root, file), path.join(root, "src", file))
-          .catch((err) => {
-            if (err.code !== "ENOENT") {
-              throw err;
-            }
-          });
-      }),
-    );
-
-    const isAppTemplate = template.startsWith("app");
-
-    // Change the `Get started by editing pages/index` / `app/page` to include `src`
-    const indexPageFile = path.join(
-      "src",
-      isAppTemplate ? "app" : "pages",
-      `${isAppTemplate ? "page" : "index"}.tsx`,
-    );
-
-    await fs.writeFile(
-      indexPageFile,
-      (await fs.readFile(indexPageFile, "utf8")).replace(
-        isAppTemplate ? "app/page" : "pages/index",
-        isAppTemplate ? "src/app/page" : "src/pages/index",
-      ),
-    );
-
-    if (framework === "nextjs") {
-      const tailwindConfigFile = path.join(root, "tailwind.config.ts");
-      await fs.writeFile(
-        tailwindConfigFile,
-        (await fs.readFile(tailwindConfigFile, "utf8")).replace(
-          /\.\/(\w+)\/\*\*\/\*\.\{js,ts,jsx,tsx,mdx\}/g,
-          "./src/$1/**/*.{js,ts,jsx,tsx,mdx}",
-        ),
-      );
-    }
-  }
-
   /**
    * Update the package.json scripts.
    */
diff --git a/packages/create-llama/templates/types.ts b/packages/create-llama/templates/types.ts
index 9cd44c968..087731013 100644
--- a/packages/create-llama/templates/types.ts
+++ b/packages/create-llama/templates/types.ts
@@ -3,12 +3,6 @@ import { PackageManager } from "../helpers/get-pkg-manager";
 export type TemplateType = "simple";
 export type TemplateFramework = "nextjs" | "express";
 
-export interface GetTemplateFileArgs {
-  template: TemplateType;
-  framework: TemplateFramework;
-  file: string;
-}
-
 export interface InstallTemplateArgs {
   appName: string;
   root: string;
@@ -17,6 +11,4 @@ export interface InstallTemplateArgs {
   template: TemplateType;
   framework: TemplateFramework;
   eslint: boolean;
-  srcDir: boolean;
-  importAlias: string;
 }
-- 
GitLab