juxscript 1.1.74 → 1.1.76
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 +2 -2
- package/machinery/serve.js +61 -5
- package/package.json +1 -1
package/dom-structure-map.json
CHANGED
package/machinery/compiler3.js
CHANGED
|
@@ -507,8 +507,8 @@ navigate(location.pathname);
|
|
|
507
507
|
*/
|
|
508
508
|
copyPublicFolder() {
|
|
509
509
|
// ✅ Use configured public path or resolve from paths object
|
|
510
|
-
const publicSrc = this.paths.public
|
|
511
|
-
? this.paths.public
|
|
510
|
+
const publicSrc = this.paths.public
|
|
511
|
+
? this.paths.public
|
|
512
512
|
: path.resolve(process.cwd(), this.publicDir);
|
|
513
513
|
|
|
514
514
|
if (!fs.existsSync(publicSrc)) {
|
package/machinery/serve.js
CHANGED
|
@@ -29,10 +29,36 @@ function getArgValue(flag, shortFlag, defaultValue) {
|
|
|
29
29
|
const PORT = parseInt(getArgValue('--port', '-p', process.env.PORT || '3000'));
|
|
30
30
|
const WS_PORT = parseInt(getArgValue('--ws-port', '-w', process.env.WS_PORT || String(PORT + 1)));
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// ✅ Load juxconfig.js to get configured paths
|
|
33
33
|
const PROJECT_ROOT = process.cwd();
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const JUX_CONFIG_PATH = path.resolve(PROJECT_ROOT, 'juxconfig.js');
|
|
35
|
+
|
|
36
|
+
let rawConfig = {};
|
|
37
|
+
try {
|
|
38
|
+
const imported = await import(JUX_CONFIG_PATH);
|
|
39
|
+
rawConfig = imported.config || {};
|
|
40
|
+
console.log(`⚙️ Loaded config: ${JUX_CONFIG_PATH}`);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn(`⚠️ No juxconfig.js found, using defaults`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ✅ Extract configured directories
|
|
46
|
+
const directories = {
|
|
47
|
+
source: rawConfig.directories?.source || './jux',
|
|
48
|
+
distribution: rawConfig.directories?.distribution || './.jux-dist',
|
|
49
|
+
public: rawConfig.directories?.public || './public'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// ✅ Resolve absolute paths
|
|
53
|
+
const paths = {
|
|
54
|
+
source: path.resolve(PROJECT_ROOT, directories.source),
|
|
55
|
+
distribution: path.resolve(PROJECT_ROOT, directories.distribution),
|
|
56
|
+
public: path.resolve(PROJECT_ROOT, directories.public)
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Resolve paths relative to CWD (user's project)
|
|
60
|
+
const DIST_DIR = paths.distribution;
|
|
61
|
+
const SRC_DIR = paths.source;
|
|
36
62
|
|
|
37
63
|
const app = express();
|
|
38
64
|
let lastBuildResult = { success: true, errors: [] };
|
|
@@ -43,7 +69,9 @@ if (!fs.existsSync(DIST_DIR) || !fs.existsSync(path.join(DIST_DIR, 'index.html')
|
|
|
43
69
|
|
|
44
70
|
const compiler = new JuxCompiler({
|
|
45
71
|
srcDir: SRC_DIR,
|
|
46
|
-
distDir: DIST_DIR
|
|
72
|
+
distDir: DIST_DIR,
|
|
73
|
+
publicDir: directories.public, // ✅ Pass configured name
|
|
74
|
+
paths // ✅ Pass resolved paths
|
|
47
75
|
});
|
|
48
76
|
|
|
49
77
|
try {
|
|
@@ -180,6 +208,7 @@ app.get('*', (req, res) => {
|
|
|
180
208
|
const server = http.createServer(app);
|
|
181
209
|
let wss = null;
|
|
182
210
|
let watcher = null;
|
|
211
|
+
let publicWatcher = null; // ✅ Declare at top level
|
|
183
212
|
|
|
184
213
|
if (HOT_RELOAD) {
|
|
185
214
|
wss = new WebSocketServer({ port: WS_PORT });
|
|
@@ -199,7 +228,9 @@ if (HOT_RELOAD) {
|
|
|
199
228
|
|
|
200
229
|
const compiler = new JuxCompiler({
|
|
201
230
|
srcDir: SRC_DIR,
|
|
202
|
-
distDir: DIST_DIR
|
|
231
|
+
distDir: DIST_DIR,
|
|
232
|
+
publicDir: directories.public, // ✅ Pass configured name
|
|
233
|
+
paths // ✅ Pass resolved paths
|
|
203
234
|
});
|
|
204
235
|
|
|
205
236
|
watcher = createWatcher(SRC_DIR, {
|
|
@@ -228,6 +259,29 @@ if (HOT_RELOAD) {
|
|
|
228
259
|
console.log(`👀 Watching: ${SRC_DIR}`);
|
|
229
260
|
}
|
|
230
261
|
});
|
|
262
|
+
|
|
263
|
+
// ✅ ALSO watch public/ directory if it exists
|
|
264
|
+
if (fs.existsSync(paths.public)) {
|
|
265
|
+
console.log(`👀 Watching public assets: ${paths.public}`);
|
|
266
|
+
|
|
267
|
+
publicWatcher = createWatcher(paths.public, {
|
|
268
|
+
onChange: async (changedFiles) => {
|
|
269
|
+
console.log('📦 Public asset changed, copying...');
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
// Just copy public folder, don't rebuild everything
|
|
273
|
+
compiler.copyPublicFolder();
|
|
274
|
+
console.log('✅ Public assets updated');
|
|
275
|
+
broadcast({ type: 'reload', files: changedFiles });
|
|
276
|
+
} catch (err) {
|
|
277
|
+
console.warn('⚠️ Error copying public assets:', err.message);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
onReady: () => {
|
|
281
|
+
// Silent, already logged main watcher
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
231
285
|
}
|
|
232
286
|
|
|
233
287
|
server.listen(PORT, () => {
|
|
@@ -240,9 +294,11 @@ server.listen(PORT, () => {
|
|
|
240
294
|
}
|
|
241
295
|
});
|
|
242
296
|
|
|
297
|
+
// ✅ Define shutdown AFTER all variables are initialized
|
|
243
298
|
const shutdown = () => {
|
|
244
299
|
console.log('\n👋 Shutting down...');
|
|
245
300
|
if (watcher) watcher.close();
|
|
301
|
+
if (publicWatcher) publicWatcher.close(); // ✅ Close public watcher
|
|
246
302
|
if (wss) {
|
|
247
303
|
wss.clients.forEach(client => client.terminate());
|
|
248
304
|
wss.close();
|