Skip to content

Commit

Permalink
Remove goroutines that break v8go ctx.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Jul 9, 2020
1 parent 757e2ec commit 8a5693b
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"rogchap.com/v8go"
Expand All @@ -21,8 +20,6 @@ func Client(buildPath string) {

Log("\nCompiling client SPA with svelte")

var wg sync.WaitGroup

stylePath := buildPath + "/spa/bundle.css"

// Set up counter for logging output.
Expand All @@ -35,12 +32,9 @@ func Client(buildPath string) {
}
// Remove reference to 'self' that breaks v8go.
compilerStr := strings.Replace(string(compiler), "self.performance.now();", "'';", 1)
//ctx, _ := v8go.NewContext(nil)
//ctx.RunScript(compilerStr, "compile_svelte")
wg.Add(1)
go compileSvelte(compilerStr, "ejected/router.svelte", buildPath+"/spa/ejected/router.js", stylePath, &wg, 1)
//go compileSvelte(ctx, "ejected/router.svelte", buildPath+"/spa/ejected/router.js", stylePath, &wg, 1)
//compileSvelte(ctx, "ejected/router.svelte", buildPath+"/spa/ejected/router.js", stylePath, &wg)
ctx, _ := v8go.NewContext(nil)
ctx.RunScript(compilerStr, "compile_svelte")
compileSvelte(ctx, "ejected/router.svelte", buildPath+"/spa/ejected/router.js", stylePath)

// Go through all file paths in the "/layout" folder.
layoutFilesErr := filepath.Walk("layout", func(layoutPath string, layoutFileInfo os.FileInfo, err error) error {
Expand All @@ -57,14 +51,10 @@ func Client(buildPath string) {
// Replace .svelte file extension with .js.
destFile = strings.TrimSuffix(destFile, filepath.Ext(destFile)) + ".js"

//compileSvelte(ctx, layoutPath, destFile, stylePath, &wg)
compileSvelte(ctx, layoutPath, destFile, stylePath)

compiledComponentCounter++

wg.Add(1)
go compileSvelte(compilerStr, layoutPath, destFile, stylePath, &wg, compiledComponentCounter+1)
//go compileSvelte(ctx, layoutPath, destFile, stylePath, &wg, compiledComponentCounter+1)

}
}
return nil
Expand All @@ -73,23 +63,11 @@ func Client(buildPath string) {
fmt.Printf("Could not get layout file: %s", layoutFilesErr)
}

fmt.Println("Not done..")
wg.Wait()
fmt.Println("Done!")

Log("Number of components compiled: " + strconv.Itoa(compiledComponentCounter))

}

//func compileSvelte(ctx *v8go.Context, layoutPath string, destFile string, stylePath string, wg *sync.WaitGroup, count int) {
func compileSvelte(compileStr string, layoutPath string, destFile string, stylePath string, wg *sync.WaitGroup, count int) {

fmt.Println(count)

defer wg.Done()

ctx, _ := v8go.NewContext(nil)
ctx.RunScript(compileStr, "compile_svelte")
func compileSvelte(ctx *v8go.Context, layoutPath string, destFile string, stylePath string) {

component, err := ioutil.ReadFile(layoutPath)
if err != nil {
Expand Down Expand Up @@ -117,7 +95,6 @@ func compileSvelte(compileStr string, layoutPath string, destFile string, styleP
fmt.Printf("V8go could not execute css.code: %v", err)
}
cssStr := strings.TrimSpace(cssCode.String())
fmt.Println(cssStr)
// If there is CSS, write it into the bundle.css file.
if cssStr != "null" {
cssFile, WriteStyleErr := os.OpenFile(stylePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand Down

0 comments on commit 8a5693b

Please sign in to comment.