elm-pages 3.0.0-beta.2 → 3.0.0-beta.20
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/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2420 -1592
- 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 +1326 -121
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15215 -13007
- 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/dead-code-review/elm.json +8 -6
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +189 -17
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +255 -21
- 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 +1326 -121
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14620 -12636
- 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/review/elm.json +8 -8
- package/generator/src/RouteBuilder.elm +66 -52
- 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 +122 -86
- package/generator/src/cli.js +247 -51
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +1 -0
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +119 -110
- 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 +14 -21
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +41 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +26 -28
- package/generator/src/render.js +322 -142
- package/generator/src/request-cache.js +200 -162
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +7 -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/hmr.js +16 -2
- package/generator/template/app/Api.elm +3 -3
- package/generator/template/app/Route/Index.elm +3 -3
- package/generator/template/app/Shared.elm +3 -3
- package/generator/template/app/Site.elm +9 -4
- package/package.json +21 -21
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +214 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +128 -43
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +673 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +28 -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 +89 -0
- package/src/Form/Field.elm +1 -1
- package/src/Form.elm +72 -92
- package/src/Head/Seo.elm +4 -4
- 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/Generate.elm +775 -132
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Form.elm +21 -1
- package/src/Pages/Internal/Platform/Cli.elm +479 -747
- package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
- 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 +373 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Internal/Platform.elm +54 -53
- 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/ProgramConfig.elm +12 -8
- 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 -98
- package/src/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +21 -0
- package/src/Server/Request.elm +43 -34
- package/src/Server/Session.elm +166 -100
- package/src/Server/SetCookie.elm +89 -31
- 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
|
@@ -1,36 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { default as which } from "which";
|
|
4
|
+
import * as chokidar from "chokidar";
|
|
5
|
+
import { URL } from "url";
|
|
6
|
+
import {
|
|
7
7
|
compileElmForBrowser,
|
|
8
8
|
runElmReview,
|
|
9
9
|
compileCliApp,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
} from "./compile-elm.js";
|
|
11
|
+
import * as http from "http";
|
|
12
|
+
import * as https from "https";
|
|
13
|
+
import * as codegen from "./codegen.js";
|
|
14
|
+
import * as kleur from "kleur/colors";
|
|
15
|
+
import { default as serveStatic } from "serve-static";
|
|
16
|
+
import { default as connect } from "connect";
|
|
17
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
18
|
+
import { Worker, SHARE_ENV } from "worker_threads";
|
|
19
|
+
import * as os from "os";
|
|
20
|
+
import { ensureDirSync } from "./file-helpers.js";
|
|
21
|
+
import { baseMiddleware } from "./basepath-middleware.js";
|
|
22
|
+
import * as devcert from "devcert";
|
|
23
|
+
import * as busboy from "busboy";
|
|
24
|
+
import { createServer as createViteServer } from "vite";
|
|
25
|
+
import * as esbuild from "esbuild";
|
|
26
|
+
import { merge_vite_configs } from "./vite-utils.js";
|
|
27
|
+
import { templateHtml } from "./pre-render-html.js";
|
|
28
|
+
import { resolveConfig } from "./config.js";
|
|
29
|
+
import { globbySync } from "globby";
|
|
30
|
+
import * as packageJson from "../../package.json" assert { type: "json" };
|
|
31
|
+
import { fileURLToPath } from "url";
|
|
32
|
+
|
|
33
|
+
const cliVersion = packageJson.version;
|
|
34
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
35
|
+
const __dirname = path.dirname(__filename);
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
38
|
* @param {{ port: string; base: string; https: boolean; debug: boolean; }} options
|
|
30
39
|
*/
|
|
31
|
-
async function start(options) {
|
|
40
|
+
export async function start(options) {
|
|
32
41
|
let threadReadyQueue = [];
|
|
33
42
|
let pool = [];
|
|
43
|
+
|
|
44
|
+
function restartPool() {
|
|
45
|
+
pool.forEach((thread) => thread.worker.terminate());
|
|
46
|
+
const poolSize = Math.max(1, cpuCount / 2 - 1);
|
|
47
|
+
pool = [];
|
|
48
|
+
|
|
49
|
+
for (let index = 0; index < poolSize; index++) {
|
|
50
|
+
pool.push(initWorker(options.base));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
34
54
|
ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache"));
|
|
35
55
|
const cpuCount = os.cpus().length;
|
|
36
56
|
|
|
@@ -42,6 +62,7 @@ async function start(options) {
|
|
|
42
62
|
const serveCachedFiles = serveStatic(".elm-pages/cache", { index: false });
|
|
43
63
|
const generatedFilesDirectory = "elm-stuff/elm-pages/generated-files";
|
|
44
64
|
fs.mkdirSync(generatedFilesDirectory, { recursive: true });
|
|
65
|
+
|
|
45
66
|
const serveStaticCode = serveStatic(
|
|
46
67
|
path.join(__dirname, "../static-code"),
|
|
47
68
|
{}
|
|
@@ -117,63 +138,79 @@ async function start(options) {
|
|
|
117
138
|
watcher.add(sourceDirs);
|
|
118
139
|
}
|
|
119
140
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
setup(build) {
|
|
160
|
-
build.onEnd((result) => {
|
|
141
|
+
const config = await resolveConfig();
|
|
142
|
+
const vite = await createViteServer(
|
|
143
|
+
merge_vite_configs(
|
|
144
|
+
{
|
|
145
|
+
server: {
|
|
146
|
+
middlewareMode: true,
|
|
147
|
+
base: options.base,
|
|
148
|
+
port: options.port,
|
|
149
|
+
},
|
|
150
|
+
appType: "custom",
|
|
151
|
+
configFile: false,
|
|
152
|
+
root: process.cwd(),
|
|
153
|
+
base: options.base,
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
config.vite
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const ctx = await esbuild.context({
|
|
161
|
+
entryPoints: ["./custom-backend-task"],
|
|
162
|
+
platform: "node",
|
|
163
|
+
assetNames: "[name]-[hash]",
|
|
164
|
+
chunkNames: "chunks/[name]-[hash]",
|
|
165
|
+
outExtension: { ".js": ".mjs" },
|
|
166
|
+
format: "esm",
|
|
167
|
+
metafile: true,
|
|
168
|
+
bundle: true,
|
|
169
|
+
packages: "external",
|
|
170
|
+
logLevel: "silent",
|
|
171
|
+
outdir: ".elm-pages/compiled-ports",
|
|
172
|
+
entryNames: "[dir]/[name]-[hash]",
|
|
173
|
+
|
|
174
|
+
plugins: [
|
|
175
|
+
{
|
|
176
|
+
name: "example",
|
|
177
|
+
setup(build) {
|
|
178
|
+
build.onEnd(async (result) => {
|
|
179
|
+
try {
|
|
161
180
|
global.portsFilePath = Object.keys(result.metafile.outputs)[0];
|
|
162
181
|
|
|
163
182
|
clients.forEach((client) => {
|
|
164
183
|
client.response.write(`data: content.dat\n\n`);
|
|
165
184
|
});
|
|
166
|
-
})
|
|
167
|
-
|
|
185
|
+
} catch (e) {
|
|
186
|
+
const portBackendTaskFileFound =
|
|
187
|
+
globbySync("./custom-backend-task.*").length > 0;
|
|
188
|
+
if (portBackendTaskFileFound) {
|
|
189
|
+
// don't present error if there are no files matching custom-backend-task
|
|
190
|
+
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
191
|
+
const messages = (
|
|
192
|
+
await esbuild.formatMessages(result.errors, {
|
|
193
|
+
kind: "error",
|
|
194
|
+
color: true,
|
|
195
|
+
})
|
|
196
|
+
).join("\n");
|
|
197
|
+
global.portsFilePath = {
|
|
198
|
+
__internalElmPagesError: messages,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
clients.forEach((client) => {
|
|
202
|
+
client.response.write(`data: content.dat\n\n`);
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
global.portsFilePath = null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
168
209
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
})
|
|
174
|
-
.catch((error) => {
|
|
175
|
-
console.error("Failed to start port-data-source watcher", error);
|
|
176
|
-
});
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
await ctx.watch();
|
|
177
214
|
|
|
178
215
|
const app = connect()
|
|
179
216
|
.use(timeMiddleware())
|
|
@@ -238,6 +275,7 @@ async function start(options) {
|
|
|
238
275
|
}
|
|
239
276
|
}
|
|
240
277
|
elmMakeRunning = true;
|
|
278
|
+
restartPool();
|
|
241
279
|
if (codegenError) {
|
|
242
280
|
const errorJson = JSON.stringify({
|
|
243
281
|
type: "compile-errors",
|
|
@@ -274,18 +312,18 @@ async function start(options) {
|
|
|
274
312
|
// TODO use similar logic in the workers? Or don't use cache at all?
|
|
275
313
|
// const changedPathRelative = path.relative(process.cwd(), pathThatChanged);
|
|
276
314
|
//
|
|
277
|
-
// Object.keys(global.staticHttpCache).forEach((
|
|
278
|
-
// if (
|
|
279
|
-
// delete global.staticHttpCache[
|
|
315
|
+
// Object.keys(global.staticHttpCache).forEach((backendTaskKey) => {
|
|
316
|
+
// if (backendTaskKey.includes(`file://${changedPathRelative}`)) {
|
|
317
|
+
// delete global.staticHttpCache[backendTaskKey];
|
|
280
318
|
// } else if (
|
|
281
319
|
// (eventName === "add" ||
|
|
282
320
|
// eventName === "unlink" ||
|
|
283
321
|
// eventName === "change" ||
|
|
284
322
|
// eventName === "addDir" ||
|
|
285
323
|
// eventName === "unlinkDir") &&
|
|
286
|
-
//
|
|
324
|
+
// backendTaskKey.startsWith("glob://")
|
|
287
325
|
// ) {
|
|
288
|
-
// delete global.staticHttpCache[
|
|
326
|
+
// delete global.staticHttpCache[backendTaskKey];
|
|
289
327
|
// }
|
|
290
328
|
// });
|
|
291
329
|
clients.forEach((client) => {
|
|
@@ -459,35 +497,7 @@ async function start(options) {
|
|
|
459
497
|
}
|
|
460
498
|
case "html": {
|
|
461
499
|
try {
|
|
462
|
-
const template =
|
|
463
|
-
/*html*/
|
|
464
|
-
`<!DOCTYPE html>
|
|
465
|
-
<!-- ROOT --><html lang="en">
|
|
466
|
-
<head>
|
|
467
|
-
<script src="/hmr.js" type="text/javascript"></script>
|
|
468
|
-
<script src="/elm.js" type="text/javascript"></script>
|
|
469
|
-
<link rel="stylesheet" href="/style.css">
|
|
470
|
-
<link rel="stylesheet" href="/dev-style.css">
|
|
471
|
-
<script src="/elm-pages.js" type="module"></script>
|
|
472
|
-
<meta charset="UTF-8" />
|
|
473
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
474
|
-
<title><!-- PLACEHOLDER_TITLE --></title>
|
|
475
|
-
<meta name="generator" content="elm-pages v${cliVersion}" />
|
|
476
|
-
<meta name="mobile-web-app-capable" content="yes" />
|
|
477
|
-
<meta name="theme-color" content="#ffffff" />
|
|
478
|
-
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
479
|
-
<meta
|
|
480
|
-
name="apple-mobile-web-app-status-bar-style"
|
|
481
|
-
content="black-translucent"
|
|
482
|
-
/>
|
|
483
|
-
<!-- PLACEHOLDER_HEAD_AND_DATA -->
|
|
484
|
-
</head>
|
|
485
|
-
<body>
|
|
486
|
-
<div data-url="" display="none"></div>
|
|
487
|
-
<!-- PLACEHOLDER_HTML -->
|
|
488
|
-
</body>
|
|
489
|
-
</html>
|
|
490
|
-
`;
|
|
500
|
+
const template = templateHtml(true, config.headTagsTemplate);
|
|
491
501
|
const processedTemplate = await vite.transformIndexHtml(
|
|
492
502
|
req.originalUrl,
|
|
493
503
|
template
|
|
@@ -804,4 +814,3 @@ function paramsToObject(entries) {
|
|
|
804
814
|
}
|
|
805
815
|
return result;
|
|
806
816
|
}
|
|
807
|
-
module.exports = { start };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as util from "node:util";
|
|
2
|
+
import * as fsSync from "node:fs";
|
|
3
|
+
import * as path from "node: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();
|
|
@@ -75,20 +75,3 @@ async function copyDirNested(src, dest) {
|
|
|
75
75
|
fs.copyFile(src, dest);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
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
|
|
@@ -17,6 +17,9 @@ function runElmCodegenInstall() {
|
|
|
17
17
|
subprocess.stderr.on("data", function (data) {
|
|
18
18
|
commandOutput += data;
|
|
19
19
|
});
|
|
20
|
+
subprocess.stdout.on("data", function (data) {
|
|
21
|
+
commandOutput += data;
|
|
22
|
+
});
|
|
20
23
|
subprocess.on("error", function () {
|
|
21
24
|
reject(commandOutput);
|
|
22
25
|
});
|
|
@@ -30,5 +33,3 @@ function runElmCodegenInstall() {
|
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
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
|
|
@@ -13,11 +15,12 @@ const kleur = require("kleur");
|
|
|
13
15
|
* @param {string} rule
|
|
14
16
|
* @param {string} path
|
|
15
17
|
* */
|
|
16
|
-
|
|
17
|
-
kleur.cyan(
|
|
18
|
-
`-- ${rule.replace("-", " ")} --------------- ${path || ""}
|
|
18
|
+
function parseHeader(rule, path) {
|
|
19
|
+
return kleur.cyan(
|
|
20
|
+
`-- ${(rule || "").replace("-", " ")} --------------- ${path || ""}
|
|
19
21
|
`
|
|
20
22
|
);
|
|
23
|
+
}
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* parseMsg :: String|Object -> String
|
|
@@ -55,9 +58,6 @@ function toKleurColor(color) {
|
|
|
55
58
|
case "33BBC8": {
|
|
56
59
|
return "cyan";
|
|
57
60
|
}
|
|
58
|
-
case "33BBC8": {
|
|
59
|
-
return "cyan";
|
|
60
|
-
}
|
|
61
61
|
case "FFFF00": {
|
|
62
62
|
return "yellow";
|
|
63
63
|
}
|
|
@@ -81,7 +81,7 @@ function toKleurColor(color) {
|
|
|
81
81
|
/**
|
|
82
82
|
* @param {RootObject} error
|
|
83
83
|
* */
|
|
84
|
-
const restoreColor = (error) => {
|
|
84
|
+
export const restoreColor = (error) => {
|
|
85
85
|
try {
|
|
86
86
|
if (error.type === "compile-errors") {
|
|
87
87
|
return error.errors
|
|
@@ -110,7 +110,7 @@ const restoreColor = (error) => {
|
|
|
110
110
|
* @param {string} error
|
|
111
111
|
* @returns {string}
|
|
112
112
|
*/
|
|
113
|
-
function restoreColorSafe(error) {
|
|
113
|
+
export function restoreColorSafe(error) {
|
|
114
114
|
try {
|
|
115
115
|
if (typeof error === "string") {
|
|
116
116
|
const asJson = JSON.parse(error);
|
|
@@ -137,7 +137,10 @@ const restoreProblem =
|
|
|
137
137
|
parseHeader(info.rule, path),
|
|
138
138
|
...info.formatted.map(parseMsg),
|
|
139
139
|
].join("");
|
|
140
|
+
} else if (typeof info.message === "string") {
|
|
141
|
+
return info.message;
|
|
140
142
|
} else {
|
|
143
|
+
// console.log("info.message", info.message);
|
|
141
144
|
return [
|
|
142
145
|
parseHeader(info.title, path),
|
|
143
146
|
...info.message.map(parseMsg),
|
|
@@ -145,8 +148,6 @@ const restoreProblem =
|
|
|
145
148
|
}
|
|
146
149
|
};
|
|
147
150
|
|
|
148
|
-
module.exports = { restoreColor, restoreColorSafe };
|
|
149
|
-
|
|
150
151
|
/** @typedef { CompilerError | ReportError | IElmReviewError } RootObject */
|
|
151
152
|
|
|
152
153
|
/** @typedef { { type: "compile-errors"; errors: Error_[]; } } CompilerError */
|
|
@@ -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,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 },
|
|
@@ -82,18 +83,16 @@ async function runElmCodegenCli(templates, basePath, phase) {
|
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
85
|
const filesToGenerate = await promise;
|
|
85
|
-
console.dir(filesToGenerate.map((file) => file.path));
|
|
86
86
|
|
|
87
87
|
return filesToGenerate;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
90
|
/**
|
|
92
91
|
*
|
|
93
92
|
* @param {string[][]} templates
|
|
94
93
|
* @returns
|
|
95
94
|
*/
|
|
96
|
-
function sortTemplates(templates) {
|
|
95
|
+
export function sortTemplates(templates) {
|
|
97
96
|
return templates.sort((first, second) => {
|
|
98
97
|
const a = sortScore(first);
|
|
99
98
|
const b = sortScore(second);
|
|
@@ -153,8 +152,6 @@ function sortScore(name) {
|
|
|
153
152
|
);
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
158
155
|
function fetcherModule(name) {
|
|
159
156
|
let moduleName = name.join(".");
|
|
160
157
|
// TODO need to account for splat routes/etc.
|
|
@@ -226,7 +223,6 @@ submit toMsg options =
|
|
|
226
223
|
`;
|
|
227
224
|
}
|
|
228
225
|
|
|
229
|
-
|
|
230
226
|
/**
|
|
231
227
|
* Convert Strings from camelCase to kebab-case
|
|
232
228
|
* @param {string} input
|
|
@@ -235,6 +231,3 @@ submit toMsg options =
|
|
|
235
231
|
function camelToKebab(input) {
|
|
236
232
|
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
237
233
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
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 };
|