changed .gitignore file handling/creation
This commit is contained in:
@@ -2,4 +2,10 @@
|
||||
|
||||
## Intro
|
||||
|
||||
blah blah blah
|
||||
## Git
|
||||
|
||||
Git is available to be used as the version control system for new projects. Select/Deselect within the `scaffold-<PROJECTTYPE>.toml` file.
|
||||
|
||||
***Please Note** that if you also use it for your configuration files and sample directories, then a .gitignore file within your sample directory will interfere with git's ability to track your skeletons/templates properly. So, to allow for this, put what you normally would in a .gitignore file into a GITIGNORE file in your sample directory. And scaffold will convert it to a .gitignore file within your newProject directory.
|
||||
|
||||
If you are NOT using git to track your project types and samples/skeletons/templates, then no problem, just place a .gitignore file within the sample directory as you would any other file.
|
||||
|
||||
@@ -11,18 +11,32 @@ scaffold go NewGoProject
|
||||
scaffold py aPythonProject
|
||||
`
|
||||
|
||||
var gi_template = `%s
|
||||
.env
|
||||
*.env
|
||||
.env.toml
|
||||
// var gi_template = `%s
|
||||
// .env
|
||||
// *.env
|
||||
// .env.toml
|
||||
|
||||
cfg/*.toml
|
||||
cfg/.env
|
||||
cfg/*.env
|
||||
cfg/.env*
|
||||
*.toml
|
||||
// cfg/*.toml
|
||||
// cfg/.env
|
||||
// cfg/*.env
|
||||
// cfg/.env*
|
||||
// *.toml
|
||||
|
||||
build/
|
||||
buildTime.txt
|
||||
buildVersion.txt
|
||||
`
|
||||
// build/
|
||||
// buildTime.txt
|
||||
// buildVersion.txt
|
||||
// `
|
||||
|
||||
// var gi_py_template = `%s
|
||||
// .env
|
||||
// *.env
|
||||
// .env.toml
|
||||
|
||||
// cfg/*.toml
|
||||
// cfg/.env
|
||||
// cfg/*.env
|
||||
// cfg/.env*
|
||||
// *.toml
|
||||
|
||||
// bin/
|
||||
// `
|
||||
|
||||
47
main.go
47
main.go
@@ -160,15 +160,19 @@ func main() {
|
||||
|
||||
// run init commands
|
||||
|
||||
// make mod file
|
||||
modpath := npsetup.Module_basepath + sep + newProjectName
|
||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
||||
ifFerr("go mod init failed", err)
|
||||
switch projType {
|
||||
case "go":
|
||||
// make mod file
|
||||
modpath := npsetup.Module_basepath + sep + newProjectName
|
||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
||||
ifFerr("go mod init failed", err)
|
||||
|
||||
// do a mod tidy to update the mod file
|
||||
_, err = exec.Command("go", "mod", "tidy").Output()
|
||||
ifFerr("Unable to update the mod file with a tidy", err)
|
||||
fmt.Println("Updated go.mod")
|
||||
// do a mod tidy to update the mod file
|
||||
_, err = exec.Command("go", "mod", "tidy").Output()
|
||||
ifFerr("Unable to update the mod file with a tidy", err)
|
||||
fmt.Println("Updated go.mod")
|
||||
case "py":
|
||||
}
|
||||
|
||||
// setup git
|
||||
if npsetup.Setup_git {
|
||||
@@ -179,10 +183,29 @@ func main() {
|
||||
nifd, err := os.Create(".gitignore")
|
||||
ifFerr("Unable to create .gitignore file", err)
|
||||
defer nifd.Close()
|
||||
gi_content := fmt.Sprintf(gi_template, newProjectName)
|
||||
_, err = nifd.WriteString(gi_content)
|
||||
ifFerr("Unable to write .gitignore content", err)
|
||||
fmt.Println("Wrote .gitignore content")
|
||||
|
||||
var gi_content string
|
||||
var gi_in []byte = []byte("bin/")
|
||||
|
||||
gisrc, err := os.Open("GITIGNORE")
|
||||
if err == nil { // assume error means there is no source file
|
||||
gi_in, err = io.ReadAll(gisrc)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to read GITIGNORE, using default content")
|
||||
}
|
||||
gi_content = fmt.Sprintf("%s\n\n%s", newProjectName, string(gi_in))
|
||||
|
||||
_, err = nifd.WriteString(gi_content)
|
||||
ifFerr("Unable to write .gitignore content", err)
|
||||
fmt.Println("Wrote .gitignore content")
|
||||
|
||||
// remove GITIGNORE
|
||||
err = os.Remove("GITIGNORE")
|
||||
if err != nil {
|
||||
fmt.Println("Unable to remove GITIGNORE file")
|
||||
}
|
||||
}
|
||||
defer gisrc.Close()
|
||||
|
||||
// stage files
|
||||
_, err = exec.Command("git", "add", ".").Output()
|
||||
|
||||
Reference in New Issue
Block a user