tungsten 0.1.37 → 0.1.39

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.
@@ -16,7 +16,7 @@ export declare class Framework {
16
16
  build(mode: Mode): Promise<void>;
17
17
  clean(mode?: Mode | 'staticSite'): Promise<void>;
18
18
  staticGen(): Promise<void>;
19
- private getConfig;
19
+ private getAppConfig;
20
20
  private compileUserApp;
21
21
  private copyFrameworkAssets;
22
22
  private bundle;
@@ -1 +1 @@
1
- {"version":3,"file":"Framework.d.ts","sourceRoot":"","sources":["../src/Framework.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIrC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAA+B,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAEtG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAuBxD,qBAAa,SAAS;IAClB,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAA;IACnC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,UAAU,CAAC,EAAE,UAAU,CAAA;IAEjB,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAOxC,KAAK,CAAC,IAAI,EAAE,IAAI;IAmBhB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY;IAwBhC,SAAS;YAGD,SAAS;YAUT,cAAc;YAOd,mBAAmB;YAYnB,MAAM;IAKd,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC;IAoBrC,aAAa,CAAC,MAAM,EAAE,uBAAuB;IAkG7C,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;CAuChD"}
1
+ {"version":3,"file":"Framework.d.ts","sourceRoot":"","sources":["../src/Framework.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIrC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAA+B,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAEtG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAuBxD,qBAAa,SAAS;IAClB,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAA;IACnC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,UAAU,CAAC,EAAE,UAAU,CAAA;IAEjB,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAOxC,KAAK,CAAC,IAAI,EAAE,IAAI;IAmBhB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY;IAwBhC,SAAS;YAGD,YAAY;YAUZ,cAAc;YAOd,mBAAmB;YAYnB,MAAM;IAKd,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC;IAoBrC,aAAa,CAAC,MAAM,EAAE,uBAAuB;IAkG7C,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;CAuChD"}
package/dist/Framework.js CHANGED
@@ -41,7 +41,7 @@ export class Framework {
41
41
  _defineProperty(this, "prodServer", void 0);
42
42
  }
43
43
  async init() {
44
- const configOrUndefined = await this.getConfig();
44
+ const configOrUndefined = await this.getAppConfig();
45
45
  if (configOrUndefined === undefined) {
46
46
  throwError('Framework.init()', 'config is undefined');
47
47
  }
@@ -88,7 +88,7 @@ export class Framework {
88
88
  async staticGen() {
89
89
  await staticGen(this);
90
90
  }
91
- async getConfig() {
91
+ async getAppConfig() {
92
92
  const userConfigOrNull = await findUserConfig(process.cwd());
93
93
  if (userConfigOrNull !== null) {
94
94
  const userConfig = userConfigOrNull;
@@ -1,12 +1,14 @@
1
1
  import type { Server } from 'http';
2
2
  import express from 'express';
3
+ import { FrameworkConfigComplete } from 'tungsten/FrameworkConfig.js';
3
4
  export declare class StaticSiteServer {
5
+ config: FrameworkConfigComplete;
4
6
  port: number;
5
7
  location?: string;
6
8
  app: express.Application;
7
9
  server?: Server;
8
10
  staticSiteLocation: string;
9
- constructor();
11
+ constructor(config: FrameworkConfigComplete);
10
12
  start: () => Promise<string>;
11
13
  stop: () => void;
12
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StaticSiteServer.d.ts","sourceRoot":"","sources":["../../src/Servers/StaticSiteServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,OAAO,MAAM,SAAS,CAAA;AAM7B,qBAAa,gBAAgB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,OAAO,CAAC,WAAW,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;;IAS1B,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAQ3B;IACD,IAAI,aAEH;CACJ"}
1
+ {"version":3,"file":"StaticSiteServer.d.ts","sourceRoot":"","sources":["../../src/Servers/StaticSiteServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,OAAO,MAAM,SAAS,CAAA;AAK7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAErE,qBAAa,gBAAgB;IACzB,MAAM,EAAE,uBAAuB,CAAA;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,OAAO,CAAC,WAAW,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;gBAEd,MAAM,EAAE,uBAAuB;IAQ3C,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAQ3B;IACD,IAAI,aAEH;CACJ"}
@@ -7,14 +7,15 @@ import { staticSiteFolder } from "../settings.js";
7
7
  import { cliNews } from "../cliOutput.js";
8
8
  export class StaticSiteServer {
9
9
  // to do
10
- constructor() {
10
+ constructor(config) {
11
+ _defineProperty(this, "config", void 0);
11
12
  _defineProperty(this, "port", void 0);
12
13
  _defineProperty(this, "location", void 0);
13
14
  _defineProperty(this, "app", void 0);
14
15
  _defineProperty(this, "server", void 0);
15
16
  _defineProperty(this, "staticSiteLocation", void 0);
16
17
  _defineProperty(this, "start", () => {
17
- const location = this.location = `http://localhost:${this.port}`;
18
+ const location = this.location = `http://localhost:${this.port}${this.config.siteBasePath}`;
18
19
  return new Promise(resolve => {
19
20
  this.server = this.app.listen(this.port, () => {
20
21
  cliNews(`Static preview ready at ${this.location}`);
@@ -25,6 +26,7 @@ export class StaticSiteServer {
25
26
  _defineProperty(this, "stop", () => {
26
27
  if (this.server !== undefined) this.server.close();
27
28
  });
29
+ this.config = config;
28
30
  this.port = 3001;
29
31
  this.app = express();
30
32
  this.staticSiteLocation = join(process.cwd(), staticSiteFolder);
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/static.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/static.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import open from 'open';
2
+ import { getAppConfig } from 'tungsten/getAppConfig.js';
2
3
  import { StaticSiteServer } from "../../Servers/StaticSiteServer.js";
3
- const staticServer = new StaticSiteServer();
4
+ const staticServer = new StaticSiteServer(await getAppConfig());
4
5
  const staticServerLocation = await staticServer.start();
5
6
  open(staticServerLocation);
@@ -0,0 +1,3 @@
1
+ import { FrameworkConfigComplete } from './FrameworkConfig.js';
2
+ export declare function getAppConfig(): Promise<FrameworkConfigComplete>;
3
+ //# sourceMappingURL=getAppConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAppConfig.d.ts","sourceRoot":"","sources":["../src/getAppConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAG9D,wBAAsB,YAAY,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAQrE"}
@@ -0,0 +1,12 @@
1
+ import { defaultConfig } from "./defaultConfig.js";
2
+ import { findUserConfig } from "./findUserConfig.js";
3
+ import { makeFinalConfig } from "./makeFinalConfig.js";
4
+ export async function getAppConfig() {
5
+ const userConfigOrNull = await findUserConfig(process.cwd());
6
+ if (userConfigOrNull !== null) {
7
+ const userConfig = userConfigOrNull;
8
+ return makeFinalConfig(userConfig.data);
9
+ } else {
10
+ return defaultConfig;
11
+ }
12
+ }
@@ -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.39",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {