changed .gitignore file handling/creation

This commit is contained in:
2023-04-10 15:54:41 -04:00
parent 38c3a87dd2
commit 87a045cbea
3 changed files with 69 additions and 26 deletions

View File

@@ -2,4 +2,10 @@
## Intro ## 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.

View File

@@ -11,18 +11,32 @@ scaffold go NewGoProject
scaffold py aPythonProject scaffold py aPythonProject
` `
var gi_template = `%s // var gi_template = `%s
.env // .env
*.env // *.env
.env.toml // .env.toml
cfg/*.toml // cfg/*.toml
cfg/.env // cfg/.env
cfg/*.env // cfg/*.env
cfg/.env* // cfg/.env*
*.toml // *.toml
build/ // build/
buildTime.txt // buildTime.txt
buildVersion.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
View File

@@ -160,15 +160,19 @@ func main() {
// run init commands // run init commands
// make mod file switch projType {
modpath := npsetup.Module_basepath + sep + newProjectName case "go":
_, err = exec.Command("go", "mod", "init", modpath).Output() // make mod file
ifFerr("go mod init failed", err) 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 // do a mod tidy to update the mod file
_, err = exec.Command("go", "mod", "tidy").Output() _, err = exec.Command("go", "mod", "tidy").Output()
ifFerr("Unable to update the mod file with a tidy", err) ifFerr("Unable to update the mod file with a tidy", err)
fmt.Println("Updated go.mod") fmt.Println("Updated go.mod")
case "py":
}
// setup git // setup git
if npsetup.Setup_git { if npsetup.Setup_git {
@@ -179,10 +183,29 @@ func main() {
nifd, err := os.Create(".gitignore") nifd, err := os.Create(".gitignore")
ifFerr("Unable to create .gitignore file", err) ifFerr("Unable to create .gitignore file", err)
defer nifd.Close() defer nifd.Close()
gi_content := fmt.Sprintf(gi_template, newProjectName)
_, err = nifd.WriteString(gi_content) var gi_content string
ifFerr("Unable to write .gitignore content", err) var gi_in []byte = []byte("bin/")
fmt.Println("Wrote .gitignore content")
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 // stage files
_, err = exec.Command("git", "add", ".").Output() _, err = exec.Command("git", "add", ".").Output()