Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b082810d91 | |||
| 87a045cbea |
16
README.md
16
README.md
@@ -2,4 +2,18 @@
|
|||||||
|
|
||||||
## 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.
|
||||||
|
|
||||||
|
## The Process
|
||||||
|
|
||||||
|
- The new project directory is created
|
||||||
|
- Your project skeleton is copied from your sample directory
|
||||||
|
- your setup/initialization commmands are run
|
||||||
|
- a git repository is initialized in the project directory
|
||||||
|
- and if you enable it, a remote repository is created and setup
|
||||||
|
|||||||
@@ -11,18 +11,89 @@ 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/
|
||||||
|
// `
|
||||||
|
|
||||||
|
// var cfg_content = `# New Go Project configuration file
|
||||||
|
|
||||||
|
// # Format: TOML - see https://toml.io for details
|
||||||
|
|
||||||
|
// # Go specific
|
||||||
|
// # Go module path is of the form basePath/projectName
|
||||||
|
// # must be addressable if you are going to publish
|
||||||
|
// module_basepath = "officallygood.com"
|
||||||
|
|
||||||
|
// # where to put new project directories
|
||||||
|
// # within the user's home directory
|
||||||
|
// projects_basedir = "devel/GoMyApps"
|
||||||
|
// #def_project_name = "new-go-project"
|
||||||
|
|
||||||
|
// # Must be string, will be parsed to correct type
|
||||||
|
// # Remember perms are in octal
|
||||||
|
// project_dir_permissions = "0700"
|
||||||
|
// file_permissions = "0660"
|
||||||
|
|
||||||
|
// # Git
|
||||||
|
// setup_git = true
|
||||||
|
|
||||||
|
// # Do you have a remote location?
|
||||||
|
// # Do you have autologins setup correctly with ssh keys?
|
||||||
|
// # Using your .ssh/config file might be helpful
|
||||||
|
|
||||||
|
// # setup remote repo?
|
||||||
|
// create_remote_repo = false
|
||||||
|
|
||||||
|
// # remote repo user@location
|
||||||
|
// remote_user = "user@server"
|
||||||
|
|
||||||
|
// # remote repo base dir
|
||||||
|
// # relative to remote user home dir
|
||||||
|
// # eg unix/linux server
|
||||||
|
// # for user@server:/home/user/git -- absolute path
|
||||||
|
// user@server:git -- relative to home dir
|
||||||
|
// # eg windows server
|
||||||
|
// # ???
|
||||||
|
|
||||||
|
// ############################
|
||||||
|
// # remote location MUST already exist on remote server
|
||||||
|
// ############################
|
||||||
|
// remote_location = "git"
|
||||||
|
|
||||||
|
// # default remote short name
|
||||||
|
// remote_shortname = "origin"
|
||||||
|
//`
|
||||||
|
|
||||||
|
var cfg_content = `# Scaffold program configuration
|
||||||
|
|
||||||
|
# Format: TOML - see https://toml.io for details
|
||||||
|
|
||||||
|
# Too funny - this config file doesn't seem to be needed ;-)
|
||||||
|
# let's keep it for future use -- very silly
|
||||||
|
testkey = "test value"`
|
||||||
|
|||||||
69
main.go
69
main.go
@@ -31,6 +31,7 @@ type (
|
|||||||
Remote_User string
|
Remote_User string
|
||||||
Remote_Location string
|
Remote_Location string
|
||||||
Remote_Shortname string
|
Remote_Shortname string
|
||||||
|
Commands [][]string
|
||||||
}
|
}
|
||||||
ScaffoldSetup struct {
|
ScaffoldSetup struct {
|
||||||
TestKey string
|
TestKey string
|
||||||
@@ -71,14 +72,21 @@ func main() {
|
|||||||
|
|
||||||
if _, err := os.Stat(cfg_file); err != nil {
|
if _, err := os.Stat(cfg_file); err != nil {
|
||||||
fmt.Println("No scaffold program configuration file found - creating a default file")
|
fmt.Println("No scaffold program configuration file found - creating a default file")
|
||||||
// ok now do it
|
cfgfd, err := os.Create(cfg_file)
|
||||||
|
ifFerr("Unable to create scaffold configuration file", err)
|
||||||
|
defer cfgfd.Close()
|
||||||
|
|
||||||
|
_, err = cfgfd.WriteString(cfg_content)
|
||||||
|
ifFerr("Unable to write scaffold configuration file content", err)
|
||||||
|
fmt.Println("Wrote new scaffold configuration file")
|
||||||
|
_, err = toml.Decode(cfg_content, &setup)
|
||||||
|
ifFerr("[Failed] to parse config file", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("found config file")
|
fmt.Println("found config file")
|
||||||
|
_, err = toml.DecodeFile(cfg_file, &setup)
|
||||||
|
ifFerr("[Failed] to parse config file", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = toml.DecodeFile(cfg_file, &setup)
|
|
||||||
ifFerr("[Failed] to parse config file", err)
|
|
||||||
|
|
||||||
pts, err := availableProjectTypes(scaffold_cfg_dir)
|
pts, err := availableProjectTypes(scaffold_cfg_dir)
|
||||||
ifFerr("Unable to read scaffold config directory contents", err)
|
ifFerr("Unable to read scaffold config directory contents", err)
|
||||||
|
|
||||||
@@ -106,6 +114,8 @@ func main() {
|
|||||||
_, err = toml.DecodeFile(projectCfgFile, &npsetup)
|
_, err = toml.DecodeFile(projectCfgFile, &npsetup)
|
||||||
ifFerr("Unable to read configuration for requested project type", err)
|
ifFerr("Unable to read configuration for requested project type", err)
|
||||||
|
|
||||||
|
//fmt.Printf("Found commands: %+v\n", npsetup.Commands)
|
||||||
|
|
||||||
//Setup and Ready to begin
|
//Setup and Ready to begin
|
||||||
|
|
||||||
// Permissions are octal (ugo - user, group, other)
|
// Permissions are octal (ugo - user, group, other)
|
||||||
@@ -158,17 +168,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Println("Project sample skeleton copied")
|
fmt.Println("Project sample skeleton copied")
|
||||||
|
|
||||||
// run init commands
|
// run your init commands from the projectType/scaffold-<PROJECTTYPE>.toml file
|
||||||
|
|
||||||
// make mod file
|
for _, comm := range npsetup.Commands {
|
||||||
modpath := npsetup.Module_basepath + sep + newProjectName
|
args := comm[1:]
|
||||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
if comm[0] == "go" && comm[1] == "mod" && comm[2] == "init" {
|
||||||
ifFerr("go mod init failed", err)
|
args[2] = args[2] + sep + newProjectName
|
||||||
|
//fmt.Printf("executing: %+v -- %+v\n", comm, args)
|
||||||
// do a mod tidy to update the mod file
|
}
|
||||||
_, err = exec.Command("go", "mod", "tidy").Output()
|
_, err = exec.Command(comm[0], args...).Output()
|
||||||
ifFerr("Unable to update the mod file with a tidy", err)
|
if err != nil {
|
||||||
fmt.Println("Updated go.mod")
|
commstring := fmt.Sprintf("Unable to execute command: %+v", comm)
|
||||||
|
log.Fatalf("%s -- %s\n", commstring, err)
|
||||||
|
}
|
||||||
|
fmt.Printf("executing: %+v %+v\n", comm[0], args)
|
||||||
|
}
|
||||||
|
|
||||||
// setup git
|
// setup git
|
||||||
if npsetup.Setup_git {
|
if npsetup.Setup_git {
|
||||||
@@ -179,10 +193,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()
|
||||||
|
|||||||
Reference in New Issue
Block a user