Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyARoss committed Sep 11, 2024
1 parent d148ca3 commit 067d54e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ var buildCMD = &cobra.Command{
WebPrefix: outDir,
CacheDir: "",
})
// note: altering the order of the appends will break functionality
htmlDoc.Body = append(htmlDoc.Body, wr.DocumentTag(spaEntryComponent.BundleKey()))

htmlDoc.Body = append(htmlDoc.Body, body...)
htmlDoc.Body = append(htmlDoc.Body, fmt.Sprintf(`<script src="./%s.js"></script>`, spaEntryComponent.BundleKey()))

Expand Down
4 changes: 3 additions & 1 deletion examples/spa/pages/app.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const Example = () => {
const date = new Date();

return (
<div className="orbit-integration-applied">
<h1>Orbit!</h1>
<p>Welcome to this example</p>
<p>
Today is {day}/{month}/{year}
Today is {date.toString()}
</p>
</div>
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/webwrap/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type JavascriptWrap struct {

const javascriptExtension string = "js"

func (s *JavascriptWrap) DocumentTag(string) string { return "" }

func (s *JavascriptWrap) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) {
if page.Extension() != javascriptExtension { // @@todo bad pattern fix this
return nil, fmt.Errorf("invalid extension %s", page.Extension())
Expand Down
4 changes: 4 additions & 0 deletions pkg/webwrap/react_csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type ReactCSR struct {
var ErrComponentExport = errors.New("prefer capitalization for jsx components")
var ErrInvalidComponent = errors.New("invalid jsx component")

func (s *ReactCSR) DocumentTag(key string) string {
return fmt.Sprintf(`<div id="%s_react_frame"></script>`, key)
}

func (s *ReactCSR) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) {
if len(string(page.Name())) == 0 {
return nil, ErrInvalidComponent
Expand Down
4 changes: 4 additions & 0 deletions pkg/webwrap/react_hydrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type ReactHydrate struct {
ssr *PartialWrapReactSSR
}

func (s *ReactHydrate) DocumentTag(key string) string {
return fmt.Sprintf(`<div id="%s_react_frame"></script>`, key)
}

func (s *ReactHydrate) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) {
// react components should always be capitalized.
if string(page.Name()[0]) != strings.ToUpper(string(page.Name()[0])) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/webwrap/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ type JSWebWrapper interface {
Stats() *WrapStats
VerifyRequirements() error
Version() string
DocumentTag(string) string
}

type WrapStats struct {
WebVersion string
Bundler string
WebVersion string
Bundler string
HTMLBodyTag string
}

type JSWebWrapperList []JSWebWrapper
Expand Down

0 comments on commit 067d54e

Please sign in to comment.