corequery 0.1.9 → 0.1.10

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 (26) hide show
  1. package/README.md +1 -0
  2. package/package.json +3 -3
  3. package/server/dist/server/corequery.d.ts +1 -1
  4. package/server/dist/server/corequery.js +1 -1
  5. package/server/dist/server/corequery.js.map +1 -1
  6. package/server/dist/server/{web-server-asset-preparer.d.ts → web-server/asset-preparer.d.ts} +10 -7
  7. package/server/dist/server/web-server/asset-preparer.js +42 -0
  8. package/server/dist/server/web-server/asset-preparer.js.map +1 -0
  9. package/server/dist/server/web-server/icons-preparer.d.ts +17 -0
  10. package/server/dist/server/web-server/icons-preparer.js +39 -0
  11. package/server/dist/server/web-server/icons-preparer.js.map +1 -0
  12. package/server/dist/server/web-server/index-html-preparer.d.ts +18 -0
  13. package/server/dist/server/web-server/index-html-preparer.js +49 -0
  14. package/server/dist/server/web-server/index-html-preparer.js.map +1 -0
  15. package/server/dist/server/web-server/manifest-preparer.d.ts +17 -0
  16. package/server/dist/server/web-server/manifest-preparer.js +44 -0
  17. package/server/dist/server/web-server/manifest-preparer.js.map +1 -0
  18. package/server/dist/server/web-server/service-worker-preparer.d.ts +17 -0
  19. package/server/dist/server/web-server/service-worker-preparer.js +63 -0
  20. package/server/dist/server/web-server/service-worker-preparer.js.map +1 -0
  21. package/server/dist/server/{web-server.d.ts → web-server/web-server.d.ts} +2 -3
  22. package/server/dist/server/{web-server.js → web-server/web-server.js} +2 -4
  23. package/server/dist/server/web-server/web-server.js.map +1 -0
  24. package/server/dist/server/web-server-asset-preparer.js +0 -105
  25. package/server/dist/server/web-server-asset-preparer.js.map +0 -1
  26. package/server/dist/server/web-server.js.map +0 -1
