gantry-web 0.1.0 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/vite/index.js +42 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gantry-web",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Frontend half of the Gantry desktop app framework: window chrome, native bridge, Tea runtime, Vite plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/vite/index.js CHANGED
@@ -28,23 +28,33 @@ export function gantry(opts = {}) {
28
28
  let appRoot = "";
29
29
  let goPort = opts.goPort ?? 0;
30
30
 
31
+ // Pairs nest to any depth: pages/account/settings/settings.tsx is
32
+ // the pair "pages/account/settings" and serves /account/settings. A
33
+ // folder both IS a pair and CONTAINS pairs when it wants to
34
+ // (pages/account/account.tsx + pages/account/settings/...).
31
35
  function scanKind(kind) {
32
- const dir = path.join(appRoot, kind);
36
+ const root = path.join(appRoot, kind);
33
37
  const out = [];
34
- if (!fs.existsSync(dir)) return out;
35
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
36
- if (!entry.isDirectory()) continue;
37
- const name = entry.name;
38
- const tsx = path.join(dir, name, name + ".tsx");
39
- if (!fs.existsSync(tsx)) continue;
40
- const css = path.join(dir, name, name + ".css");
41
- out.push({
42
- key: kind + "/" + name,
43
- name,
44
- tsx: tsx.split(path.sep).join("/"),
45
- css: fs.existsSync(css) ? css.split(path.sep).join("/") : null,
46
- });
47
- }
38
+ if (!fs.existsSync(root)) return out;
39
+ const walk = (dir) => {
40
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
41
+ if (!entry.isDirectory()) continue;
42
+ const sub = path.join(dir, entry.name);
43
+ const tsx = path.join(sub, entry.name + ".tsx");
44
+ if (fs.existsSync(tsx)) {
45
+ const rel = path.relative(root, sub).split(path.sep).join("/");
46
+ const css = path.join(sub, entry.name + ".css");
47
+ out.push({
48
+ key: kind + "/" + rel,
49
+ name: rel,
50
+ tsx: tsx.split(path.sep).join("/"),
51
+ css: fs.existsSync(css) ? css.split(path.sep).join("/") : null,
52
+ });
53
+ }
54
+ walk(sub);
55
+ }
56
+ };
57
+ walk(root);
48
58
  out.sort((a, b) => a.key.localeCompare(b.key));
49
59
  return out;
50
60
  }
@@ -90,8 +100,18 @@ export function gantry(opts = {}) {
90
100
  // The derived route only; an optional "export const route" on the
91
101
  // page module overrides it at runtime (createApp checks mod.route
92
102
  // there - referencing it here would make rollup warn on every
93
- // page that does not export it).
94
- const route = p.name === "index" ? "/" : "/" + p.name;
103
+ // page that does not export it). Nested pages route by their
104
+ // path; an "index" leaf maps to the parent:
105
+ // pages/index -> /, pages/account/settings -> /account/settings,
106
+ // pages/account/index -> /account
107
+ let route;
108
+ if (p.name === "index") {
109
+ route = "/";
110
+ } else if (p.name.endsWith("/index")) {
111
+ route = "/" + p.name.slice(0, -"/index".length);
112
+ } else {
113
+ route = "/" + p.name;
114
+ }
95
115
  return `{ key: ${JSON.stringify(p.key)}, route: ${JSON.stringify(route)}, mod: p${i} }`;
96
116
  });
97
117
  lines.push(`export const pages = [${pageEntries.join(", ")}];`);
@@ -113,8 +133,10 @@ export function gantry(opts = {}) {
113
133
  const root = appRoot.split(path.sep).join("/");
114
134
  if (!file.startsWith(root + "/")) return null;
115
135
  const rel = file.slice(root.length + 1);
116
- const m = rel.match(/^(pages|components|layouts)\/([^/]+)\/([^/]+)\.tsx$/);
117
- if (!m || m[2] !== m[3]) return null;
136
+ const m = rel.match(/^(pages|components|layouts)\/(.+)\/([^/]+)\.tsx$/);
137
+ if (!m) return null;
138
+ const segs = m[2].split("/");
139
+ if (segs[segs.length - 1] !== m[3]) return null;
118
140
  return m[1] + "/" + m[2];
119
141
  }
120
142
 
@@ -184,7 +206,7 @@ export function gantry(opts = {}) {
184
206
  const root = appRoot.split(path.sep).join("/");
185
207
  if (!f.startsWith(root)) return;
186
208
  if (
187
- !/\/(pages|components|layouts)\/[^/]+\/[^/]+\.(tsx|css)$/.test(f) &&
209
+ !/\/(pages|components|layouts)\/.+\.(tsx|css)$/.test(f) &&
188
210
  !f.endsWith("/index.css") &&
189
211
  !f.endsWith("/app.tsx")
190
212
  ) {