Skip to content

Commit

Permalink
Move compiled app into layouts dir (#191).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Jan 8, 2023
1 parent b21b299 commit 9195a50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func Client(buildPath string, coreFS embed.FS) error {
}
// Initialize var to hold actual component file contents
var componentStr string
// Remove the root folder since that doesn't get written to fs
path = strings.TrimPrefix(path, "defaults/")
// Check if the path has been ejected to the filesystem.
_, err = os.Stat(path)
// Check if the path has been ejected to the virtual filesystem for a theme build.
Expand Down Expand Up @@ -209,7 +207,7 @@ func copyNonSvelteFiles(layoutPath string, buildPath string) error {
}
defer from.Close()

destPath := buildPath + "/spa/" + strings.TrimPrefix(layoutPath, "layouts/")
destPath := buildPath + "/spa/" + layoutPath
// Create any sub directories need for filepath.
if err := os.MkdirAll(filepath.Dir(destPath), os.ModePerm); err != nil {
return fmt.Errorf("can't make folders for '%s': %w\n", destPath, err)
Expand All @@ -234,7 +232,7 @@ func compileComponent(err error, layoutPath string, layoutFileInfo os.FileInfo,
return compiledComponentCounter, allLayoutsStr, fmt.Errorf("can't stat %s: %w", layoutPath, err)
}
// Create destination path.
destFile := buildPath + "/spa/" + strings.TrimPrefix(layoutPath, "layouts/")
destFile := buildPath + "/spa/" + layoutPath
// If the file is in .svelte format, compile it to .js
if filepath.Ext(layoutPath) == ".svelte" {
// Replace .svelte file extension with .js.
Expand All @@ -251,10 +249,8 @@ func compileComponent(err error, layoutPath string, layoutFileInfo os.FileInfo,
}
// Create entry for layouts.js.
layoutSignature := strings.ReplaceAll(strings.ReplaceAll((layoutPath), "/", "_"), ".", "_")
// Remove layouts directory.
destLayoutPath := strings.TrimPrefix(layoutPath, "layouts/")
// Compose entry for layouts.js file.
allLayoutsStr = allLayoutsStr + "export {default as " + layoutSignature + "} from '../" + destLayoutPath + "';\n"
allLayoutsStr = allLayoutsStr + "export {default as " + layoutSignature + "} from '../" + layoutPath + "';\n"
// Increment counter for each compiled component.
compiledComponentCounter++
}
Expand Down
4 changes: 2 additions & 2 deletions defaults/core/router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
const defaultContent = allDefaults.find(defaultContent => defaultContent.type == type);
if (type && filename && defaultContent) {
import('../content/' + type + '.js').then(m => {
import('../layouts/content/' + type + '.js').then(m => {
content = structuredClone(defaultContent);
content.isNew = true;
content.filename = filename + '.json';
Expand All @@ -109,7 +109,7 @@
return;
}
import('../content/' + content.type + '.js')
import('../layouts/content/' + content.type + '.js')
.then(m => draw(m, content))
.catch(handle404);
});
Expand Down

0 comments on commit 9195a50

Please sign in to comment.