Skip to content

Commit a7c7e30

Browse files
committed
functionally complete
1 parent 55cba56 commit a7c7e30

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/@apphosting/adapter-nextjs/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
MiddlewareManifest,
1313
} from "./interfaces.js";
1414
import { NextConfigComplete } from "next/dist/server/config-shared.js";
15-
import { OutputBundleConfig } from "@apphosting/common";
15+
import { OutputBundleConfig, UpdateOrCreateGitignore } from "@apphosting/common";
1616

1717
// fs-extra is CJS, readJson can't be imported using shorthand
1818
export const { copy, exists, writeFile, readJson, readdir, readFileSync, existsSync, ensureDir } =
@@ -203,6 +203,7 @@ async function generateBundleYaml(
203203
}
204204

205205
await writeFile(opts.bundleYamlPath, yamlStringify(outputBundle));
206+
UpdateOrCreateGitignore(cwd, ["/.apphosting/"]);
206207
return;
207208
}
208209

packages/@apphosting/common/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { spawn } from "child_process";
2+
import * as path from "node:path";
3+
import * as fs from "fs-extra";
4+
25

36
// Output bundle metadata specifications to be written to bundle.yaml
47
export interface OutputBundleConfig {
@@ -139,3 +142,27 @@ export function getBuildOptions(): BuildOptions {
139142
projectDirectory: process.cwd(),
140143
};
141144
}
145+
146+
147+
/**
148+
* Updates or creates a .gitignore file with the given entries in the given path
149+
*/
150+
export function UpdateOrCreateGitignore(dirPath: string, entries: string[]) {
151+
const gitignorePath = path.join(dirPath, ".gitignore");
152+
153+
if (!fs.existsSync(gitignorePath)) {
154+
console.log(`creating ${gitignorePath} with entries: ${entries.join("\n")}`);
155+
fs.writeFileSync(gitignorePath, entries.join("\n"));
156+
return;
157+
}
158+
159+
let content = fs.readFileSync(gitignorePath, "utf-8");
160+
for (const entry of entries) {
161+
if (!content.includes(entry)) {
162+
console.log(`adding ${entry} to ${gitignorePath}`);
163+
content += `\n${entry}\n`;
164+
}
165+
}
166+
167+
fs.writeFileSync(gitignorePath, content);
168+
}

0 commit comments

Comments
 (0)