Skip to content

Commit 803dbef

Browse files
chore: wip
1 parent 01816a1 commit 803dbef

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

examples/licenses.stx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@
625625

626626
<script>
627627
// License Manager JavaScript
628+
console.log('License Manager script loaded');
629+
628630
let licenses = [
629631
{
630632
key: 'STX-2024-ABC123-XYZ789',
@@ -836,17 +838,27 @@
836838

837839
// Window management functions
838840
function minimizeWindow(windowId) {
841+
console.log('minimizeWindow called with:', windowId);
839842
document.getElementById(windowId).classList.add('minimized');
840843
}
841844

842845
function maximizeWindow(windowId) {
846+
console.log('maximizeWindow called with:', windowId);
843847
const window = document.getElementById(windowId);
844848
window.classList.toggle('maximized');
845849
}
846850

847851
function closeWindow(windowId) {
852+
console.log('closeWindow called with:', windowId);
848853
document.getElementById(windowId).classList.add('minimized');
849854
}
855+
856+
// Test if functions are defined
857+
console.log('Functions defined:', {
858+
minimizeWindow: typeof minimizeWindow,
859+
maximizeWindow: typeof maximizeWindow,
860+
closeWindow: typeof closeWindow
861+
});
850862

851863
// Update clock
852864
function updateClock() {

packages/stx/src/plugin.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,24 @@ export const plugin: BunPlugin = {
117117
)
118118

119119
// Process template directives with performance monitoring
120-
const output = await performanceMonitor.timeAsync('directive-processing', async () => {
120+
const processedTemplate = await performanceMonitor.timeAsync('directive-processing', async () => {
121121
return await processDirectives(templateContent, context, filePath, options, dependencies)
122122
})
123123

124+
// Preserve script content in final output
125+
let output = processedTemplate
126+
if (scriptContent.trim()) {
127+
// Find the closing </body> tag and insert script before it
128+
const bodyEndMatch = output.match(/(<\/body>)/i)
129+
if (bodyEndMatch) {
130+
const scriptTag = `<script>\n${scriptContent}\n</script>`
131+
output = output.replace(/(<\/body>)/i, `${scriptTag}\n$1`)
132+
} else {
133+
// If no </body> tag, append script at the end
134+
output += `\n<script>\n${scriptContent}\n</script>`
135+
}
136+
}
137+
124138
// Track dependencies for this file
125139
dependencies.forEach(dep => allDependencies.add(dep))
126140

packages/stx/src/serve.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,21 @@ export async function serve(options: ServeOptions = {}): Promise<ServeResult> {
9393

9494
// Process template
9595
const dependencies = new Set<string>()
96-
const output = await processDirectives(templateContent, context, filePath, stxOptions, dependencies)
96+
const processedTemplate = await processDirectives(templateContent, context, filePath, stxOptions, dependencies)
97+
98+
// Preserve script content in final output
99+
let output = processedTemplate
100+
if (scriptContent.trim()) {
101+
// Find the closing </body> tag and insert script before it
102+
const bodyEndMatch = output.match(/(<\/body>)/i)
103+
if (bodyEndMatch) {
104+
const scriptTag = `<script>\n${scriptContent}\n</script>`
105+
output = output.replace(/(<\/body>)/i, `${scriptTag}\n$1`)
106+
} else {
107+
// If no </body> tag, append script at the end
108+
output += `\n<script>\n${scriptContent}\n</script>`
109+
}
110+
}
97111

98112
// Cache result
99113
fileCache.set(cacheKey, { content: output, mtime: stats.mtimeMs })

0 commit comments

Comments
 (0)