github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/buffalo/cmd/fix/deprecations.go (about)

     1  package fix
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"io/ioutil"
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  // DeprecrationsCheck will either log, or fix, deprecated items in the application
    12  func DeprecrationsCheck(r *Runner) error {
    13  	fmt.Println("~~~ Checking for deprecations ~~~")
    14  	b, err := ioutil.ReadFile("main.go")
    15  	if err != nil {
    16  		return err
    17  	}
    18  	if bytes.Contains(b, []byte("app.Start")) {
    19  		r.Warnings = append(r.Warnings, "app.Start has been removed in v0.11.0. Use app.Serve Instead. [main.go]")
    20  	}
    21  
    22  	return filepath.Walk(filepath.Join(r.App.Root, "actions"), func(path string, info os.FileInfo, _ error) error {
    23  		if info.IsDir() {
    24  			return nil
    25  		}
    26  
    27  		if filepath.Ext(path) != ".go" {
    28  			return nil
    29  		}
    30  
    31  		b, err := ioutil.ReadFile(path)
    32  		if err != nil {
    33  			return err
    34  		}
    35  		if bytes.Contains(b, []byte("Websocket()")) {
    36  			r.Warnings = append(r.Warnings, fmt.Sprintf("buffalo.Context#Websocket has been deprecated in v0.11.0, and removed in v0.12.0. Use github.com/gorilla/websocket directly. [%s]", path))
    37  		}
    38  		if bytes.Contains(b, []byte("meta.Name")) {
    39  			r.Warnings = append(r.Warnings, fmt.Sprintf("meta.Name has been deprecated in v0.11.0, and removed in v0.12.0. Use github.com/markbates/inflect.Name directly. [%s]", path))
    40  		}
    41  		if bytes.Contains(b, []byte("generators.Find(")) {
    42  			r.Warnings = append(r.Warnings, fmt.Sprintf("generators.Find(string) has been deprecated in v0.11.0, and removed in v0.12.0. Use generators.FindByBox() instead. [%s]", path))
    43  		}
    44  		// i18n middleware changes in v0.11.1
    45  		if bytes.Contains(b, []byte("T.CookieName")) {
    46  			b = bytes.Replace(b, []byte("T.CookieName"), []byte("T.LanguageExtractorOptions[\"CookieName\"]"), -1)
    47  		}
    48  		if bytes.Contains(b, []byte("T.SessionName")) {
    49  			b = bytes.Replace(b, []byte("T.SessionName"), []byte("T.LanguageExtractorOptions[\"SessionName\"]"), -1)
    50  		}
    51  		if bytes.Contains(b, []byte("T.LanguageFinder=")) || bytes.Contains(b, []byte("T.LanguageFinder ")) {
    52  			r.Warnings = append(r.Warnings, fmt.Sprintf("i18n.Translator#LanguageFinder has been deprecated in v0.11.1, and has been removed in v0.12.0. Use i18n.Translator#LanguageExtractors instead. [%s]", path))
    53  		}
    54  		ioutil.WriteFile(path, b, 0664)
    55  
    56  		return nil
    57  	})
    58  }