juxscript 1.1.120 → 1.1.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dom-structure-map.json +1 -1
- package/machinery/compiler3.js +56 -16
- package/package.json +1 -1
package/dom-structure-map.json
CHANGED
package/machinery/compiler3.js
CHANGED
|
@@ -53,24 +53,47 @@ export class JuxCompiler {
|
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* ✅ Recursively scan for .jux and .js files in srcDir and subdirectories
|
|
58
|
+
*/
|
|
56
59
|
scanFiles() {
|
|
57
|
-
const files = fs.readdirSync(this.srcDir)
|
|
58
|
-
.filter(f => (f.endsWith('.jux') || f.endsWith('.js')) && !this.isAssetFile(f));
|
|
59
|
-
|
|
60
60
|
const views = [], dataModules = [], sharedModules = [];
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Recursive directory scanner
|
|
64
|
+
*/
|
|
65
|
+
const scanDirectory = (currentDir) => {
|
|
66
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
67
|
+
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
70
|
+
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
// ✅ Recurse into subdirectories
|
|
73
|
+
scanDirectory(fullPath);
|
|
74
|
+
} else if (entry.isFile()) {
|
|
75
|
+
const file = entry.name;
|
|
76
|
+
|
|
77
|
+
// ✅ Only process .jux and .js files (skip assets)
|
|
78
|
+
if ((file.endsWith('.jux') || file.endsWith('.js')) && !this.isAssetFile(file)) {
|
|
79
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
80
|
+
const relativePath = path.relative(this.srcDir, fullPath);
|
|
81
|
+
const name = relativePath.replace(/\.[^/.]+$/, ''); // Remove extension
|
|
82
|
+
|
|
83
|
+
if (file.includes('data')) {
|
|
84
|
+
dataModules.push({ name, file: relativePath, content });
|
|
85
|
+
} else if (/export\s+(function|const|let|var|class)\s+/.test(content)) {
|
|
86
|
+
sharedModules.push({ name, file: relativePath, content });
|
|
87
|
+
} else {
|
|
88
|
+
views.push({ name, file: relativePath, content });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
72
92
|
}
|
|
73
|
-
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ✅ Start recursive scan from srcDir
|
|
96
|
+
scanDirectory(this.srcDir);
|
|
74
97
|
|
|
75
98
|
return { views, dataModules, sharedModules };
|
|
76
99
|
}
|
|
@@ -209,8 +232,10 @@ export class JuxCompiler {
|
|
|
209
232
|
entry += `\n// --- VIEW FUNCTIONS ---\n`;
|
|
210
233
|
|
|
211
234
|
views.forEach(v => {
|
|
212
|
-
|
|
213
|
-
|
|
235
|
+
// ✅ Sanitize the name for use in function names
|
|
236
|
+
// Replace slashes, dots, and other invalid characters with underscores
|
|
237
|
+
const sanitizedName = v.name.replace(/[\/\\.\\-\s]/g, '_');
|
|
238
|
+
const capitalized = sanitizedName.charAt(0).toUpperCase() + sanitizedName.slice(1);
|
|
214
239
|
|
|
215
240
|
sourceSnapshot[v.file] = {
|
|
216
241
|
name: v.name,
|
|
@@ -222,6 +247,7 @@ export class JuxCompiler {
|
|
|
222
247
|
let viewCode = this.removeImports(v.content).replace(/^\s*export\s+default\s+.*$/gm, '');
|
|
223
248
|
const asyncPrefix = viewCode.includes('await ') ? 'async ' : '';
|
|
224
249
|
|
|
250
|
+
// ✅ Use sanitized name in function declaration
|
|
225
251
|
entry += `\n${asyncPrefix}function render${capitalized}() {\n${viewCode}\n}\n`;
|
|
226
252
|
});
|
|
227
253
|
|
|
@@ -580,4 +606,18 @@ navigate(location.pathname);
|
|
|
580
606
|
};
|
|
581
607
|
return icons[ext.toLowerCase()] || '📦';
|
|
582
608
|
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* ✅ Generate name from folder structure
|
|
612
|
+
* Example: abc/aaa.jux -> abc_aaa
|
|
613
|
+
* Example: components/header.jux -> components_header
|
|
614
|
+
*/
|
|
615
|
+
_generateNameFromPath(filepath) {
|
|
616
|
+
return filepath
|
|
617
|
+
.replace(/\.jux$/, '') // Remove .jux extension
|
|
618
|
+
.replace(/[\/\\]/g, '_') // Replace slashes with underscores
|
|
619
|
+
.replace(/[^a-zA-Z0-9_]/g, '_') // Replace any other invalid chars
|
|
620
|
+
.replace(/_+/g, '_') // Collapse multiple underscores
|
|
621
|
+
.replace(/^_|_$/g, ''); // Remove leading/trailing underscores
|
|
622
|
+
}
|
|
583
623
|
}
|