fix downloading template
This commit is contained in:
parent
99dea36a63
commit
dd0bcf5671
1 changed files with 17 additions and 6 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteAllExceptTemplate(outPath string, excludeDir string) {
|
func deleteAllExceptTemplate(outPath string, excludeDir string) {
|
||||||
|
|
@ -38,9 +40,14 @@ func deleteAllExceptTemplate(outPath string, excludeDir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
var outPath string
|
var outPath string
|
||||||
fmt.Print("What should we call your new app? ")
|
reader := bufio.NewReader(os.Stdin)
|
||||||
fmt.Scanln(&outPath) // Reads user input from the command line
|
fmt.Print("What should we call your new app? Enter name: ")
|
||||||
|
outPath, _ = reader.ReadString('\n')
|
||||||
|
outPath = strings.ReplaceAll(outPath, "\n", "")
|
||||||
|
outPath = strings.ReplaceAll(outPath, " ", "-")
|
||||||
|
outPath = strings.ToLower(outPath)
|
||||||
|
|
||||||
if outPath == "" {
|
if outPath == "" {
|
||||||
fmt.Println("Please provide a name for your app.")
|
fmt.Println("Please provide a name for your app.")
|
||||||
|
|
@ -61,19 +68,23 @@ func main() {
|
||||||
|
|
||||||
deleteAllExceptTemplate(outPath, excludeDir)
|
deleteAllExceptTemplate(outPath, excludeDir)
|
||||||
|
|
||||||
templateDir := filepath.Join(outPath, excludeDir)
|
newDir := filepath.Join(cwd, outPath)
|
||||||
|
|
||||||
err = exec.Command("mv", templateDir+"/*", "./"+outPath).Run()
|
mvCmd := exec.Command("cp", "-vaR", "starter-template/.", ".")
|
||||||
|
mvCmd.Dir = newDir
|
||||||
|
err = mvCmd.Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Error moving files %v\n", err)
|
println("Error moving files %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = exec.Command("rm", "-rf", templateDir).Run()
|
rmCmd := exec.Command("rm", "-rf", "starter-template")
|
||||||
|
rmCmd.Dir = newDir
|
||||||
|
err = rmCmd.Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Error removing directory %v\n", err)
|
println("Error removing starter-template %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue