azoxjs 0.1.0 → 0.2.0

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.
@@ -7,7 +7,7 @@
7
7
  import { resolve } from 'node:path';
8
8
  import { existsSync } from 'node:fs';
9
9
 
10
- import { buildAll, BuildError, PAGES_DIR, BUILD_DIR } from '../build.js';
10
+ import { buildAll, BuildError, PAGES_DIR, PUBLIC_DIR, COMPONENTS_DIR, BUILD_DIR } from '../build.js';
11
11
  import { createDevServer } from '../dev/server.js';
12
12
  import { watchDirectory } from '../dev/watcher.js';
13
13
  import { injectLiveReload } from '../dev/liveReload.js';
@@ -58,24 +58,39 @@ export async function devCommand({ flags }) {
58
58
  console.log(' Watching for changes. Press Ctrl+C to stop.');
59
59
  console.log('');
60
60
 
61
- const stopWatching = watchDirectory(
62
- pagesDir,
63
- (filename) => {
64
- const result = rebuild(projectDir);
65
- dev.setBuildError(result.ok ? null : result.error);
66
-
67
- if (result.ok) {
68
- console.log(` rebuilt${filename ? ` (${filename})` : ''}`);
69
- } else {
70
- reportFailure(result.error);
71
- }
72
-
73
- // Reload either way: on failure the browser picks up the error
74
- // page the server renders in place of the build output.
75
- dev.reload();
76
- },
77
- { filter: (filename) => filename.endsWith('.azox') }
78
- );
61
+ const onChange = (filename) => {
62
+ const result = rebuild(projectDir);
63
+ dev.setBuildError(result.ok ? null : result.error);
64
+
65
+ if (result.ok) {
66
+ console.log(` rebuilt${filename ? ` (${filename})` : ''}`);
67
+ } else {
68
+ reportFailure(result.error);
69
+ }
70
+
71
+ // Reload either way: on failure the browser picks up the error
72
+ // page the server renders in place of the build output.
73
+ dev.reload();
74
+ };
75
+
76
+ // Everything a page is built from, not just the pages themselves.
77
+ // Watching pages/ alone meant editing a component or a stylesheet
78
+ // did nothing until an unrelated .azox file was touched.
79
+ const watched = [
80
+ { dir: pagesDir, filter: (name) => name.endsWith('.azox') },
81
+ { dir: resolve(projectDir, COMPONENTS_DIR), filter: (name) => name.endsWith('.azox') },
82
+ // public/ holds stylesheets, fonts and images; any of them
83
+ // changing is worth a reload.
84
+ { dir: resolve(projectDir, PUBLIC_DIR), filter: () => true },
85
+ ];
86
+
87
+ const stoppers = watched
88
+ .filter(({ dir }) => existsSync(dir))
89
+ .map(({ dir, filter }) => watchDirectory(dir, onChange, { filter }));
90
+
91
+ const stopWatching = () => {
92
+ for (const stop of stoppers) stop();
93
+ };
79
94
 
80
95
  const shutdown = async () => {
81
96
  stopWatching();
@@ -5,6 +5,7 @@ import { readFileSync } from 'node:fs';
5
5
 
6
6
  import { parseAzox } from '../compiler/parser.js';
7
7
  import { resolveComponents } from '../compiler/resolveComponents.js';
8
+ import { createNodeResolver } from '../nodeResolver.js';
8
9
  import { listRoutes, PAGES_DIR } from '../build.js';
9
10
  import { BANNER, VERSION } from '../meta.js';
10
11
 
@@ -38,7 +39,11 @@ export function doctorCommand() {
38
39
  // build.
39
40
  for (const route of routes) {
40
41
  try {
41
- resolveComponents(parseAzox(readFileSync(route.sourcePath, 'utf8')), route.sourcePath);
42
+ resolveComponents(
43
+ parseAzox(readFileSync(route.sourcePath, 'utf8')),
44
+ route.sourcePath,
45
+ createNodeResolver()
46
+ );
42
47
  checks.push({ ok: true, label: `${route.url}`, note: `${PAGES_DIR}/${route.name}.azox` });
43
48
  } catch (error) {
44
49
  checks.push({