Skip to content

Commit

Permalink
ensure all templates have a .gitignore file (#3754)
Browse files Browse the repository at this point in the history
* add test to ensure all templates have a .gitignore file

* c3: rename .gitignore to an intermediate name
that npm pack will not exclude
  • Loading branch information
RamIdeas authored Oct 3, 2023
1 parent b54512b commit 811730d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .changeset/hip-monkeys-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-cloudflare": patch
---

.gitignore files were not included in our templates due to npm/npm#3763

we now workaround this issue and ensure C3 templates include a .gitignore file
3 changes: 3 additions & 0 deletions packages/create-cloudflare/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ create-cloudflare-*.tgz
templates/**/package-lock.json
templates/**/yarn.lock
templates/**/pnpm-lock.yaml

# the build step renames .gitignore files to __dot__gitignore
templates/**/__dot__gitignore
3 changes: 3 additions & 0 deletions packages/create-cloudflare/e2e-tests/workers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
// Relevant project files should have been created
expect(projectPath).toExist();

const gitignorePath = join(projectPath, ".gitignore");
expect(gitignorePath).toExist();

const pkgJsonPath = join(projectPath, "package.json");
expect(pkgJsonPath).toExist();

Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"dns2": "^2.1.0",
"esbuild": "^0.17.12",
"execa": "^7.1.1",
"glob": "^10.3.3",
"haikunator": "^2.1.2",
"log-update": "^5.0.1",
"open": "^8.4.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/create-cloudflare/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { build, context, BuildOptions } from "esbuild";
import { cp } from "fs/promises";
import * as glob from "glob";

const run = async () => {
const argv = process.argv.slice(2);
Expand All @@ -20,6 +21,15 @@ const run = async () => {
recursive: true,
force: true,
});

// npm pack doesn't include .gitignore files (see https://github.com/npm/npm/issues/3763)
// To workaround, copy all ".gitignore" files as "__dot__gitignore" so npm pack includes them
// The latter has been added to the project's .gitignore file
// This renaming will be reversed when each template is used
// We can continue to author ".gitignore" files in each template
for (const filepath of glob.sync("templates/**/.gitignore")) {
await cp(filepath, filepath.replace(".gitignore", "__dot__gitignore"));
}
};

const runWatch = async () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/create-cloudflare/src/workers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { readFile, writeFile, mkdtemp, cp, rm, readdir } from "fs/promises";
import {
readFile,
writeFile,
mkdtemp,
cp,
rm,
readdir,
rename,
} from "fs/promises";
import { tmpdir } from "os";
import { resolve, join } from "path";
import { chdir } from "process";
Expand Down Expand Up @@ -81,6 +89,9 @@ async function copyFiles(ctx: Context) {
// copy template files
updateStatus(`Copying files from "${template}" template`);
await cp(srcdir, destdir, { recursive: true });

// reverse renaming from build step
await rename(join(destdir, "__dot__gitignore"), join(destdir, ".gitignore"));
}

async function copyExistingWorkerFiles(ctx: Context) {
Expand Down
30 changes: 12 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 811730d

Please sign in to comment.