Skip to content

Commit

Permalink
feat(init): Adds minimal .gitignore on prisma init (#8203)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhankarKG committed Jul 23, 2021
1 parent ff8fa06 commit 410fb9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/packages/cli/src/Init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export const defaultURL = (
}
}

export const defaultGitIgnore = () => {
return `node_modules
# Keep environment variables out of version control
.env
`
}

export class Init implements Command {
static new(): Init {
return new Init()
Expand Down Expand Up @@ -268,6 +275,15 @@ export class Init implements Command {
}
}

try {
fs.writeFileSync(
path.join(outputDir, ".gitignore"),
defaultGitIgnore()
);
} catch (error) {
console.error("Failed to write .gitignore file, reason: ", error);
}

const steps: string[] = []

if (provider === 'mongodb') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@ More information in our documentation:
https://pris.ly/d/getting-started
`;

exports[`writes a minimal .gitignore file 1`] = `
node_modules
# Keep environment variables out of version control
.env
`;
11 changes: 10 additions & 1 deletion src/packages/cli/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import { join } from 'path'
import stripAnsi from 'strip-ansi'
import { defaultEnv, defaultSchema } from '../Init'
import { defaultEnv, defaultGitIgnore, defaultSchema } from '../Init'
import { consoleContext, Context } from './__helpers__/context'

const ctx = Context.new().add(consoleContext()).assemble()
Expand Down Expand Up @@ -196,3 +196,12 @@ test('appends when .env present', async () => {
const env = fs.readFileSync(join(ctx.tmpDir, '.env'), 'utf-8')
expect(env).toMatchSnapshot()
})

test('writes a minimal .gitignore file', async () => {
ctx.fixture('init');
await ctx.cli('init');
const gitignore = fs.readFileSync(join(ctx.tmpDir, '.gitignore'), 'utf-8');
expect(gitignore).toMatch(defaultGitIgnore());

expect(gitignore).toMatchSnapshot();
})

0 comments on commit 410fb9a

Please sign in to comment.