elm-pages 3.0.0-beta.4 → 3.0.0-beta.40
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/README.md +10 -1
- package/adapter/netlify.js +207 -0
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2678 -2725
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +17004 -13817
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/dead-code-review/elm.json +9 -7
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25025 -21739
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/review/elm.json +10 -10
- package/generator/src/RouteBuilder.elm +115 -109
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +209 -92
- package/generator/src/cli.js +292 -88
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +43 -26
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +176 -138
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +23 -23
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +39 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +321 -142
- package/generator/src/request-cache.js +265 -162
- package/generator/src/resolve-elm-module.js +64 -0
- package/generator/src/rewrite-client-elm-json.js +6 -5
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +17 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/elm-pages.js +10 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +6 -5
- package/generator/template/app/Effect.elm +123 -0
- package/generator/template/app/ErrorPage.elm +37 -6
- package/generator/template/app/Route/Index.elm +17 -10
- package/generator/template/app/Shared.elm +24 -47
- package/generator/template/app/Site.elm +19 -6
- package/generator/template/app/View.elm +1 -8
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +32 -24
- package/generator/template/package.json +10 -4
- package/package.json +30 -27
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +171 -56
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +679 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +69 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +90 -0
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Msg.elm +93 -0
- package/src/Pages/Internal/Platform/Cli.elm +612 -763
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
- package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
- package/src/Pages/Internal/Platform.elm +327 -194
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/PageUrl.elm +23 -9
- package/src/Pages/ProgramConfig.elm +26 -15
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -99
- package/src/Pages/Transition.elm +12 -3
- package/src/PagesMsg.elm +82 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +37 -20
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +546 -0
- package/src/Scaffold/Route.elm +1402 -0
- package/src/Server/Request.elm +73 -72
- package/src/Server/Session.elm +62 -42
- package/src/Server/SetCookie.elm +12 -4
- package/src/Stub.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
- package/src/Form/Field.elm +0 -717
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -417
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1683
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -256
- package/src/Pages/Generate.elm +0 -800
- package/src/Pages/Internal/Form.elm +0 -17
- package/src/Pages/Msg.elm +0 -79
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = { ensureDirSync, deleteIfExists };
|
|
1
|
+
import * as fs from "node:fs";
|
|
3
2
|
|
|
4
|
-
function ensureDirSync(dirpath) {
|
|
3
|
+
export function ensureDirSync(dirpath) {
|
|
5
4
|
try {
|
|
6
5
|
fs.mkdirSync(dirpath, { recursive: true });
|
|
7
6
|
} catch (err) {
|
|
@@ -9,7 +8,7 @@ function ensureDirSync(dirpath) {
|
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
function deleteIfExists(/** @type string */ filePath) {
|
|
11
|
+
export function deleteIfExists(/** @type string */ filePath) {
|
|
13
12
|
if (fs.existsSync(filePath)) {
|
|
14
13
|
fs.unlinkSync(filePath);
|
|
15
14
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { restoreColorSafe } = require("./error-formatter");
|
|
1
|
+
import * as globby from "globby";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { default as mm } from "micromatch";
|
|
4
|
+
import * as routeHelpers from "./route-codegen-helpers.js";
|
|
5
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @param {string} basePath
|
|
11
10
|
* @param {'browser' | 'cli'} phase
|
|
12
11
|
*/
|
|
13
|
-
async function generateTemplateModuleConnector(basePath, phase) {
|
|
14
|
-
const templates = globby
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
export async function generateTemplateModuleConnector(basePath, phase) {
|
|
13
|
+
const templates = globby
|
|
14
|
+
.globbySync(["app/Route/**/*.elm"], {})
|
|
15
|
+
.map((file) => {
|
|
16
|
+
const captures = mm.capture("app/Route/**/*.elm", file);
|
|
17
|
+
if (captures) {
|
|
18
|
+
return path.join(captures[0], captures[1]).split(path.sep);
|
|
19
|
+
} else {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
22
23
|
if (templates.length <= 0) {
|
|
23
24
|
throw {
|
|
24
25
|
path: "",
|
|
@@ -63,10 +64,12 @@ async function generateTemplateModuleConnector(basePath, phase) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
async function runElmCodegenCli(templates, basePath, phase) {
|
|
66
|
-
const
|
|
67
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
68
|
+
const __dirname = path.dirname(__filename);
|
|
69
|
+
const filePath = path.join(__dirname, `../../codegen/elm-pages-codegen.cjs`);
|
|
67
70
|
|
|
68
|
-
const promise = new Promise((resolve, reject) => {
|
|
69
|
-
const elmPagesCodegen =
|
|
71
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
72
|
+
const elmPagesCodegen = (await import(filePath)).default.Elm.Generate;
|
|
70
73
|
|
|
71
74
|
const app = elmPagesCodegen.init({
|
|
72
75
|
flags: { templates: templates, basePath, phase },
|
|
@@ -91,7 +94,7 @@ async function runElmCodegenCli(templates, basePath, phase) {
|
|
|
91
94
|
* @param {string[][]} templates
|
|
92
95
|
* @returns
|
|
93
96
|
*/
|
|
94
|
-
function sortTemplates(templates) {
|
|
97
|
+
export function sortTemplates(templates) {
|
|
95
98
|
return templates.sort((first, second) => {
|
|
96
99
|
const a = sortScore(first);
|
|
97
100
|
const b = sortScore(second);
|
|
@@ -186,7 +189,6 @@ function fetcherModule(name) {
|
|
|
186
189
|
|
|
187
190
|
import Bytes exposing (Bytes)
|
|
188
191
|
import Bytes.Decode
|
|
189
|
-
import FormDecoder
|
|
190
192
|
import Http
|
|
191
193
|
import Pages.Fetcher
|
|
192
194
|
import Route.${moduleName}
|
|
@@ -230,5 +232,3 @@ submit toMsg options =
|
|
|
230
232
|
function camelToKebab(input) {
|
|
231
233
|
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
232
234
|
}
|
|
233
|
-
|
|
234
|
-
module.exports = { generateTemplateModuleConnector, sortTemplates };
|
package/generator/src/init.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as fsExtra from "fs-extra";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as kleur from "kleur/colors";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* @param {string} name
|
|
8
11
|
*/
|
|
9
|
-
async function run(name) {
|
|
12
|
+
export async function run(name) {
|
|
10
13
|
console.log("Creating " + name + " project...");
|
|
11
14
|
|
|
12
15
|
const appRoot = path.resolve(name.toString());
|
|
@@ -14,7 +17,7 @@ async function run(name) {
|
|
|
14
17
|
|
|
15
18
|
if (!fs.existsSync(name)) {
|
|
16
19
|
try {
|
|
17
|
-
copySync(template, appRoot);
|
|
20
|
+
fsExtra.copySync(template, appRoot);
|
|
18
21
|
fs.renameSync(
|
|
19
22
|
path.resolve(appRoot, "gitignore"),
|
|
20
23
|
path.resolve(appRoot, ".gitignore")
|
|
@@ -36,5 +39,3 @@ async function run(name) {
|
|
|
36
39
|
kleur.green("Project is successfully created in `" + appRoot + "`.")
|
|
37
40
|
);
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
module.exports = { run };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as seo from "./seo-renderer.js";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { packageVersion } from "./compatibility-key.js";
|
|
4
5
|
|
|
5
6
|
/** @typedef { { head: any[]; errors: any[]; html: string; route: string; title: string; } } Arg */
|
|
6
7
|
/** @typedef { { tag : 'PageProgress'; args : Arg[] } } PageProgress */
|
|
7
8
|
|
|
8
|
-
function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
9
|
+
export function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
9
10
|
const seoData = seo.gather(fromElm.head);
|
|
10
11
|
return {
|
|
11
12
|
kind: "html-template",
|
|
@@ -17,28 +18,34 @@ function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @param {boolean} devMode
|
|
23
|
+
* @param {(context: {cliVersion: string;}) => string} userHeadTagsTemplate
|
|
24
|
+
*/
|
|
25
|
+
export function templateHtml(devMode, userHeadTagsTemplate) {
|
|
26
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = path.dirname(__filename);
|
|
21
28
|
return /* html */ `<!DOCTYPE html>
|
|
22
29
|
<!-- ROOT --><html lang="en">
|
|
23
30
|
<head>
|
|
24
|
-
<!-- PLACEHOLDER_PRELOADS -->
|
|
25
|
-
<script defer src="/elm.js" type="text/javascript"></script>
|
|
26
|
-
<script defer src="${path.join(
|
|
27
|
-
__dirname,
|
|
28
|
-
"../static-code/elm-pages.js"
|
|
29
|
-
)}" type="module"></script>
|
|
30
|
-
<link rel="stylesheet" href="/style.css" />
|
|
31
31
|
<meta charset="UTF-8" />
|
|
32
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
33
32
|
<title><!-- PLACEHOLDER_TITLE --></title>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
${
|
|
34
|
+
devMode
|
|
35
|
+
? `<script src="/hmr.js" type="text/javascript"></script>
|
|
36
|
+
<link rel="stylesheet" href="/dev-style.css">`
|
|
37
|
+
: `<!-- PLACEHOLDER_PRELOADS -->`
|
|
38
|
+
}
|
|
39
|
+
<script defer src="/elm.js" type="text/javascript"></script>
|
|
40
|
+
${
|
|
41
|
+
devMode
|
|
42
|
+
? `<script src="/elm-pages.js" type="module"></script>`
|
|
43
|
+
: `<script defer src="${path.join(
|
|
44
|
+
__dirname,
|
|
45
|
+
"../static-code/elm-pages.js"
|
|
46
|
+
)}" type="module"></script>`
|
|
47
|
+
}
|
|
48
|
+
${indent(userHeadTagsTemplate({ cliVersion: packageVersion }))}
|
|
42
49
|
<!-- PLACEHOLDER_HEAD_AND_DATA -->
|
|
43
50
|
</head>
|
|
44
51
|
<body>
|
|
@@ -48,10 +55,20 @@ function templateHtml() {
|
|
|
48
55
|
</html>`;
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} snippet
|
|
60
|
+
*/
|
|
61
|
+
function indent(snippet) {
|
|
62
|
+
return snippet
|
|
63
|
+
.split("\n")
|
|
64
|
+
.map((line) => ` ${line}`)
|
|
65
|
+
.join("\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
51
68
|
/**
|
|
52
69
|
* @param {string} processedTemplate
|
|
53
70
|
*/
|
|
54
|
-
function replaceTemplate(processedTemplate, info) {
|
|
71
|
+
export function replaceTemplate(processedTemplate, info) {
|
|
55
72
|
return processedTemplate
|
|
56
73
|
.replace(
|
|
57
74
|
/<!--\s*PLACEHOLDER_HEAD_AND_DATA\s*-->/,
|
|
@@ -62,9 +79,3 @@ function replaceTemplate(processedTemplate, info) {
|
|
|
62
79
|
.replace(/<!--\s*PLACEHOLDER_HTML\s* -->/, info.html)
|
|
63
80
|
.replace(/<!-- ROOT -->\S*<html lang="en">/m, info.rootElement);
|
|
64
81
|
}
|
|
65
|
-
|
|
66
|
-
module.exports = {
|
|
67
|
-
wrapHtml,
|
|
68
|
-
templateHtml,
|
|
69
|
-
replaceTemplate,
|
|
70
|
-
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const renderer = require("../../generator/src/render");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const compiledElmPath = path.join(process.cwd(), "elm-stuff/elm-pages/elm.js");
|
|
4
|
+
const codegen = require("./codegen.js");
|
|
5
|
+
const {
|
|
6
|
+
compileElmForBrowser,
|
|
7
|
+
runElmReview,
|
|
8
|
+
compileCliApp,
|
|
9
|
+
} = require("./compile-elm.js");
|
|
10
|
+
const { restoreColorSafe } = require("./error-formatter");
|
|
11
|
+
|
|
12
|
+
async function run({ pathname, serverRequest }) {
|
|
13
|
+
try {
|
|
14
|
+
const basePath = "/";
|
|
15
|
+
await codegen.generate(basePath);
|
|
16
|
+
console.log("Compiling...");
|
|
17
|
+
await compileCliApp(
|
|
18
|
+
{ port: 1234, base: basePath, https: false, debug: true },
|
|
19
|
+
".elm-pages/Main.elm",
|
|
20
|
+
|
|
21
|
+
path.join(process.cwd(), "elm-stuff/elm-pages/", "elm.js"),
|
|
22
|
+
|
|
23
|
+
// "elm.js",
|
|
24
|
+
"elm-stuff/elm-pages/",
|
|
25
|
+
path.join("elm-stuff/elm-pages/", "elm.js")
|
|
26
|
+
);
|
|
27
|
+
console.log("Compiling DONE");
|
|
28
|
+
|
|
29
|
+
const portsFilePath =
|
|
30
|
+
".elm-pages/compiled-ports/custom-backend-task-FA2IJND6.js";
|
|
31
|
+
const mode = "dev-server";
|
|
32
|
+
|
|
33
|
+
const renderResult = await renderer.render(
|
|
34
|
+
portsFilePath,
|
|
35
|
+
basePath,
|
|
36
|
+
require(compiledElmPath),
|
|
37
|
+
mode,
|
|
38
|
+
pathname,
|
|
39
|
+
serverRequest,
|
|
40
|
+
function (patterns) {},
|
|
41
|
+
true
|
|
42
|
+
);
|
|
43
|
+
console.log("renderResult", renderResult);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.log("ERROR");
|
|
46
|
+
console.log(restoreColorSafe(error));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// run({
|
|
51
|
+
// serverRequest: {
|
|
52
|
+
// method: "POST",
|
|
53
|
+
// headers: {
|
|
54
|
+
// host: "localhost:1234",
|
|
55
|
+
// cookie: "darkMode=%7B%7D.X1hjuYBa1OZulUomD5yrPy6VcYeY3sC7SKZVGViT0Q4",
|
|
56
|
+
// accept: "*/*",
|
|
57
|
+
// "accept-language": "en-US,en;q=0.9",
|
|
58
|
+
// connection: "keep-alive",
|
|
59
|
+
// "content-type": "application/x-www-form-urlencoded",
|
|
60
|
+
// origin: "http://localhost:1234",
|
|
61
|
+
// referer: "http://localhost:1234/dark-mode",
|
|
62
|
+
// },
|
|
63
|
+
// rawUrl: "http://localhost:1234/dark-mode/content.dat",
|
|
64
|
+
// body: "name=1",
|
|
65
|
+
// requestTime: 1671391652138,
|
|
66
|
+
// multiPartFormData: null,
|
|
67
|
+
// },
|
|
68
|
+
// pathname: "/dark-mode/content.dat",
|
|
69
|
+
// });
|
|
70
|
+
|
|
71
|
+
// run({
|
|
72
|
+
// pathname: "/fetcher/content.dat",
|
|
73
|
+
// serverRequest: {
|
|
74
|
+
// method: "POST",
|
|
75
|
+
// headers: {
|
|
76
|
+
// host: "localhost:1234",
|
|
77
|
+
// cookie: "darkMode=%7B%7D",
|
|
78
|
+
// accept: "*/*",
|
|
79
|
+
// "content-type": "application/x-www-form-urlencoded",
|
|
80
|
+
// origin: "http://localhost:1234",
|
|
81
|
+
// referer: "http://localhost:1234/fetcher",
|
|
82
|
+
// },
|
|
83
|
+
// rawUrl: "http://localhost:1234/fetcher/content.dat",
|
|
84
|
+
// body: "name=1",
|
|
85
|
+
// requestTime: 1671296755228,
|
|
86
|
+
// multiPartFormData: null,
|
|
87
|
+
// },
|
|
88
|
+
// });
|
|
89
|
+
|
|
90
|
+
run({
|
|
91
|
+
serverRequest: {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: {
|
|
94
|
+
host: "localhost:1234",
|
|
95
|
+
"cache-control": "max-age=0",
|
|
96
|
+
accept:
|
|
97
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
|
|
98
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
99
|
+
referer: "http://localhost:1234/login",
|
|
100
|
+
cookie:
|
|
101
|
+
"darkMode=%7B%22darkMode%22%3A%22%22%7D.vtrl8xZXjtx9E3iidJrgurAz4Vk7rnMQmf6zKiAbwNo; mysession=%7B%7D.YX1rW5PIpRFkjgIjLn4p9iyl5r9kWLYHqQUYxAYKJgQ",
|
|
102
|
+
},
|
|
103
|
+
rawUrl: "http://localhost:1234/login/content.dat",
|
|
104
|
+
body: "name=1",
|
|
105
|
+
requestTime: 1671391652138,
|
|
106
|
+
multiPartFormData: null,
|
|
107
|
+
},
|
|
108
|
+
pathname: "/login/content.dat",
|
|
109
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
global.staticHttpCache = {};
|
|
1
|
+
import * as renderer from "../../generator/src/render.js";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import * as fs from "./dir-helpers.js";
|
|
4
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { parentPort, threadId, workerData } from "node:worker_threads";
|
|
6
|
+
import * as url from "node:url";
|
|
9
7
|
|
|
10
8
|
async function run({ mode, pathname, serverRequest, portsFilePath }) {
|
|
11
9
|
console.time(`${threadId} ${pathname}`);
|
|
12
10
|
try {
|
|
13
|
-
const renderResult = await renderer(
|
|
14
|
-
portsFilePath
|
|
11
|
+
const renderResult = await renderer.render(
|
|
12
|
+
typeof portsFilePath === "string"
|
|
13
|
+
? await import(url.pathToFileURL(path.resolve(portsFilePath)).href)
|
|
14
|
+
: portsFilePath,
|
|
15
15
|
workerData.basePath,
|
|
16
|
-
requireElm(mode),
|
|
16
|
+
await requireElm(mode),
|
|
17
17
|
mode,
|
|
18
18
|
pathname,
|
|
19
19
|
serverRequest,
|
|
@@ -42,20 +42,17 @@ async function run({ mode, pathname, serverRequest, portsFilePath }) {
|
|
|
42
42
|
console.timeEnd(`${threadId} ${pathname}`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function requireElm(mode) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
delete require.cache[require.resolve(compiledElmPath)];
|
|
57
|
-
return require(compiledElmPath);
|
|
58
|
-
}
|
|
45
|
+
async function requireElm(mode) {
|
|
46
|
+
const compiledElmPath = path.join(
|
|
47
|
+
process.cwd(),
|
|
48
|
+
"elm-stuff/elm-pages/elm.cjs"
|
|
49
|
+
);
|
|
50
|
+
let pathAsUrl = url.pathToFileURL(compiledElmPath);
|
|
51
|
+
const warnOriginal = console.warn;
|
|
52
|
+
console.warn = function () {};
|
|
53
|
+
const Elm = (await import(pathAsUrl.toString())).default;
|
|
54
|
+
console.warn = warnOriginal;
|
|
55
|
+
return Elm;
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
async function outputString(
|
|
@@ -67,13 +64,13 @@ async function outputString(
|
|
|
67
64
|
const args = fromElm;
|
|
68
65
|
const normalizedRoute = args.route.replace(/index$/, "");
|
|
69
66
|
await fs.tryMkdir(`./dist/${normalizedRoute}`);
|
|
70
|
-
const template =
|
|
71
|
-
|
|
67
|
+
const template = readFileSync("./dist/template.html", "utf8");
|
|
68
|
+
writeFileSync(
|
|
72
69
|
`dist/${normalizedRoute}/index.html`,
|
|
73
70
|
renderTemplate(template, fromElm)
|
|
74
71
|
);
|
|
75
72
|
args.contentDatPayload &&
|
|
76
|
-
|
|
73
|
+
writeFileSync(
|
|
77
74
|
`dist/${normalizedRoute}/content.dat`,
|
|
78
75
|
Buffer.from(args.contentDatPayload.buffer)
|
|
79
76
|
);
|