elm-pages 3.0.0-beta.17 → 3.0.0-beta.19
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/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +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/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- 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/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +36 -30
- package/generator/src/cli.js +30 -23
- package/generator/src/codegen.js +19 -18
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +2 -4
- package/generator/src/dev-server.js +47 -30
- package/generator/src/dir-helpers.js +9 -25
- package/generator/src/elm-codegen.js +2 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +5 -5
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +14 -15
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +11 -12
- package/generator/src/render-worker.js +21 -26
- package/generator/src/render.js +122 -162
- package/generator/src/request-cache.js +13 -8
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +5 -5
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +1 -3
- package/generator/src/vite-utils.js +1 -2
- package/package.json +9 -8
- package/src/BackendTask/Custom.elm +1 -1
- package/src/BackendTask/File.elm +1 -1
- package/src/BackendTask/Glob.elm +4 -2
- package/src/BackendTask/Http.elm +6 -6
- package/src/FatalError.elm +2 -14
- package/src/Form.elm +26 -47
- package/src/Pages/Generate.elm +42 -13
- package/src/Pages/Internal/Form.elm +14 -1
- package/src/Pages/Internal/Platform/Cli.elm +8 -6
- package/src/Pages/Internal/Platform/Effect.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +8 -6
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Script.elm +2 -2
- package/src/Server/Request.elm +21 -13
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as util from "util";
|
|
2
|
+
import * as fsSync from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
|
|
3
5
|
const fs = {
|
|
4
6
|
writeFile: util.promisify(fsSync.writeFile),
|
|
5
7
|
writeFileSync: fsSync.writeFileSync,
|
|
@@ -15,14 +17,14 @@ const fs = {
|
|
|
15
17
|
/**
|
|
16
18
|
* @param {import("fs").PathLike} dirName
|
|
17
19
|
*/
|
|
18
|
-
async function tryMkdir(dirName) {
|
|
20
|
+
export async function tryMkdir(dirName) {
|
|
19
21
|
const exists = await fs.exists(dirName);
|
|
20
22
|
if (!exists) {
|
|
21
23
|
await fs.mkdir(dirName, { recursive: true });
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function fileExists(file) {
|
|
27
|
+
export function fileExists(file) {
|
|
26
28
|
return fsSync.promises
|
|
27
29
|
.access(file, fsSync.constants.F_OK)
|
|
28
30
|
.then(() => true)
|
|
@@ -33,18 +35,16 @@ function fileExists(file) {
|
|
|
33
35
|
* @param {string} filePath
|
|
34
36
|
* @param {string} data
|
|
35
37
|
*/
|
|
36
|
-
function writeFileSyncSafe(filePath, data) {
|
|
38
|
+
export function writeFileSyncSafe(filePath, data) {
|
|
37
39
|
fsSync.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
38
40
|
fs.writeFileSync(filePath, data);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
const path = require("path");
|
|
42
|
-
|
|
43
43
|
/**
|
|
44
44
|
* @param {string} srcDirectory
|
|
45
45
|
* @param {string} destDir
|
|
46
46
|
*/
|
|
47
|
-
async function copyDirFlat(srcDirectory, destDir) {
|
|
47
|
+
export async function copyDirFlat(srcDirectory, destDir) {
|
|
48
48
|
const items = await fs.readdir(srcDirectory);
|
|
49
49
|
items.forEach(function (childItemName) {
|
|
50
50
|
copyDirNested(
|
|
@@ -58,7 +58,7 @@ async function copyDirFlat(srcDirectory, destDir) {
|
|
|
58
58
|
* @param {string} src
|
|
59
59
|
* @param {string} dest
|
|
60
60
|
*/
|
|
61
|
-
async function copyDirNested(src, dest) {
|
|
61
|
+
export async function copyDirNested(src, dest) {
|
|
62
62
|
var exists = fsSync.existsSync(src);
|
|
63
63
|
var stats = exists && fsSync.statSync(src);
|
|
64
64
|
var isDirectory = exists && stats.isDirectory();
|
|
@@ -76,19 +76,3 @@ async function copyDirNested(src, dest) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
module.exports = {
|
|
80
|
-
writeFile: fs.writeFile,
|
|
81
|
-
writeFileSync: fs.writeFileSync,
|
|
82
|
-
readFile: fs.readFile,
|
|
83
|
-
readFileSync: fsSync.readFileSync,
|
|
84
|
-
copyFile: fs.copyFile,
|
|
85
|
-
exists: fs.exists,
|
|
86
|
-
writeFileSyncSafe,
|
|
87
|
-
tryMkdir,
|
|
88
|
-
copyDirFlat,
|
|
89
|
-
copyDirNested,
|
|
90
|
-
rmSync: fs.rm,
|
|
91
|
-
rm: fs.rm,
|
|
92
|
-
existsSync: fs.existsSync,
|
|
93
|
-
fileExists: fileExists,
|
|
94
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
2
2
|
|
|
3
|
-
function runElmCodegenInstall() {
|
|
3
|
+
export function runElmCodegenInstall() {
|
|
4
4
|
return new Promise(async (resolve, reject) => {
|
|
5
5
|
const subprocess = spawnCallback(`elm-codegen`, ["install"], {
|
|
6
6
|
// ignore stdout
|
|
@@ -33,5 +33,3 @@ function runElmCodegenInstall() {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
module.exports = { runElmCodegenInstall };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function elmPagesUiFile() {
|
|
1
|
+
export function elmPagesUiFile() {
|
|
2
2
|
return `module Pages exposing (builtAt)
|
|
3
3
|
|
|
4
4
|
import Time
|
|
@@ -12,7 +12,6 @@ builtAt =
|
|
|
12
12
|
`;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function elmPagesCliFile() {
|
|
15
|
+
export function elmPagesCliFile() {
|
|
16
16
|
return elmPagesUiFile();
|
|
17
17
|
}
|
|
18
|
-
module.exports = { elmPagesUiFile, elmPagesCliFile };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as kleur from "kleur/colors";
|
|
2
4
|
|
|
3
5
|
/* Thanks to elm-live for this code!
|
|
4
6
|
https://github.com/wking-io/elm-live/blob/e317b4914c471addea7243c47f28dcebe27a5d36/lib/src/build.js#L65
|
|
@@ -82,7 +84,7 @@ function toKleurColor(color) {
|
|
|
82
84
|
/**
|
|
83
85
|
* @param {RootObject} error
|
|
84
86
|
* */
|
|
85
|
-
const restoreColor = (error) => {
|
|
87
|
+
export const restoreColor = (error) => {
|
|
86
88
|
try {
|
|
87
89
|
if (error.type === "compile-errors") {
|
|
88
90
|
return error.errors
|
|
@@ -111,7 +113,7 @@ const restoreColor = (error) => {
|
|
|
111
113
|
* @param {string} error
|
|
112
114
|
* @returns {string}
|
|
113
115
|
*/
|
|
114
|
-
function restoreColorSafe(error) {
|
|
116
|
+
export function restoreColorSafe(error) {
|
|
115
117
|
try {
|
|
116
118
|
if (typeof error === "string") {
|
|
117
119
|
const asJson = JSON.parse(error);
|
|
@@ -149,8 +151,6 @@ const restoreProblem =
|
|
|
149
151
|
}
|
|
150
152
|
};
|
|
151
153
|
|
|
152
|
-
module.exports = { restoreColor, restoreColorSafe };
|
|
153
|
-
|
|
154
154
|
/** @typedef { CompilerError | ReportError | IElmReviewError } RootObject */
|
|
155
155
|
|
|
156
156
|
/** @typedef { { type: "compile-errors"; errors: Error_[]; } } CompilerError */
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = { ensureDirSync, deleteIfExists };
|
|
1
|
+
import * as fs from "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,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { restoreColorSafe } = require("./error-formatter");
|
|
1
|
+
import { globbySync } 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 =
|
|
12
|
+
export async function generateTemplateModuleConnector(basePath, phase) {
|
|
13
|
+
const templates = globbySync(["app/Route/**/*.elm"], {}).map((file) => {
|
|
15
14
|
const captures = mm.capture("app/Route/**/*.elm", file);
|
|
16
15
|
if (captures) {
|
|
17
16
|
return path.join(captures[0], captures[1]).split(path.sep);
|
|
@@ -63,10 +62,12 @@ async function generateTemplateModuleConnector(basePath, phase) {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
async function runElmCodegenCli(templates, basePath, phase) {
|
|
66
|
-
const
|
|
65
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
66
|
+
const __dirname = path.dirname(__filename);
|
|
67
|
+
const filePath = path.join(__dirname, `../../codegen/elm-pages-codegen.cjs`);
|
|
67
68
|
|
|
68
|
-
const promise = new Promise((resolve, reject) => {
|
|
69
|
-
const elmPagesCodegen =
|
|
69
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
70
|
+
const elmPagesCodegen = (await import(filePath)).default.Elm.Generate;
|
|
70
71
|
|
|
71
72
|
const app = elmPagesCodegen.init({
|
|
72
73
|
flags: { templates: templates, basePath, phase },
|
|
@@ -91,7 +92,7 @@ async function runElmCodegenCli(templates, basePath, phase) {
|
|
|
91
92
|
* @param {string[][]} templates
|
|
92
93
|
* @returns
|
|
93
94
|
*/
|
|
94
|
-
function sortTemplates(templates) {
|
|
95
|
+
export function sortTemplates(templates) {
|
|
95
96
|
return templates.sort((first, second) => {
|
|
96
97
|
const a = sortScore(first);
|
|
97
98
|
const b = sortScore(second);
|
|
@@ -230,5 +231,3 @@ submit toMsg options =
|
|
|
230
231
|
function camelToKebab(input) {
|
|
231
232
|
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
232
233
|
}
|
|
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 { copySync } from "fs-extra/esm";
|
|
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());
|
|
@@ -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,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as seo from "./seo-renderer.js";
|
|
2
|
+
import * as packageJson from "../../package.json" assert { type: "json" };
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
|
|
6
|
+
const cliVersion = packageJson.version;
|
|
4
7
|
|
|
5
8
|
/** @typedef { { head: any[]; errors: any[]; html: string; route: string; title: string; } } Arg */
|
|
6
9
|
/** @typedef { { tag : 'PageProgress'; args : Arg[] } } PageProgress */
|
|
7
10
|
|
|
8
|
-
function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
11
|
+
export function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
9
12
|
const seoData = seo.gather(fromElm.head);
|
|
10
13
|
return {
|
|
11
14
|
kind: "html-template",
|
|
@@ -21,7 +24,9 @@ function wrapHtml(basePath, fromElm, contentDatPayload) {
|
|
|
21
24
|
* @param {boolean} devMode
|
|
22
25
|
* @param {(context: {cliVersion: string;}) => string} userHeadTagsTemplate
|
|
23
26
|
*/
|
|
24
|
-
function templateHtml(devMode, userHeadTagsTemplate) {
|
|
27
|
+
export function templateHtml(devMode, userHeadTagsTemplate) {
|
|
28
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
29
|
+
const __dirname = path.dirname(__filename);
|
|
25
30
|
return /* html */ `<!DOCTYPE html>
|
|
26
31
|
<!-- ROOT --><html lang="en">
|
|
27
32
|
<head>
|
|
@@ -65,7 +70,7 @@ function indent(snippet) {
|
|
|
65
70
|
/**
|
|
66
71
|
* @param {string} processedTemplate
|
|
67
72
|
*/
|
|
68
|
-
function replaceTemplate(processedTemplate, info) {
|
|
73
|
+
export function replaceTemplate(processedTemplate, info) {
|
|
69
74
|
return processedTemplate
|
|
70
75
|
.replace(
|
|
71
76
|
/<!--\s*PLACEHOLDER_HEAD_AND_DATA\s*-->/,
|
|
@@ -76,9 +81,3 @@ function replaceTemplate(processedTemplate, info) {
|
|
|
76
81
|
.replace(/<!--\s*PLACEHOLDER_HTML\s* -->/, info.html)
|
|
77
82
|
.replace(/<!-- ROOT -->\S*<html lang="en">/m, info.rootElement);
|
|
78
83
|
}
|
|
79
|
-
|
|
80
|
-
module.exports = {
|
|
81
|
-
wrapHtml,
|
|
82
|
-
templateHtml,
|
|
83
|
-
replaceTemplate,
|
|
84
|
-
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
global.staticHttpCache = {};
|
|
1
|
+
import * as renderer from "../../generator/src/render.js";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import * as fs from "./dir-helpers.js";
|
|
4
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { stat } from "fs/promises";
|
|
6
|
+
import { parentPort, threadId, workerData } from "worker_threads";
|
|
9
7
|
|
|
10
8
|
async function run({ mode, pathname, serverRequest, portsFilePath }) {
|
|
11
9
|
console.time(`${threadId} ${pathname}`);
|
|
@@ -13,7 +11,7 @@ async function run({ mode, pathname, serverRequest, portsFilePath }) {
|
|
|
13
11
|
const renderResult = await renderer.render(
|
|
14
12
|
portsFilePath,
|
|
15
13
|
workerData.basePath,
|
|
16
|
-
requireElm(mode),
|
|
14
|
+
await requireElm(mode),
|
|
17
15
|
mode,
|
|
18
16
|
pathname,
|
|
19
17
|
serverRequest,
|
|
@@ -42,20 +40,17 @@ async function run({ mode, pathname, serverRequest, portsFilePath }) {
|
|
|
42
40
|
console.timeEnd(`${threadId} ${pathname}`);
|
|
43
41
|
}
|
|
44
42
|
|
|
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
|
-
}
|
|
43
|
+
async function requireElm(mode) {
|
|
44
|
+
const compiledElmPath = path.join(
|
|
45
|
+
process.cwd(),
|
|
46
|
+
"elm-stuff/elm-pages/elm.cjs"
|
|
47
|
+
);
|
|
48
|
+
let elmImportPath = compiledElmPath;
|
|
49
|
+
const warnOriginal = console.warn;
|
|
50
|
+
console.warn = function () {};
|
|
51
|
+
const Elm = (await import(elmImportPath)).default;
|
|
52
|
+
console.warn = warnOriginal;
|
|
53
|
+
return Elm;
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
async function outputString(
|
|
@@ -67,13 +62,13 @@ async function outputString(
|
|
|
67
62
|
const args = fromElm;
|
|
68
63
|
const normalizedRoute = args.route.replace(/index$/, "");
|
|
69
64
|
await fs.tryMkdir(`./dist/${normalizedRoute}`);
|
|
70
|
-
const template =
|
|
71
|
-
|
|
65
|
+
const template = readFileSync("./dist/template.html", "utf8");
|
|
66
|
+
writeFileSync(
|
|
72
67
|
`dist/${normalizedRoute}/index.html`,
|
|
73
68
|
renderTemplate(template, fromElm)
|
|
74
69
|
);
|
|
75
70
|
args.contentDatPayload &&
|
|
76
|
-
|
|
71
|
+
writeFileSync(
|
|
77
72
|
`dist/${normalizedRoute}/content.dat`,
|
|
78
73
|
Buffer.from(args.contentDatPayload.buffer)
|
|
79
74
|
);
|