github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/buffalo/cmd/fix/fix.go (about) 1 package fix 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 "path/filepath" 8 "strings" 9 10 "github.com/BurntSushi/toml" 11 ) 12 13 // YesToAll will be used by the command to skip the questions 14 var YesToAll bool 15 16 var replace = map[string]string{ 17 "github.com/gobuffalo/buffalo-plugins": "github.com/gobuffalo/buffalo/plugins", 18 "github.com/gobuffalo/genny": "github.com/gobuffalo/genny/v2", 19 "github.com/gobuffalo/pop": "github.com/gobuffalo/pop/v5", 20 "github.com/gobuffalo/pop/nulls": "github.com/gobuffalo/nulls", 21 "github.com/gobuffalo/uuid": "github.com/gofrs/uuid", 22 "github.com/markbates/pop": "github.com/gobuffalo/pop/v5", 23 "github.com/markbates/validate": "github.com/gobuffalo/validate/v3", 24 "github.com/markbates/willie": "github.com/gobuffalo/httptest", 25 "github.com/satori/go.uuid": "github.com/gofrs/uuid", 26 "github.com/shurcooL/github_flavored_markdown": "github.com/gobuffalo/github_flavored_markdown", 27 "github.com/gobuffalo/validate": "github.com/gobuffalo/validate/v3", 28 "github.com/gobuffalo/validate/validators": "github.com/gobuffalo/validate/v3/validators", 29 "github.com/gobuffalo/suite": "github.com/gobuffalo/suite/v3", 30 "github.com/gobuffalo/buffalo-pop/": "github.com/gobuffalo/buffalo-pop/v2", 31 "github.com/gobuffalo/buffalo-pop/pop/popmw": "github.com/gobuffalo/buffalo-pop/v2/pop/popmw", 32 "github.com/gobuffalo/plush": "github.com/gobuffalo/plush/v4", 33 } 34 35 var ic = ImportConverter{ 36 Data: replace, 37 } 38 39 var mr = MiddlewareTransformer{ 40 PackagesReplacement: map[string]string{ 41 "github.com/gobuffalo/buffalo/middleware/basicauth": "github.com/gobuffalo/mw-basicauth", 42 "github.com/gobuffalo/buffalo/middleware/csrf": "github.com/gobuffalo/mw-csrf", 43 "github.com/gobuffalo/buffalo/middleware/i18n": "github.com/gobuffalo/mw-i18n", 44 "github.com/gobuffalo/buffalo/middleware/ssl": "github.com/gobuffalo/mw-forcessl", 45 "github.com/gobuffalo/buffalo/middleware/tokenauth": "github.com/gobuffalo/mw-tokenauth", 46 }, 47 48 Aliases: map[string]string{ 49 "github.com/gobuffalo/mw-basicauth": "basicauth", 50 "github.com/gobuffalo/mw-contenttype": "contenttype", 51 "github.com/gobuffalo/mw-csrf": "csrf", 52 "github.com/gobuffalo/mw-forcessl": "forcessl", 53 "github.com/gobuffalo/mw-i18n": "i18n", 54 "github.com/gobuffalo/mw-paramlogger": "paramlogger", 55 "github.com/gobuffalo/mw-tokenauth": "tokenauth", 56 }, 57 } 58 59 var checks = []Check{ 60 PackrClean, 61 ic.Process, 62 mr.transformPackages, 63 WebpackCheck, 64 PackageJSONCheck, 65 AddPackageJSONScripts, 66 installTools, 67 DeprecrationsCheck, 68 fixDocker, 69 encodeApp, 70 Plugins{}.RemoveOld, 71 Plugins{}.CleanCache, 72 Plugins{}.Reinstall, 73 Plush, 74 } 75 76 func encodeApp(r *Runner) error { 77 p := filepath.Join("config", "buffalo-app.toml") 78 if _, err := os.Stat(p); err == nil { 79 return nil 80 } 81 os.MkdirAll(filepath.Dir(p), 0755) 82 f, err := os.Create(p) 83 if err != nil { 84 return err 85 } 86 if err := toml.NewEncoder(f).Encode(r.App); err != nil { 87 return err 88 } 89 return nil 90 } 91 92 func ask(q string) bool { 93 if YesToAll { 94 return true 95 } 96 97 fmt.Printf("? %s [y/n]\n", q) 98 99 reader := bufio.NewReader(os.Stdin) 100 text, _ := reader.ReadString('\n') 101 102 text = strings.ToLower(strings.TrimSpace(text)) 103 return text == "y" || text == "yes" 104 }