From 1228f009b3e90ebaf6cbf3b9de2a5a0f96885512 Mon Sep 17 00:00:00 2001 From: Dhaiwat Date: Sat, 6 Jan 2024 00:43:50 +0530 Subject: [PATCH] fix: include a `.gitignore` file in the create-fuels template --- .changeset/cold-worms-heal.md | 6 ++++ packages/create-fuels/src/cli.ts | 3 +- packages/create-fuels/test/cli.test.ts | 7 +++++ templates/nextjs/.gitignore | 4 ++- templates/nextjs/gitignore | 39 ++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .changeset/cold-worms-heal.md create mode 100644 templates/nextjs/gitignore diff --git a/.changeset/cold-worms-heal.md b/.changeset/cold-worms-heal.md new file mode 100644 index 00000000000..aa44086521c --- /dev/null +++ b/.changeset/cold-worms-heal.md @@ -0,0 +1,6 @@ +--- +"create-fuels": patch +"nextjs": patch +--- + +fix: include a `.gitignore` file in the template copied over by create-fuels diff --git a/packages/create-fuels/src/cli.ts b/packages/create-fuels/src/cli.ts index 1b1449ab13c..2be78860fb4 100644 --- a/packages/create-fuels/src/cli.ts +++ b/packages/create-fuels/src/cli.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; import { execSync } from 'child_process'; import { Command } from 'commander'; import { existsSync } from 'fs'; -import { cp, mkdir } from 'fs/promises'; +import { cp, mkdir, rename } from 'fs/promises'; import { join } from 'path'; import prompts from 'prompts'; @@ -64,6 +64,7 @@ export const runScaffoldCli = async ( await mkdir(projectPath); await cp(join(__dirname, '../templates/nextjs'), projectPath, { recursive: true }); + await rename(join(projectPath, 'gitignore'), join(projectPath, '.gitignore')); if (shouldInstallDeps) { process.chdir(projectPath); diff --git a/packages/create-fuels/test/cli.test.ts b/packages/create-fuels/test/cli.test.ts index d4272b99b4d..a172bccfbc3 100644 --- a/packages/create-fuels/test/cli.test.ts +++ b/packages/create-fuels/test/cli.test.ts @@ -16,6 +16,13 @@ test('create-fuels extracts the template to the specified directory', async () = // check if the template was extracted to the test-project directory. // compare the templates/nextjs folder with the test-project folder recursively const originalTemplateFiles = await fs.readdir(join(__dirname, '../templates/nextjs')); + + // remove the gitignore file from the array because it is not copied to the test-project folder + const gitIgnoreIndex = originalTemplateFiles.indexOf('gitignore'); + if (gitIgnoreIndex > -1) { + originalTemplateFiles.splice(gitIgnoreIndex, 1); + } + const testProjectFiles = await fs.readdir('test-project'); expect(originalTemplateFiles).toEqual(testProjectFiles); diff --git a/templates/nextjs/.gitignore b/templates/nextjs/.gitignore index 7f59c6b9fb1..31a347c5f82 100644 --- a/templates/nextjs/.gitignore +++ b/templates/nextjs/.gitignore @@ -34,4 +34,6 @@ yarn-error.log* next-env.d.ts .fuels -sway-api \ No newline at end of file +src/sway-api +sway-contracts/out +.turbo \ No newline at end of file diff --git a/templates/nextjs/gitignore b/templates/nextjs/gitignore new file mode 100644 index 00000000000..31a347c5f82 --- /dev/null +++ b/templates/nextjs/gitignore @@ -0,0 +1,39 @@ +# dependencies +/node_modules +/.pnp +.pnp.js +.yarn/install-state.gz + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts + +.fuels +src/sway-api +sway-contracts/out +.turbo \ No newline at end of file