tungsten 0.1.37 → 0.1.38

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.
@@ -1,4 +1,5 @@
1
1
  import { FrameworkConfigComplete } from '../FrameworkConfig.js';
2
2
  import type { CompilationInfo } from '../build/CompilationInfo.js';
3
- export declare function getAppRoutes(compilationInfo: CompilationInfo, config: FrameworkConfigComplete): Promise<any>;
3
+ import { AppRoutes } from 'tungsten/routing/AppRoutes.js';
4
+ export declare function getAppRoutes(compilationInfo: CompilationInfo, config: FrameworkConfigComplete): Promise<AppRoutes>;
4
5
  //# sourceMappingURL=getAppRoutes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAppRoutes.d.ts","sourceRoot":"","sources":["../../src/staticGen/getAppRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAIlE,wBAAsB,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,uBAAuB,gBAoBnG"}
1
+ {"version":3,"file":"getAppRoutes.d.ts","sourceRoot":"","sources":["../../src/staticGen/getAppRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAIzD,wBAAsB,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,uBAAuB,GAC9F,OAAO,CAAC,SAAS,CAAC,CAoBvB"}
@@ -1,6 +1,8 @@
1
1
  import { join } from 'path';
2
2
  import { fixExtension } from "../fixExtension.js";
3
3
  import { TungstenError } from "../TungstenError.js";
4
+ // this file is outdated and may not work correct
5
+ // should compare this to the functions used by Servers
4
6
  export async function getAppRoutes(compilationInfo, config) {
5
7
  const fullBuildLocation = 'file://' + compilationInfo.location;
6
8
  const routesLocationConfig = config.routesLocation;
@@ -1 +1 @@
1
- {"version":3,"file":"staticGen.d.ts","sourceRoot":"","sources":["../../src/staticGen/staticGen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAchD,wBAAsB,SAAS,CAAC,SAAS,EAAE,SAAS,iBAgKnD"}
1
+ {"version":3,"file":"staticGen.d.ts","sourceRoot":"","sources":["../../src/staticGen/staticGen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAgBhD,wBAAsB,SAAS,CAAC,SAAS,EAAE,SAAS,iBAqKnD"}
@@ -9,6 +9,7 @@ import { matchPath } from "../routing/matchPath.js";
9
9
  import { throwError } from "../throwError.js";
10
10
  import { RouteKeyIsPath, StringIsPath } from "../routing/RouteTypes.js";
11
11
  import { findLinks, pathToLink, pathToFileName, rewriteLinks } from "./staticGenFunctions.js";
12
+ import { filter as objectFilter, count } from 'sxy-lib/objects.js';
12
13
  export async function staticGen(framework) {
13
14
  if (framework.compilationInfo === undefined) {
14
15
  throwError('staticGen()', `framework.compilationInfo is undefined`);
@@ -20,7 +21,9 @@ export async function staticGen(framework) {
20
21
  const siteBasePath = config.siteBasePath;
21
22
  console.log('siteBasePath', siteBasePath);
22
23
  const projectDir = process.cwd();
23
- let appRoutes = await getAppRoutes(framework.compilationInfo, config);
24
+ //let appRoutes: RouteDefinition[] | Record<RouteKey, RouteDefinition> = await getAppRoutes(framework.compilationInfo, config)
25
+ const getRoutes = await getAppRoutes(framework.compilationInfo, config);
26
+ const appRoutes = typeof getRoutes === 'function' ? getRoutes(null) : getRoutes;
24
27
  const buildLocation = framework.compilationInfo.location;
25
28
  const server = await framework.createProdServer();
26
29
  const serverLocation = await server.start(null, true); // port, mute
@@ -29,12 +32,12 @@ export async function staticGen(framework) {
29
32
  recursive: true
30
33
  });
31
34
  const rewriteMap = {};
32
- if (!Array.isArray(appRoutes)) {
33
- appRoutes = Object.entries(appRoutes).map(([path, route]) => {
34
- route.path = path;
35
- return route;
36
- });
37
- }
35
+ // if ( ! Array.isArray(appRoutes) ) {
36
+ // appRoutes = Object.entries(appRoutes).map( ([path, route]) => {
37
+ // route.path = path as keyof typeof appRoutes
38
+ // return route
39
+ // } )
40
+ // }
38
41
  // for default and 404 routes we need to identify which one is in use, and then make sure the app renders it
39
42
  // appRoutes = appRoutes.map( route => {
40
43
  // if (route.path === 'default') {
@@ -47,25 +50,27 @@ export async function staticGen(framework) {
47
50
  // return route
48
51
  // })
49
52
  const dynamicRoutes = [];
50
- appRoutes = appRoutes.filter(route => {
51
- if (!route.path.startsWith('/')) {
53
+ const finalRoutes = objectFilter(appRoutes, (path, route) => {
54
+ if (!path.startsWith('/')) {
52
55
  //cliWarn(`Static gen skipping route ${route.path}, because it does not start with /, and is not default or 404`)
53
- cliWarn(`Static gen skipping route ${route.path}, because it does not start with /`);
56
+ cliWarn(`Static gen skipping route ${path}, because it does not start with /`);
54
57
  return false;
55
58
  }
56
- if (route.path.includes(':')) {
59
+ if (path.includes(':')) {
57
60
  // separate these out
58
- dynamicRoutes.push(route);
61
+ dynamicRoutes.push([path, route]);
59
62
  return false;
60
63
  }
61
64
  return true;
62
65
  });
63
- for (const route of appRoutes) {
66
+ if (count(finalRoutes) === 0) {
67
+ cliWarn('Found no valid route!');
68
+ }
69
+ for (const [path, route] of Object.entries(finalRoutes)) {
64
70
  // we need to develop the rewrite map over time, because we discover links during processing
65
- const path = route.path;
66
71
  rewriteMap[path] = pathToLink(path, siteBasePath);
67
- console.log('rewriteMap', rewriteMap);
68
72
  }
73
+ console.log('rewriteMap', rewriteMap);
69
74
  async function renderPath(path, siteBasePath) {
70
75
  const url = serverLocation + path;
71
76
  let links;
@@ -78,9 +83,9 @@ export async function staticGen(framework) {
78
83
  for (const link of links) {
79
84
  if (!StringIsPath(link)) throwError('renderRoute', `Found a link '${link}' that did not start with /`);
80
85
  if (!(link in rewriteMap)) {
81
- for (const dynamicRoute of dynamicRoutes) {
82
- if (RouteKeyIsPath(dynamicRoute.path)) {
83
- if (matchPath(dynamicRoute.path, link)) {
86
+ for (const [path, dynamicRoute] of dynamicRoutes) {
87
+ if (RouteKeyIsPath(path)) {
88
+ if (matchPath(path, link)) {
84
89
  //console.log('link', link)
85
90
  //console.log('in?', link in rewriteMap)
86
91
  //console.log(`link ${link} matched dynamic route ${dynamicRoute.path}`)
@@ -117,8 +122,8 @@ export async function staticGen(framework) {
117
122
  cliError(`Static site gen - error generating path ${path} (full location ${url}): ${e} ${e.stack}`);
118
123
  }
119
124
  }
120
- for (const route of appRoutes) {
121
- await renderPath(route.path, siteBasePath);
125
+ for (const [path, route] of Object.entries(finalRoutes)) {
126
+ await renderPath(path, siteBasePath);
122
127
  }
123
128
  console.log('rewriteMap', rewriteMap);
124
129
  const copyPromises = [fsExtra.copy(join(buildLocation, staticFolder), join(projectDir, staticSiteFolder)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {