Skip to content

Commit 79d2ee5

Browse files
authored
Merge pull request #232 from eparis/gitignore
pkg:generator: Generate .gitignore at top and for tmp/_output
2 parents 6fbb75b + 9b77bfc commit 79d2ee5

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

pkg/generator/generator.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const (
5959
catalogPackageYaml = "package.yaml"
6060
catalogCSVYaml = "csv.yaml"
6161
crdYaml = "crd.yaml"
62+
gitignore = ".gitignore"
6263
)
6364

6465
type Generator struct {
@@ -93,6 +94,10 @@ func NewGenerator(apiVersion, kind, projectName, repoPath string) *Generator {
9394
// │ ├── build
9495
// │ └── codegen
9596
func (g *Generator) Render() error {
97+
if err := g.renderProject(); err != nil {
98+
return err
99+
}
100+
96101
if err := g.renderCmd(); err != nil {
97102
return err
98103
}
@@ -111,6 +116,23 @@ func (g *Generator) Render() error {
111116
return g.renderGoDep()
112117
}
113118

119+
func (g *Generator) renderProject() error {
120+
if err := os.MkdirAll(g.projectName, defaultDirFileMode); err != nil {
121+
return err
122+
}
123+
return renderProjectGitignore(g.projectName)
124+
}
125+
126+
func renderProjectGitignore(projectName string) error {
127+
gitignoreFile := filepath.Join(projectName, gitignore)
128+
buf := &bytes.Buffer{}
129+
if _, err := buf.Write([]byte(projectGitignoreTmpl)); err != nil {
130+
return err
131+
}
132+
133+
return writeFileAndPrint(gitignoreFile, buf.Bytes(), defaultFileMode)
134+
}
135+
114136
func (g *Generator) renderGoDep() error {
115137
buf := &bytes.Buffer{}
116138
if err := renderGopkgTomlFile(buf); err != nil {

pkg/generator/gitignore_tmpls.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2018 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package generator
16+
17+
const projectGitignoreTmpl = `
18+
# Temporary Build Files
19+
tmp/_output
20+
tmp/_test
21+
22+
23+
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
24+
25+
### Emacs ###
26+
# -*- mode: gitignore; -*-
27+
*~
28+
\#*\#
29+
/.emacs.desktop
30+
/.emacs.desktop.lock
31+
*.elc
32+
auto-save-list
33+
tramp
34+
.\#*
35+
36+
# Org-mode
37+
.org-id-locations
38+
*_archive
39+
40+
# flymake-mode
41+
*_flymake.*
42+
43+
# eshell files
44+
/eshell/history
45+
/eshell/lastdir
46+
47+
# elpa packages
48+
/elpa/
49+
50+
# reftex files
51+
*.rel
52+
53+
# AUCTeX auto folder
54+
/auto/
55+
56+
# cask packages
57+
.cask/
58+
dist/
59+
60+
# Flycheck
61+
flycheck_*.el
62+
63+
# server auth directory
64+
/server/
65+
66+
# projectiles files
67+
.projectile
68+
projectile-bookmarks.eld
69+
70+
# directory configuration
71+
.dir-locals.el
72+
73+
# saveplace
74+
places
75+
76+
# url cache
77+
url/cache/
78+
79+
# cedet
80+
ede-projects.el
81+
82+
# smex
83+
smex-items
84+
85+
# company-statistics
86+
company-statistics-cache.el
87+
88+
# anaconda-mode
89+
anaconda-mode/
90+
91+
### Go ###
92+
# Binaries for programs and plugins
93+
*.exe
94+
*.exe~
95+
*.dll
96+
*.so
97+
*.dylib
98+
99+
# Test binary, build with 'go test -c'
100+
*.test
101+
102+
# Output of the go coverage tool, specifically when used with LiteIDE
103+
*.out
104+
105+
### Vim ###
106+
# swap
107+
.sw[a-p]
108+
.*.sw[a-p]
109+
# session
110+
Session.vim
111+
# temporary
112+
.netrwhist
113+
# auto-generated tag files
114+
tags
115+
116+
### VisualStudioCode ###
117+
.vscode/*
118+
!.vscode/settings.json
119+
!.vscode/tasks.json
120+
!.vscode/launch.json
121+
!.vscode/extensions.json
122+
.history
123+
124+
125+
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
126+
`

0 commit comments

Comments
 (0)