@sealcode/sealgen 0.17.4 → 0.17.5

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/lib/add-route.js CHANGED
@@ -47,11 +47,12 @@ async function addRoute(params, app_directory = process.cwd()) {
47
47
  ]);
48
48
  const { action, url, mode } = response;
49
49
  const extension = ["list", "lpr", "page", "sreact"].includes(mode) ? "tsx" : "ts";
50
+ const base_file_name = escape_url_params(url) || "index";
50
51
  const file_path = target_locreq.resolve(
51
- `src/back/routes/${escape_url_params(url)}.${mode}.${extension}`
52
+ `src/back/routes/${base_file_name}.${mode}.${extension}`
52
53
  );
53
54
  const test_file_path = target_locreq.resolve(
54
- `src/back/routes/${escape_url_params(url)}.test.ts`
55
+ `src/back/routes/${base_file_name}.test.ts`
55
56
  );
56
57
  const template = Templates[mode];
57
58
  if (!template) {
@@ -42,6 +42,7 @@ async function generateRoutes() {
42
42
  ).map(async (fullpath) => ({
43
43
  fullpath,
44
44
  actionName: await extractActionName(fullpath),
45
+ // trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
45
46
  url: unescape_url_params(
46
47
  "/" + relative(
47
48
  target_locreq.resolve("src/back/routes"),
@@ -50,8 +51,7 @@ async function generateRoutes() {
50
51
  basename(fullpath).startsWith("index.") ? "../" : ""
51
52
  )
52
53
  ).replace(/\..+/, "") + "/"
53
- // trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
54
- )
54
+ ).replace(/\/\//g, "/")
55
55
  }))
56
56
  );
57
57
  const routes_content = `// DO NOT EDIT! This file is generated automaticaly with npm run generate-routes
@@ -15,7 +15,7 @@ export default new (class ${action_name}Page extends Page {
15
15
  }
16
16
 
17
17
  async render(ctx: Context) {
18
- return html(ctx, "${action_name}", <div></div>);
18
+ return html({ ctx: ctx, title: "${action_name}", body: <div></div>, description: "" });
19
19
  }
20
20
  })();
21
21
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.17.4",
3
+ "version": "0.17.5",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
package/src/add-route.ts CHANGED
@@ -58,11 +58,12 @@ export async function addRoute(
58
58
  ? "tsx"
59
59
  : "ts";
60
60
 
61
+ const base_file_name = escape_url_params(url) || "index";
61
62
  const file_path = target_locreq.resolve(
62
- `src/back/routes/${escape_url_params(url)}.${mode}.${extension}`
63
+ `src/back/routes/${base_file_name}.${mode}.${extension}`
63
64
  );
64
65
  const test_file_path = target_locreq.resolve(
65
- `src/back/routes/${escape_url_params(url)}.test.ts`
66
+ `src/back/routes/${base_file_name}.test.ts`
66
67
  );
67
68
  const template = Templates[mode as keyof typeof Templates];
68
69
 
@@ -61,6 +61,7 @@ export async function generateRoutes(): Promise<void> {
61
61
  .map(async (fullpath) => ({
62
62
  fullpath,
63
63
  actionName: await extractActionName(fullpath),
64
+ // trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
64
65
  url: unescape_url_params(
65
66
  "/" +
66
67
  relative(
@@ -72,8 +73,8 @@ export async function generateRoutes(): Promise<void> {
72
73
  : ""
73
74
  )
74
75
  ).replace(/\..+/, "") +
75
- "/" // trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
76
- ),
76
+ "/"
77
+ ).replace(/\/\//g, "/"),
77
78
  }))
78
79
  );
79
80
 
@@ -18,7 +18,7 @@ export default new (class ${action_name}Page extends Page {
18
18
  }
19
19
 
20
20
  async render(ctx: Context) {
21
- return html(ctx, "${action_name}", <div></div>);
21
+ return html({ ctx: ctx, title: "${action_name}", body: <div></div>, description: "" });
22
22
  }
23
23
  })();
24
24
  `;