fix: gitignore

This commit is contained in:
bracesproul
2025-03-13 12:48:56 -07:00
parent 26c0c15b36
commit d6fff1f51d
4 changed files with 149 additions and 17 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
node_modules
dist
index.js
gitignore.js
.yarn/*
!.yarn/patches
!.yarn/plugins
+2 -1
View File
@@ -20,10 +20,11 @@
},
"files": [
"index.js",
"gitignore.js",
"templates/**"
],
"scripts": {
"build": "tsc ./src/index.ts --esModuleInterop --target es2020 --module esnext --moduleResolution node --outDir .",
"build": "tsc ./src/*.ts --esModuleInterop --target es2020 --module esnext --moduleResolution node --outDir .",
"prepublishOnly": "npm run build",
"clean": "rm -rf src/index.js",
"format": "prettier --write . --ignore-path .prettierignore",
+108
View File
@@ -0,0 +1,108 @@
export const BASE_GITIGNORE = `# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
**/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
.yarn/cache
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
/dist
**/dist
.turbo/
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
credentials.json
# LangGraph API
.langgraph_api
`;
export const NEXTJS_GITIGNORE = `# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# LangGraph API
.langgraph_api
.env
.next/
next-env.d.ts`;
export const VITE_GITIGNORE = `# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# LangGraph API
.langgraph_api
.env`;
+38 -15
View File
@@ -6,12 +6,18 @@ import chalk, { ChalkInstance } from "chalk";
import { fileURLToPath } from "url";
import prompts from "prompts";
import { execSync } from "child_process";
import {
BASE_GITIGNORE,
NEXTJS_GITIGNORE,
VITE_GITIGNORE,
} from "./gitignore.js";
// Get the directory name of the current module
const __filename: string = fileURLToPath(import.meta.url);
const __dirname: string = path.dirname(__filename);
type PackageManager = "npm" | "pnpm" | "yarn";
type Framework = "nextjs" | "vite";
interface ProjectAnswers {
/**
@@ -29,7 +35,7 @@ interface ProjectAnswers {
/**
* @default "nextjs"
*/
framework: "nextjs" | "vite";
framework: Framework;
/**
* @default true
*/
@@ -110,6 +116,33 @@ async function setPackageJsonFields(
}
}
async function writeGitignore(
baseDir: string,
framework: Framework,
chalk: ChalkInstance,
): Promise<void> {
try {
const gitignorePath = path.join(baseDir, ".gitignore");
// Write the base .gitignore file in the root
await fs.promises.writeFile(gitignorePath, BASE_GITIGNORE);
// write the framework-specific .gitignore file inside baseDir/apps/web
const frameworkGitignorePath = path.join(
baseDir,
"apps",
"web",
".gitignore",
);
if (framework === "nextjs") {
await fs.promises.writeFile(frameworkGitignorePath, NEXTJS_GITIGNORE);
} else {
await fs.promises.writeFile(frameworkGitignorePath, VITE_GITIGNORE);
}
} catch (e) {
console.log(`${chalk.red("Error: ")} Failed to write .gitignore`);
}
}
const createStartServersMessage = (
chalk: ChalkInstance,
packageManager: PackageManager,
@@ -278,13 +311,9 @@ async function init(): Promise<void> {
"templates",
"monorepo",
);
fs.copySync(monorepoTemplateDir, targetDir, {
dereference: true,
filter: (_) => {
// Ensure hidden files (like .gitignore) are copied
return true;
},
});
fs.copySync(monorepoTemplateDir, targetDir);
await writeGitignore(targetDir, framework, chalk);
// Create web directory inside apps and copy the framework template
const appsDir: string = path.join(targetDir, "apps");
@@ -297,13 +326,7 @@ async function init(): Promise<void> {
"templates",
framework,
);
fs.copySync(frameworkTemplateDir, webDir, {
dereference: true,
filter: (_) => {
// Ensure hidden files (like .gitignore) are copied
return true;
},
});
fs.copySync(frameworkTemplateDir, webDir);
// Get the path to the agents src directory which already exists in the monorepo template
const agentsDir: string = path.join(appsDir, "agents", "src");