Skip to content

Commit

Permalink
Remove parsing node return values on split and file system writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Apr 22, 2020
1 parent 2d11d57 commit 0596706
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 64 deletions.
24 changes: 12 additions & 12 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ you need to deploy for your website.`,
fmt.Printf("Creating data_source took %s\n", elapsed)

start = time.Now()
// Build the client SPA.
// Prep the client SPA.
clientBuildStr := build.Client(buildPath)
fmt.Printf("Client build string: %s", clientBuildStr)
elapsed = time.Since(start)
fmt.Printf("Creating client SPA took %s\n", elapsed)
fmt.Printf("Prepping client SPA data took %s\n", elapsed)

_, buildErr := exec.Command("node", "layout/ejected/build_client.js", clientBuildStr).Output()
start = time.Now()
// Prep the static HTML.
build.Static(nodesList)
elapsed = time.Since(start)
fmt.Printf("Preparing static HTML took %s\n", elapsed)

start = time.Now()
_, buildErr := exec.Command("node", "layout/ejected/build.js", clientBuildStr).Output()
if buildErr != nil {
fmt.Printf("Could not compile svelte to JS: %s\n", buildErr)
}
elapsed = time.Since(start)
fmt.Printf("Compiling components and creating static HTML took %s\n", elapsed)

// Run Snowpack.
//build.Snowpack()

/*
start = time.Now()
// Build the static HTML.
build.Static(nodesList)
elapsed = time.Since(start)
fmt.Printf("Creating static HTML took %s\n", elapsed)
*/

/*
_, NodeErr := exec.Command("node", "layout/ejected/server_router.js").Output()
if NodeErr != nil {
Expand Down
49 changes: 1 addition & 48 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,6 @@ func Client(buildPath string) string {
destFile = strings.TrimSuffix(destFile, filepath.Ext(destFile)) + ".js"

clientBuildStr = clientBuildStr + "{ \"component\": \"" + fileContentStr + "\", \"destPath\": \"" + destFile + "\", \"stylePath\": \"" + stylePath + "\"},"
/*
clientBuildStr = clientBuildStr + fmt.Sprintf(`{
"component": "%s",
"destPath": "%s",
"stylePath": "%s"
},`, escapedFileContentStr, destFile, stylePath)
*/
/*
clientBuildStr = clientBuildStr + "{" +
"\"component\": `" + escapedFileContentStr + "`," +
"\"destPath\": \"" + destFile + "\"," +
"\"stylePath\": \"" + stylePath + "\"},"
*/
/*
// Execute node script to compile .svelte to .js
compiledBytes, buildErr := exec.Command("node", "layout/ejected/build_client.js", fileContentStr).Output()
if buildErr != nil {
fmt.Printf("Could not compile svelte to JS: %s\n", buildErr)
}
compiledStr := string(compiledBytes)
compiledStrArray := strings.Split(compiledStr, "!plenti-split!")
// Get the JS only from the script output.
jsStr := strings.TrimSpace(compiledStrArray[0])
// Write compiled .js to build directory.
jsBytes := []byte(jsStr)
err := ioutil.WriteFile(destFile, jsBytes, 0755)
if err != nil {
fmt.Printf("Unable to write file: %v", err)
}
// Get the CSS only from the script output.
cssStr := strings.TrimSpace(compiledStrArray[1])
// 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)
if WriteStyleErr != nil {
fmt.Printf("Could not open bundle.css for writing: %s", WriteStyleErr)
}
defer cssFile.Close()
if _, err := cssFile.WriteString(cssStr); err != nil {
log.Println(err)
}
}
*/

compiledComponentCounter++

Expand All @@ -166,7 +119,7 @@ func Client(buildPath string) string {
}

fmt.Printf("Number of source files copied: %d\n", copiedSourceCounter)
fmt.Printf("Number of components compiled: %d\n", compiledComponentCounter)
fmt.Printf("Number of components to be compiled: %d\n", compiledComponentCounter)

return clientBuildStr

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import svelte from 'svelte/compiler.js';
import 'svelte/register.js';
import relative from 'require-relative';
import path from 'path';
import fs from 'fs';

// Get the arguments from Go command execution.
const args = process.argv.slice(2)

// -----------------------
// Start client SPA build:
// -----------------------

// Create any missing sub folders.
const ensureDirExists = filePath => {
let dirname = path.dirname(filePath);
Expand Down Expand Up @@ -34,7 +40,18 @@ buildStr.forEach(arg => {
}
});

// Return values to write files in Go.
//console.log(js.code);
//console.log("!plenti-split!");
//console.log(css.code);
// ------------------------
// Start static HTML build:
// ------------------------

let wrapper = path.join(path.resolve(), 'layout/global/html.svelte')
const component = relative(wrapper, process.cwd()).default;

// args[1] is the path to /layout/content .svelte files.
const route = relative(args[1], process.cwd()).default;

// args[2] is the props being passed.
args[2].Route = route; // Add the correct component class instance.

// Create the static HTML and CSS.
let { html, css } = component.render(args[1]);

0 comments on commit 0596706

Please sign in to comment.