package/README.md CHANGED
@@ -6,3 +6,4 @@ A platform for building web apps serving transit information. (Work in progress!
6
6
 
7
7
  - Setup TailwindCSS
8
8
  - Setup TypeORM, and check it can easily swap between PostgreSQL and SQLite.
9
+ - Eslint rules for console.log, absolute imports, React hooks, etc.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corequery",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "server/dist",
@@ -17,8 +17,8 @@
17
17
  "setup": "scripts/setup",
18
18
  "dev": "scripts/dev",
19
19
  "start": "scripts/start",
20
- "test": "vitest --run",
21
- "test-coverage": "vitest --run --coverage",
20
+ "test": "scripts/test",
21
+ "test-coverage": "scripts/test --coverage",
22
22
  "lint": "scripts/lint",
23
23
  "format": "prettier --write .",
24
24
  "format-check": "prettier --check .",
@@ -1,4 +1,4 @@
1
- import type { AssetConfig } from "./web-server-asset-preparer.js";
1
+ import type { AssetConfig } from "./web-server/asset-preparer.js";
2
2
  type CorequeryConfig = {
3
3
  readonly port: number;
4
4
  readonly assets: AssetConfig;
@@ -1,7 +1,7 @@
1
1
  import { runSharedCode } from "../shared/example.js";
2
2
  import { serverFolderPath } from "./dirname.js";
3
3
  import { env } from "./env.js";
4
- import { WebServer } from "./web-server.js";
4
+ import { WebServer } from "./web-server/web-server.js";
5
5
  export class Corequery {
6
6
  _config;
7
7
  _webServer;
@@ -1 +1 @@
1
- {"version":3,"file":"corequery.js","sourceRoot":"","sources":["../../corequery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,SAAS;IACH,OAAO,CAAkB;IACzB,UAAU,CAAY;IAEvC,YAAY,aAAqC;QAC/C,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAEnC,OAAO,CAAC,GAAG,CACT,mBAAmB,EACnB,IAAI,CAAC,OAAO,EACZ,GAAG,CAA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B,CAAC,CAAC,CAAC,aAAa,EAC5D,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,aAAa,EAAE,CAAC;QAEhB,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;QACtC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF"}
@@ -10,12 +10,15 @@ export type AssetConfig = {
10
10
  readonly pwaMaskable192PngPath: string;
11
11
  readonly pwaMaskable512PngPath: string;
12
12
  };
13
- export declare class WebServerAssetPreparer {
13
+ export declare class AssetPreparer {
14
+ private readonly _distFolderPath;
14
15
  private readonly _config;
15
- constructor(_config: AssetConfig);
16
- prepareDistFolder(distFolderPath: string): Promise<void>;
17
- private _replaceWebManifest;
18
- private _replaceIndexHtmlTags;
19
- private _replaceIcons;
20
- private _replaceServiceWorkerRevisionHashes;
16
+ static readonly ALL_MODIFIED_FILES: string[];
17
+ private readonly _indexHtml;
18
+ private readonly _manifest;
19
+ private readonly _icons;
20
+ private readonly _serviceWorker;
21
+ constructor(_distFolderPath: string, _config: AssetConfig);
22
+ run(): Promise<void>;
23
+ validateDistFolder(): Promise<void>;
21
24
  }
@@ -0,0 +1,42 @@
1
+ import { IndexHtmlPreparer } from "./index-html-preparer.js";
2
+ import { ManifestPreparer } from "./manifest-preparer.js";
3
+ import { IconsPreparer } from "./icons-preparer.js";
4
+ import { ServiceWorkerPreparer } from "./service-worker-preparer.js";
5
+ export class AssetPreparer {
6
+ _distFolderPath;
7
+ _config;
8
+ static ALL_MODIFIED_FILES = [
9
+ IndexHtmlPreparer.FILE_PATH,
10
+ ManifestPreparer.FILE_PATH,
11
+ ...IconsPreparer.FILE_PATHS,
12
+ ];
13
+ _indexHtml;
14
+ _manifest;
15
+ _icons;
16
+ _serviceWorker;
17
+ constructor(_distFolderPath, _config) {
18
+ this._distFolderPath = _distFolderPath;
19
+ this._config = _config;
20
+ this._indexHtml = new IndexHtmlPreparer(this._distFolderPath, this._config);
21
+ this._manifest = new ManifestPreparer(this._distFolderPath, this._config);
22
+ this._icons = new IconsPreparer(this._distFolderPath, this._config);
23
+ this._serviceWorker = new ServiceWorkerPreparer(this._distFolderPath, {
24
+ filesReplaced: AssetPreparer.ALL_MODIFIED_FILES,
25
+ });
26
+ }
27
+ async run() {
28
+ await this._indexHtml.run();
29
+ await this._manifest.run();
30
+ await this._icons.run();
31
+ // Must run last, otherwise we'll calculate hashes before the file contents
32
+ // are swapped.
33
+ await this._serviceWorker.run();
34
+ }
35
+ async validateDistFolder() {
36
+ await this._indexHtml.validate();
37
+ await this._manifest.validate();
38
+ await this._icons.validate();
39
+ await this._serviceWorker.validate();
40
+ }
41
+ }
42
+ //# sourceMappingURL=asset-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-preparer.js","sourceRoot":"","sources":["../../../web-server/asset-preparer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAgBrE,MAAM,OAAO,aAAa;IAaL;IACA;IAbnB,MAAM,CAAU,kBAAkB,GAAG;QACnC,iBAAiB,CAAC,SAAS;QAC3B,gBAAgB,CAAC,SAAS;QAC1B,GAAG,aAAa,CAAC,UAAU;KAC5B,CAAC;IAEe,UAAU,CAAoB;IAC9B,SAAS,CAAmB;IAC5B,MAAM,CAAgB;IACtB,cAAc,CAAwB;IAEvD,YACmB,eAAuB,EACvB,OAAoB;QADpB,oBAAe,GAAf,eAAe,CAAQ;QACvB,YAAO,GAAP,OAAO,CAAa;QAErC,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACpE,IAAI,CAAC,cAAc,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,eAAe,EAAE;YACpE,aAAa,EAAE,aAAa,CAAC,kBAAkB;SAChD,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAC3B,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAExB,2EAA2E;QAC3E,eAAe;QACf,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;IACvC,CAAC"}
@@ -0,0 +1,17 @@
1
+ type Config = {
2
+ readonly faviconSvgPath: string;
3
+ readonly appleTouchIconPngPath: string;
4
+ readonly pwa192PngPath: string;
5
+ readonly pwa512PngPath: string;
6
+ readonly pwaMaskable192PngPath: string;
7
+ readonly pwaMaskable512PngPath: string;
8
+ };
9
+ export declare class IconsPreparer {
10
+ private readonly _distFolderPath;
11
+ private readonly _config;
12
+ static readonly FILE_PATHS: readonly ["favicon.svg", "apple-touch-icon.png", "pwa-192x192.png", "pwa-512x512.png", "pwa-maskable-192x192.png", "pwa-maskable-512x512.png"];
13
+ constructor(_distFolderPath: string, _config: Config);
14
+ run(): Promise<void>;
15
+ validate(): Promise<void>;
16
+ }
17
+ export {};
@@ -0,0 +1,39 @@
1
+ import path from "path";
2
+ import fsp from "fs/promises";
3
+ export class IconsPreparer {
4
+ _distFolderPath;
5
+ _config;
6
+ static FILE_PATHS = [
7
+ "favicon.svg",
8
+ "apple-touch-icon.png",
9
+ "pwa-192x192.png",
10
+ "pwa-512x512.png",
11
+ "pwa-maskable-192x192.png",
12
+ "pwa-maskable-512x512.png",
13
+ ];
14
+ constructor(_distFolderPath, _config) {
15
+ this._distFolderPath = _distFolderPath;
16
+ this._config = _config;
17
+ }
18
+ async run() {
19
+ const mapping = {
20
+ "favicon.svg": this._config.faviconSvgPath,
21
+ "apple-touch-icon.png": this._config.appleTouchIconPngPath,
22
+ "pwa-192x192.png": this._config.pwa192PngPath,
23
+ "pwa-512x512.png": this._config.pwa512PngPath,
24
+ "pwa-maskable-192x192.png": this._config.pwaMaskable192PngPath,
25
+ "pwa-maskable-512x512.png": this._config.pwaMaskable512PngPath,
26
+ };
27
+ for (const [fileName, sourcePath] of Object.entries(mapping)) {
28
+ const destPath = path.join(this._distFolderPath, fileName);
29
+ await fsp.copyFile(sourcePath, destPath);
30
+ }
31
+ }
32
+ async validate() {
33
+ for (const fileName of IconsPreparer.FILE_PATHS) {
34
+ const destPath = path.join(this._distFolderPath, fileName);
35
+ await fsp.access(destPath);
36
+ }
37
+ }
38
+ }
39
+ //# sourceMappingURL=icons-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons-preparer.js","sourceRoot":"","sources":["../../../web-server/icons-preparer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,aAAa,CAAC;AAW9B,MAAM,OAAO,aAAa;IAWL;IACA;IAXnB,MAAM,CAAU,UAAU,GAAG;QAC3B,aAAa;QACb,sBAAsB;QACtB,iBAAiB;QACjB,iBAAiB;QACjB,0BAA0B;QAC1B,0BAA0B;KAClB,CAAC;IAEX,YACmB,eAAuB,EACvB,OAAe;QADf,oBAAe,GAAf,eAAe,CAAQ;QACvB,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,KAAK,CAAC,GAAG;QACP,MAAM,OAAO,GAA8D;YACzE,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;YAC1C,sBAAsB,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB;YAC1D,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa;YAC7C,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa;YAC7C,0BAA0B,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB;YAC9D,0BAA0B,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB;SAC/D,CAAC;QAEF,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;YAC3D,MAAM,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,KAAK,MAAM,QAAQ,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;YAC3D,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ type Config = {
2
+ readonly appName: string;
3
+ readonly shortAppName: string;
4
+ readonly description: string;
5
+ readonly version: string;
6
+ };
7
+ export declare class IndexHtmlPreparer {
8
+ private readonly _distFolderPath;
9
+ private readonly _config;
10
+ static readonly FILE_PATH = "index.html";
11
+ constructor(_distFolderPath: string, _config: Config);
12
+ run(): Promise<void>;
13
+ getReplacedContent(): Promise<string>;
14
+ validate(): Promise<void>;
15
+ private _readTags;
16
+ private _fullFilePath;
17
+ }
18
+ export {};
@@ -0,0 +1,49 @@
1
+ import fsp from "fs/promises";
2
+ import path from "path";
3
+ import { parse } from "node-html-parser";
4
+ export class IndexHtmlPreparer {
5
+ _distFolderPath;
6
+ _config;
7
+ static FILE_PATH = "index.html";
8
+ constructor(_distFolderPath, _config) {
9
+ this._distFolderPath = _distFolderPath;
10
+ this._config = _config;
11
+ }
12
+ async run() {
13
+ await fsp.writeFile(this._fullFilePath(), await this.getReplacedContent());
14
+ }
15
+ async getReplacedContent() {
16
+ const tags = await this._readTags();
17
+ tags.title.textContent = this._config.appName;
18
+ tags.description.setAttribute("content", this._config.description);
19
+ tags.appName.setAttribute("content", this._config.appName);
20
+ tags.frontendVersion.setAttribute("content", this._config.version);
21
+ return tags.indexHtml.toString();
22
+ }
23
+ async validate() {
24
+ // If this passes without error, we've found everything we're looking for in
25
+ // the index.html.
26
+ await this._readTags();
27
+ }
28
+ async _readTags() {
29
+ const indexHtmlStr = await fsp.readFile(this._fullFilePath(), "utf-8");
30
+ const indexHtml = parse(indexHtmlStr);
31
+ function requireTag(selector) {
32
+ const tag = indexHtml.querySelector(selector);
33
+ if (tag == null)
34
+ throw new Error(`"${selector}" tag not found.`);
35
+ return tag;
36
+ }
37
+ return {
38
+ indexHtml,
39
+ title: requireTag("title"),
40
+ description: requireTag('meta[name="description"]'),
41
+ appName: requireTag('meta[name="corequery-app-name"]'),
42
+ frontendVersion: requireTag('meta[name="corequery-frontend-version"]'),
43
+ };
44
+ }
45
+ _fullFilePath() {
46
+ return path.join(this._distFolderPath, IndexHtmlPreparer.FILE_PATH);
47
+ }
48
+ }
49
+ //# sourceMappingURL=index-html-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;QAEtC,SAAS,UAAU,CAAC,QAAgB;YAClC,MAAM,GAAG,GAAG,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,GAAG,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,IAAI,QAAQ,kBAAkB,CAAC,CAAC;YACjE,OAAO,GAAG,CAAC;QACb,CAAC;QAED,OAAO;YACL,SAAS;YACT,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;YAC1B,WAAW,EAAE,UAAU,CAAC,0BAA0B,CAAC;YACnD,OAAO,EAAE,UAAU,CAAC,iCAAiC,CAAC;YACtD,eAAe,EAAE,UAAU,CAAC,yCAAyC,CAAC;SACvE,CAAC;IACJ,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC"}
@@ -0,0 +1,17 @@
1
+ type Config = {
2
+ readonly appName: string;
3
+ readonly shortAppName: string;
4
+ readonly description: string;
5
+ };
6
+ export declare class ManifestPreparer {
7
+ private readonly _distFolderPath;
8
+ private readonly _config;
9
+ static readonly FILE_PATH = "manifest.webmanifest";
10
+ constructor(_distFolderPath: string, _config: Config);
11
+ run(): Promise<void>;
12
+ getReplacedContent(): Promise<string>;
13
+ validate(): Promise<void>;
14
+ private _readManifestJson;
15
+ private _fullFilePath;
16
+ }
17
+ export {};
@@ -0,0 +1,44 @@
1
+ import fsp from "fs/promises";
2
+ import path from "path";
3
+ import z from "zod";
4
+ export class ManifestPreparer {
5
+ _distFolderPath;
6
+ _config;
7
+ static FILE_PATH = "manifest.webmanifest";
8
+ constructor(_distFolderPath, _config) {
9
+ this._distFolderPath = _distFolderPath;
10
+ this._config = _config;
11
+ }
12
+ async run() {
13
+ await fsp.writeFile(this._fullFilePath(), await this.getReplacedContent());
14
+ }
15
+ async getReplacedContent() {
16
+ const manifest = await this._readManifestJson();
17
+ const newManifest = {
18
+ ...manifest,
19
+ name: this._config.appName,
20
+ short_name: this._config.shortAppName,
21
+ description: this._config.description,
22
+ };
23
+ return JSON.stringify(newManifest);
24
+ }
25
+ async validate() {
26
+ // If this passes without error, we've found everything we're looking for in
27
+ // the manifest.webmanifest.
28
+ await this._readManifestJson();
29
+ }
30
+ async _readManifestJson() {
31
+ const manifestStr = await fsp.readFile(this._fullFilePath(), "utf-8");
32
+ const manifestJson = JSON.parse(manifestStr);
33
+ const schema = z.object({
34
+ name: z.string(),
35
+ short_name: z.string(),
36
+ description: z.string(),
37
+ });
38
+ return schema.parse(manifestJson);
39
+ }
40
+ _fullFilePath() {
41
+ return path.join(this._distFolderPath, ManifestPreparer.FILE_PATH);
42
+ }
43
+ }
44
+ //# sourceMappingURL=manifest-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-preparer.js","sourceRoot":"","sources":["../../../web-server/manifest-preparer.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,CAAC,MAAM,KAAK,CAAC;AAQpB,MAAM,OAAO,gBAAgB;IAIR;IACA;IAJnB,MAAM,CAAU,SAAS,GAAG,sBAAsB,CAAC;IAEnD,YACmB,eAAuB,EACvB,OAAe;QADf,oBAAe,GAAf,eAAe,CAAQ;QACvB,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,KAAK,CAAC,GAAG;QACP,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEhD,MAAM,WAAW,GAAG;YAClB,GAAG,QAAQ;YACX,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC1B,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;YACrC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;SACtC,CAAC;QAEF,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,4EAA4E;QAC5E,4BAA4B;QAC5B,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE7C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;YAChB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;YACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;SACxB,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC"}
@@ -0,0 +1,17 @@
1
+ type Config = {
2
+ filesReplaced: readonly string[];
3
+ getFileHash?: (filePath: string) => Promise<string>;
4
+ };
5
+ export declare class ServiceWorkerPreparer {
6
+ private readonly _distFolderPath;
7
+ private readonly _config;
8
+ static readonly FILE_PATH = "sw.js";
9
+ constructor(_distFolderPath: string, _config: Config);
10
+ run(): Promise<void>;
11
+ getReplacedContent(): Promise<string>;
12
+ validate(): Promise<void>;
13
+ private _getFileHash;
14
+ private _getSubstringsToReplace;
15
+ private _fullFilePath;
16
+ }
17
+ export {};
@@ -0,0 +1,63 @@
1
+ import path from "path";
2
+ import fsp from "fs/promises";
3
+ import crypto from "crypto";
4
+ export class ServiceWorkerPreparer {
5
+ _distFolderPath;
6
+ _config;
7
+ static FILE_PATH = "sw.js";
8
+ constructor(_distFolderPath, _config) {
9
+ this._distFolderPath = _distFolderPath;
10
+ this._config = _config;
11
+ }
12
+ async run() {
13
+ await fsp.writeFile(this._fullFilePath(), await this.getReplacedContent());
14
+ }
15
+ async getReplacedContent() {
16
+ const { serviceWorkerStr, substringsPerFile } = await this._getSubstringsToReplace();
17
+ let newServiceWorkerStr = serviceWorkerStr;
18
+ for (const { file, substrings } of substringsPerFile) {
19
+ const hash = await this._getFileHash(file);
20
+ for (const substring of substrings) {
21
+ newServiceWorkerStr = newServiceWorkerStr.replace(substring, `{url:"${file}",revision:"${hash}"}`);
22
+ }
23
+ }
24
+ return newServiceWorkerStr;
25
+ }
26
+ async validate() {
27
+ // If this passes without error, we've found everything we're looking for in
28
+ // the sw.js.
29
+ await this._getSubstringsToReplace();
30
+ }
31
+ async _getFileHash(filePath) {
32
+ if (this._config.getFileHash != null) {
33
+ return this._config.getFileHash(filePath);
34
+ }
35
+ else {
36
+ const fullFilePath = path.join(this._distFolderPath, filePath);
37
+ const fileContent = await fsp.readFile(fullFilePath);
38
+ return crypto.createHash("md5").update(fileContent).digest("hex");
39
+ }
40
+ }
41
+ async _getSubstringsToReplace() {
42
+ const serviceWorkerStr = await fsp.readFile(this._fullFilePath(), "utf-8");
43
+ const allMatches = Array.from(serviceWorkerStr.matchAll(/{url:"([^"]+)",revision:"[^"]+"}/g)).map((match) => ({
44
+ fullText: match[0],
45
+ url: match[1],
46
+ }));
47
+ const substringsPerFile = this._config.filesReplaced.map((file) => {
48
+ // Filter, as some assets (e.g. pwa-192x192.png) are in there twice.
49
+ const substrings = allMatches
50
+ .filter((m) => m.url === file)
51
+ .map((m) => m.fullText);
52
+ if (substrings.length === 0) {
53
+ throw new Error(`Cannot find "${file}" revision in service worker.`);
54
+ }
55
+ return { file, substrings };
56
+ });
57
+ return { serviceWorkerStr, substringsPerFile };
58
+ }
59
+ _fullFilePath() {
60
+ return path.join(this._distFolderPath, ServiceWorkerPreparer.FILE_PATH);
61
+ }
62
+ }
63
+ //# sourceMappingURL=service-worker-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-worker-preparer.js","sourceRoot":"","sources":["../../../web-server/service-worker-preparer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,MAAM,OAAO,qBAAqB;IAIb;IACA;IAJnB,MAAM,CAAU,SAAS,GAAG,OAAO,CAAC;IAEpC,YACmB,eAAuB,EACvB,OAAe;QADf,oBAAe,GAAf,eAAe,CAAQ;QACvB,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,KAAK,CAAC,GAAG;QACP,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAC3C,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEvC,IAAI,mBAAmB,GAAG,gBAAgB,CAAC;QAE3C,KAAK,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAE,CAAC;YACrD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAE3C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,mBAAmB,GAAG,mBAAmB,CAAC,OAAO,CAC/C,SAAS,EACT,SAAS,IAAI,eAAe,IA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1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC;iBAC7B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YAE1B,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,+BAA+B,CAAC,CAAC;YACvE,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;IACjD,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC1E,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { Corequery } from "./corequery.js";
2
- import { type AssetConfig } from "./web-server-asset-preparer.js";
1
+ import type { Corequery } from "../corequery.js";
2
+ import { type AssetConfig } from "./asset-preparer.js";
3
3
  export declare const clientModes: readonly ["dist-folder", "vite-middleware"];
4
4
  export type ClientMode = (typeof clientModes)[number];
5
5
  export declare class WebServer {
@@ -8,7 +8,6 @@ export declare class WebServer {
8
8
  private readonly _assetConfig;
9
9
  private readonly _clientMode;
10
10
  private readonly _serverFolderPath;
11
- private readonly _assetPreparer;
12
11
  constructor(_app: Corequery, _port: number, _assetConfig: AssetConfig, _clientMode: ClientMode, _serverFolderPath: string);
13
12
  prepareAssets(): Promise<void>;
14
13
  start(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import express from "express";
2
2
  import fsp from "fs/promises";
3
3
  import path from "path";
4
- import { WebServerAssetPreparer, } from "./web-server-asset-preparer.js";
4
+ import { AssetPreparer } from "./asset-preparer.js";
5
5
  export const clientModes = ["dist-folder", "vite-middleware"];
6
6
  export class WebServer {
7
7
  _app;
@@ -9,19 +9,17 @@ export class WebServer {
9
9
  _assetConfig;
10
10
  _clientMode;
11
11
  _serverFolderPath;
12
- _assetPreparer;
13
12
  constructor(_app, _port, _assetConfig, _clientMode, _serverFolderPath) {
14
13
  this._app = _app;
15
14
  this._port = _port;
16
15
  this._assetConfig = _assetConfig;
17
16
  this._clientMode = _clientMode;
18
17
  this._serverFolderPath = _serverFolderPath;
19
- this._assetPreparer = new WebServerAssetPreparer(_assetConfig);
20
18
  }
21
19
  async prepareAssets() {
22
20
  if (this._clientMode === "dist-folder") {
23
21
  const distFolderPath = this._getWebFolderPath("dist");
24
- await this._assetPreparer.prepareDistFolder(distFolderPath);
22
+ await new AssetPreparer(distFolderPath, this._assetConfig).run();
25
23
  }
26
24
  // It's hard to think of a way to reasonably replace the assets in
27
25
  // middleware mode, as you'd be replacing the source assets. It's only a
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-server.js","sourceRoot":"","sources":["../../../web-server/web-server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,aAAa,EAAoB,MAAM,qBAAqB,CAAC;AAEtE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,iBAAiB,CAAU,CAAC;AAGvE,MAAM,OAAO,SAAS;IAED;IACA;IACA;IACA;IACA;IALnB,YACmB,IAAe,EACf,KAAa,EACb,YAAyB,EACzB,WAAuB,EACvB,iBAAyB;QAJzB,SAAI,GAAJ,IAAI,CAAW;QACf,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAa;QACzB,gBAAW,GAAX,WAAW,CAAY;QACvB,sBAAiB,GAAjB,iBAAiB,CAAQ;IACzC,CAAC;IAEJ,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,WAAW,KAAK,aAAa,EAAE,CAAC;YACvC,MAAM,cAA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AAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,iCAAiC,CAAC,MAAuB;QACrE,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;QAEjE,uEAAuE;QACvE,2EAA2E;QAC3E,sBAAsB;QACtB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QAE9C,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC;YAC9B,MAAM,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;YAChC,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE;SAC/B,CAAC,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAEO,iBAAiB,CAAC,YAAoB,EAAE;QAC9C,OAAO,IAAI,CAAC,OAAO,CACjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC,EACpD,SAAS,CACV,CAAC;IACJ,CAAC;CACF"}
@@ -1,105 +0,0 @@
1
- import path from "path";
2
- import fsp from "fs/promises";
3
- import { parse } from "node-html-parser";
4
- import crypto from "crypto";
5
- export class WebServerAssetPreparer {
6
- _config;
7
- constructor(_config) {
8
- this._config = _config;
9
- }
10
- async prepareDistFolder(distFolderPath) {
11
- const indexHtmlPath = path.join(distFolderPath, "index.html");
12
- const webManifestPath = path.join(distFolderPath, "manifest.webmanifest");
13
- await this._replaceIndexHtmlTags(indexHtmlPath);
14
- await this._replaceWebManifest(webManifestPath);
15
- await this._replaceIcons(distFolderPath);
16
- // Must come last, otherwise we'll calculate hashes before the file contents
17
- // are swapped.
18
- await this._replaceServiceWorkerRevisionHashes(distFolderPath);
19
- }
20
- async _replaceWebManifest(filePath) {
21
- const manifestStr = await fsp.readFile(filePath, "utf-8");
22
- const manifestJson = JSON.parse(manifestStr);
23
- const newManifestJson = {
24
- ...manifestJson,
25
- name: this._config.appName,
26
- short_name: this._config.shortAppName,
27
- description: this._config.description,
28
- };
29
- const newManifestStr = JSON.stringify(newManifestJson);
30
- await fsp.writeFile(filePath, newManifestStr);
31
- }
32
- async _replaceIndexHtmlTags(filePath) {
33
- const indexHtmlStr = await fsp.readFile(filePath, "utf-8");
34
- const indexHtml = parse(indexHtmlStr);
35
- function requireTag(selector) {
36
- const tag = indexHtml.querySelector(selector);
37
- if (tag == null)
38
- throw new Error(`"${selector}" tag not found.`);
39
- return tag;
40
- }
41
- const titleTag = requireTag("title");
42
- const descriptionTag = requireTag('meta[name="description"]');
43
- const appNameTag = requireTag('meta[name="corequery-app-name"]');
44
- const versionTag = requireTag('meta[name="corequery-frontend-version"]');
45
- titleTag.textContent = this._config.appName;
46
- descriptionTag.setAttribute("content", this._config.description);
47
- appNameTag.setAttribute("content", this._config.appName);
48
- versionTag.setAttribute("content", this._config.version);
49
- const newIndexHtmlStr = indexHtml.toString();
50
- await fsp.writeFile(filePath, newIndexHtmlStr);
51
- }
52
- async _replaceIcons(distFolderPath) {
53
- const mapping = {
54
- "favicon.svg": this._config.faviconSvgPath,
55
- "apple-touch-icon.png": this._config.appleTouchIconPngPath,
56
- "pwa-192x192.png": this._config.pwa192PngPath,
57
- "pwa-512x512.png": this._config.pwa512PngPath,
58
- "pwa-maskable-192x192.png": this._config.pwaMaskable192PngPath,
59
- "pwa-maskable-512x512.png": this._config.pwaMaskable512PngPath,
60
- };
61
- for (const [fileName, sourcePath] of Object.entries(mapping)) {
62
- const destPath = path.join(distFolderPath, fileName);
63
- await fsp.copyFile(sourcePath, destPath);
64
- }
65
- }
66
- async _replaceServiceWorkerRevisionHashes(distFolderPath) {
67
- const serviceWorkerPath = path.join(distFolderPath, "sw.js");
68
- const serviceWorkerStr = await fsp.readFile(serviceWorkerPath, "utf-8");
69
- // Any files this class modifies should be listed here.
70
- const filesRequiringRevisionUpdates = [
71
- "index.html",
72
- "manifest.webmanifest",
73
- "favicon.svg",
74
- "apple-touch-icon.png",
75
- "pwa-192x192.png",
76
- "pwa-512x512.png",
77
- "pwa-maskable-192x192.png",
78
- "pwa-maskable-512x512.png",
79
- ];
80
- // TODO: This regex is fragile. I should write a test of some sort which
81
- // runs Vite to build the service worker and ensures this regex finds all
82
- // the files listed above. Otherwise, an update to the Vite PWA plugin could
83
- // cause consumers to fail on startup. (And I should probably have similar
84
- // tests for everything else in this class too!)
85
- const matches = Array.from(serviceWorkerStr.matchAll(/{url:"([^"]+)",revision:"[^"]+"}/g)).map((match) => ({
86
- fullText: match[0],
87
- url: match[1],
88
- }));
89
- let newServiceWorkerStr = serviceWorkerStr;
90
- for (const file of filesRequiringRevisionUpdates) {
91
- // Filter, as some assets (e.g. pwa-192x192.png) are in there twice.
92
- const entries = matches.filter((m) => m.url === file);
93
- if (entries.length === 0)
94
- throw new Error(`"${file}" had no revisions.`);
95
- const fullFilePath = path.join(distFolderPath, file);
96
- const fileContent = await fsp.readFile(fullFilePath);
97
- const hash = crypto.createHash("md5").update(fileContent).digest("hex");
98
- for (const entry of entries) {
99
- newServiceWorkerStr = newServiceWorkerStr.replace(entry.fullText, `{url:"${entry.url}",revision:"${hash}"}`);
100
- }
101
- }
102
- await fsp.writeFile(serviceWorkerPath, newServiceWorkerStr);
103
- }
104
- }
105
- //# sourceMappingURL=web-server-asset-preparer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-server-asset-preparer.js","sourceRoot":"","sources":["../../web-server-asset-preparer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAgB5B,MAAM,OAAO,sBAAsB;IACJ;IAA7B,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAErD,KAAK,CAAC,iBAAiB,CAAC,cAAsB;QAC5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