plugin struct

Methods:

Name


Returns:
  • string

Show/Hide Method Body
{ return "devtools" }

Priority


Returns:
  • int

Show/Hide Method Body
{ return 100 }

PreBuild


Parameters:
  • json.RawMessage

Returns:
  • error

Show/Hide Method Body
{
	stub := []byte("package main\nimport _ \"github.com/rfwlab/rfw/v1/devtools\"\n")
	return os.WriteFile("rfw_devtools.go", stub, 0o644)
}

PostBuild


Parameters:
  • json.RawMessage

Returns:
  • error

Show/Hide Method Body
{
	dst := filepath.Join("build", "client", "rfw-devtools.js")
	if err := os.WriteFile(dst, devtoolsJS, 0o644); err != nil {
		return err
	}
	info, err := json.Marshal(plugins.Active())
	if err != nil {
		return err
	}
	f, err := os.OpenFile(dst, os.O_APPEND|os.O_WRONLY, 0)
	if err != nil {
		return err
	}
	if _, err := fmt.Fprintf(f, "\n;globalThis.RFW_DEVTOOLS_PLUGINS=()=>%s;\n", info); err != nil {
		f.Close()
		return err
	}
	if err := f.Close(); err != nil {
		return err
	}
	index := filepath.Join("build", "client", "index.html")
	data, err := os.ReadFile(index)
	if err != nil {
		return err
	}
	if !bytes.Contains(data, []byte("rfw-devtools.js")) {
		injection := []byte("\n<script type=\"module\" src=\"/rfw-devtools.js\"></script>\n")
		data = bytes.Replace(data, []byte("</body>"), append(injection, []byte("</body>")...), 1)
		if err := os.WriteFile(index, data, 0o644); err != nil {
			return err
		}
	}
	_ = os.Remove("rfw_devtools.go")
	return nil
}

ShouldRebuild


Parameters:
  • path string

Returns:
  • bool

Show/Hide Method Body
{
	return strings.HasSuffix(path, "devtools.js")
}

init function

Show/Hide Function Body
{ plugins.Register(&plugin{}) }

bytes import

Import example:

import "bytes"

embed import

Import example:

import "embed"

Imported as:

Anonymous Import

encoding/json import

Import example:

import "encoding/json"

fmt import

Import example:

import "fmt"

os import

Import example:

import "os"

path/filepath import

Import example:

import "path/filepath"

strings import

Import example:

import "strings"

github.com/rfwlab/rfw/cmd/rfw/plugins import

Import example:

import "github.com/rfwlab/rfw/cmd/rfw/plugins"