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
package/generator/src/cli.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
import * as build from "./build.js";
|
|
5
|
+
import * as dev from "./dev-server.js";
|
|
6
|
+
import * as init from "./init.js";
|
|
7
|
+
import * as codegen from "./codegen.js";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { restoreColorSafe } from "./error-formatter.js";
|
|
11
|
+
import * as renderer from "./render.js";
|
|
12
|
+
import { globbySync } from "globby";
|
|
13
|
+
import * as esbuild from "esbuild";
|
|
14
|
+
import { rewriteElmJson } from "./rewrite-elm-json.js";
|
|
15
|
+
import { ensureDirSync, deleteIfExists } from "./file-helpers.js";
|
|
16
|
+
import * as url from "url";
|
|
17
|
+
|
|
18
|
+
import * as commander from "commander";
|
|
19
|
+
import { runElmCodegenInstall } from "./elm-codegen.js";
|
|
2
20
|
|
|
3
|
-
const build = require("./build.js");
|
|
4
|
-
const dirHelpers = require("./dir-helpers.js");
|
|
5
|
-
const dev = require("./dev-server.js");
|
|
6
|
-
const init = require("./init.js");
|
|
7
|
-
const codegen = require("./codegen.js");
|
|
8
|
-
const fs = require("fs");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const { restoreColorSafe } = require("./error-formatter");
|
|
11
|
-
|
|
12
|
-
const commander = require("commander");
|
|
13
|
-
const { compileCliApp } = require("./compile-elm.js");
|
|
14
|
-
const { runElmCodegenInstall } = require("./elm-codegen.js");
|
|
15
21
|
const Argument = commander.Argument;
|
|
16
22
|
const Option = commander.Option;
|
|
23
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
24
|
+
const __dirname = path.dirname(__filename);
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
import * as packageJson from "../../package.json" assert { type: "json" };
|
|
27
|
+
const packageVersion = packageJson.version;
|
|
19
28
|
|
|
20
29
|
async function main() {
|
|
21
30
|
const program = new commander.Command();
|
|
@@ -84,66 +93,198 @@ async function main() {
|
|
|
84
93
|
});
|
|
85
94
|
|
|
86
95
|
program
|
|
87
|
-
.command("
|
|
88
|
-
.description("run
|
|
96
|
+
.command("run <moduleName>")
|
|
97
|
+
.description("run an elm-pages script")
|
|
89
98
|
.allowUnknownOption()
|
|
90
99
|
.allowExcessArguments()
|
|
91
100
|
.action(async (moduleName, options, options2) => {
|
|
101
|
+
const unprocessedCliOptions = options2.args.splice(
|
|
102
|
+
options2.processedArgs.length,
|
|
103
|
+
options2.args.length
|
|
104
|
+
);
|
|
92
105
|
if (!/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(moduleName)) {
|
|
93
106
|
throw `Invalid module name "${moduleName}", must be in the format of an Elm module`;
|
|
94
107
|
}
|
|
95
108
|
const splitModuleName = moduleName.split(".");
|
|
96
109
|
const expectedFilePath = path.join(
|
|
97
110
|
process.cwd(),
|
|
98
|
-
"
|
|
111
|
+
"script/src/",
|
|
99
112
|
`${splitModuleName.join("/")}.elm`
|
|
100
113
|
);
|
|
101
114
|
if (!fs.existsSync(expectedFilePath)) {
|
|
102
115
|
throw `I couldn't find a module named ${expectedFilePath}`;
|
|
103
116
|
}
|
|
104
117
|
try {
|
|
105
|
-
await codegen.generate("");
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
// await codegen.generate("");
|
|
119
|
+
ensureDirSync(
|
|
120
|
+
path.join(process.cwd(), ".elm-pages", "http-response-cache")
|
|
121
|
+
);
|
|
122
|
+
if (fs.existsSync("./codegen/")) {
|
|
123
|
+
await runElmCodegenInstall();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ensureDirSync("./script/elm-stuff");
|
|
127
|
+
ensureDirSync("./script/elm-stuff/elm-pages/.elm-pages");
|
|
128
|
+
await fs.promises.writeFile(
|
|
129
|
+
path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
|
|
130
|
+
generatorWrapperFile(moduleName)
|
|
131
|
+
);
|
|
132
|
+
await rewriteElmJson(
|
|
133
|
+
"./script/elm.json",
|
|
134
|
+
"./script/elm-stuff/elm-pages/elm.json"
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const portBackendTaskCompiled = esbuild
|
|
138
|
+
.build({
|
|
139
|
+
entryPoints: ["./custom-backend-task"],
|
|
140
|
+
platform: "node",
|
|
141
|
+
outfile: ".elm-pages/compiled-ports/custom-backend-task.mjs",
|
|
142
|
+
assetNames: "[name]-[hash]",
|
|
143
|
+
chunkNames: "chunks/[name]-[hash]",
|
|
144
|
+
metafile: true,
|
|
145
|
+
bundle: true,
|
|
146
|
+
format: "esm",
|
|
147
|
+
packages: "external",
|
|
148
|
+
logLevel: "silent",
|
|
149
|
+
})
|
|
150
|
+
.then((result) => {
|
|
151
|
+
try {
|
|
152
|
+
return Object.keys(result.metafile.outputs)[0];
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
.catch((error) => {
|
|
158
|
+
const portBackendTaskFileFound =
|
|
159
|
+
globbySync("./custom-backend-task.*").length > 0;
|
|
160
|
+
if (portBackendTaskFileFound) {
|
|
161
|
+
// don't present error if there are no files matching custom-backend-task
|
|
162
|
+
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
163
|
+
console.error(
|
|
164
|
+
"Failed to start custom-backend-task watcher",
|
|
165
|
+
error
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const portsPath = await portBackendTaskCompiled;
|
|
170
|
+
|
|
171
|
+
process.chdir("./script");
|
|
172
|
+
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
173
|
+
await build.compileCliApp({ debug: "debug" });
|
|
174
|
+
process.chdir("../");
|
|
175
|
+
fs.renameSync(
|
|
176
|
+
"./script/elm-stuff/elm-pages/elm.js",
|
|
177
|
+
"./script/elm-stuff/elm-pages/elm.cjs"
|
|
178
|
+
);
|
|
179
|
+
await renderer.runGenerator(
|
|
180
|
+
unprocessedCliOptions,
|
|
181
|
+
await import(url.pathToFileURL(path.resolve(portsPath)).href),
|
|
182
|
+
await requireElm("./script/elm-stuff/elm-pages/elm.cjs"),
|
|
183
|
+
moduleName
|
|
115
184
|
);
|
|
116
185
|
} catch (error) {
|
|
117
186
|
console.log(restoreColorSafe(error));
|
|
118
187
|
process.exit(1);
|
|
119
188
|
}
|
|
189
|
+
});
|
|
120
190
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
191
|
+
program
|
|
192
|
+
.command("bundle-script <moduleName>")
|
|
193
|
+
.description("bundle an elm-pages script")
|
|
194
|
+
.option(
|
|
195
|
+
"--debug",
|
|
196
|
+
"Skip elm-optimize-level-2 and run elm make with --debug"
|
|
197
|
+
)
|
|
198
|
+
.option(
|
|
199
|
+
"--output <path>",
|
|
200
|
+
"Output path for compiled script",
|
|
201
|
+
"./myscript.mjs"
|
|
202
|
+
)
|
|
203
|
+
.option(
|
|
204
|
+
"--external <package-or-pattern>",
|
|
205
|
+
"build site to be served under a base path",
|
|
206
|
+
collect,
|
|
207
|
+
[]
|
|
208
|
+
)
|
|
209
|
+
.action(async (moduleName, options, options2) => {
|
|
210
|
+
if (!/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(moduleName)) {
|
|
211
|
+
throw `Invalid module name "${moduleName}", must be in the format of an Elm module`;
|
|
212
|
+
}
|
|
213
|
+
const splitModuleName = moduleName.split(".");
|
|
214
|
+
const expectedFilePath = path.join(
|
|
215
|
+
process.cwd(),
|
|
216
|
+
"script/src/",
|
|
217
|
+
`${splitModuleName.join("/")}.elm`
|
|
124
218
|
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
219
|
+
if (!fs.existsSync(expectedFilePath)) {
|
|
220
|
+
throw `I couldn't find a module named ${expectedFilePath}`;
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
if (fs.existsSync("./codegen/")) {
|
|
224
|
+
await runElmCodegenInstall();
|
|
225
|
+
}
|
|
128
226
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
227
|
+
ensureDirSync("./script/elm-stuff");
|
|
228
|
+
ensureDirSync("./script/elm-stuff/elm-pages/.elm-pages");
|
|
229
|
+
await fs.promises.writeFile(
|
|
230
|
+
path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
|
|
231
|
+
generatorWrapperFile(moduleName)
|
|
232
|
+
);
|
|
233
|
+
await rewriteElmJson(
|
|
234
|
+
"./script/elm.json",
|
|
235
|
+
"./script/elm-stuff/elm-pages/elm.json"
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
process.chdir("./script");
|
|
239
|
+
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
240
|
+
console.log("Compiling...");
|
|
241
|
+
await build.compileCliApp({ debug: options.debug });
|
|
242
|
+
process.chdir("../");
|
|
243
|
+
if (!options.debug) {
|
|
244
|
+
console.log("Running elm-optimize-level-2...");
|
|
245
|
+
await build.elmOptimizeLevel2(
|
|
246
|
+
"./script/elm-stuff/elm-pages/elm.js",
|
|
247
|
+
process.cwd()
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
fs.renameSync(
|
|
251
|
+
"./script/elm-stuff/elm-pages/elm.js",
|
|
252
|
+
"./script/elm-stuff/elm-pages/elm.cjs"
|
|
253
|
+
);
|
|
254
|
+
const scriptRunner = `import * as customBackendTask from "${path.resolve(
|
|
255
|
+
"./custom-backend-task.ts"
|
|
256
|
+
)}";
|
|
257
|
+
import * as renderer from "./render.js";
|
|
258
|
+
import { default as Elm } from "${path.resolve(
|
|
259
|
+
"./script/elm-stuff/elm-pages/elm.cjs"
|
|
260
|
+
)}";
|
|
261
|
+
|
|
262
|
+
await renderer.runGenerator(
|
|
263
|
+
[...process.argv].splice(2),
|
|
264
|
+
customBackendTask,
|
|
265
|
+
Elm,
|
|
266
|
+
"${moduleName}"
|
|
267
|
+
);
|
|
268
|
+
`;
|
|
269
|
+
// source: https://github.com/evanw/esbuild/pull/2067#issuecomment-1073039746
|
|
270
|
+
const ESM_REQUIRE_SHIM = `
|
|
271
|
+
await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname=e(globalThis.__filename)),typeof globalThis.require>"u"){let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();
|
|
272
|
+
`;
|
|
273
|
+
|
|
274
|
+
await esbuild.build({
|
|
275
|
+
format: "esm",
|
|
276
|
+
platform: "node",
|
|
277
|
+
stdin: { contents: scriptRunner, resolveDir: __dirname },
|
|
278
|
+
bundle: true,
|
|
279
|
+
outfile: options.output,
|
|
280
|
+
external: ["node:*", ...options.external],
|
|
281
|
+
minify: true,
|
|
282
|
+
banner: { js: `#!/usr/bin/env node\n\n${ESM_REQUIRE_SHIM}` },
|
|
283
|
+
});
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.log(restoreColorSafe(error));
|
|
134
286
|
process.exit(1);
|
|
135
|
-
}
|
|
136
|
-
safeSubscribe(program, "printAndExitSuccess", (message) => {
|
|
137
|
-
console.log(message);
|
|
138
|
-
process.exit(0);
|
|
139
|
-
});
|
|
140
|
-
safeSubscribe(program, "writeFile", async (info) => {
|
|
141
|
-
const filePath = path.join(process.cwd(), "app", info.path);
|
|
142
|
-
await dirHelpers.tryMkdir(path.dirname(filePath));
|
|
143
|
-
fs.writeFileSync(filePath, info.body);
|
|
144
|
-
console.log("Success! Created file", filePath);
|
|
145
|
-
process.exit(0);
|
|
146
|
-
});
|
|
287
|
+
}
|
|
147
288
|
});
|
|
148
289
|
|
|
149
290
|
program
|
|
@@ -152,7 +293,7 @@ async function main() {
|
|
|
152
293
|
.option("--port <number>", "serve site at localhost:<port>", "8000")
|
|
153
294
|
.action(async (options) => {
|
|
154
295
|
await codegen.generate("/");
|
|
155
|
-
const DocServer =
|
|
296
|
+
const DocServer = (await import("elm-doc-preview")).default;
|
|
156
297
|
const server = new DocServer({
|
|
157
298
|
port: options.port,
|
|
158
299
|
browser: true,
|
|
@@ -180,7 +321,8 @@ function getAt(properties, object) {
|
|
|
180
321
|
}
|
|
181
322
|
|
|
182
323
|
function safeSubscribe(program, portName, subscribeFunction) {
|
|
183
|
-
program.ports
|
|
324
|
+
program.ports &&
|
|
325
|
+
program.ports[portName] &&
|
|
184
326
|
program.ports[portName].subscribe(subscribeFunction);
|
|
185
327
|
}
|
|
186
328
|
|
|
@@ -218,5 +360,59 @@ function normalizeUrl(rawPagePath) {
|
|
|
218
360
|
// with detecting whether the path contains the base.
|
|
219
361
|
return `/${segments.join("/")}`;
|
|
220
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* @param {string} compiledElmPath
|
|
365
|
+
*/
|
|
366
|
+
async function requireElm(compiledElmPath) {
|
|
367
|
+
const warnOriginal = console.warn;
|
|
368
|
+
console.warn = function () {};
|
|
369
|
+
|
|
370
|
+
let Elm = (await import(path.resolve(compiledElmPath))).default;
|
|
371
|
+
console.warn = warnOriginal;
|
|
372
|
+
return Elm;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @param {string} moduleName
|
|
377
|
+
*/
|
|
378
|
+
function generatorWrapperFile(moduleName) {
|
|
379
|
+
return `port module Main exposing (main)
|
|
380
|
+
|
|
381
|
+
import Bytes
|
|
382
|
+
import BackendTask exposing (BackendTask)
|
|
383
|
+
import FatalError
|
|
384
|
+
import Cli.Program as Program
|
|
385
|
+
import Json.Decode as Decode
|
|
386
|
+
import Json.Encode as Encode
|
|
387
|
+
import Pages.Internal.Platform.GeneratorApplication
|
|
388
|
+
import ${moduleName}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
main : Program.StatefulProgram Pages.Internal.Platform.GeneratorApplication.Model Pages.Internal.Platform.GeneratorApplication.Msg (BackendTask FatalError.FatalError ()) Pages.Internal.Platform.GeneratorApplication.Flags
|
|
392
|
+
main =
|
|
393
|
+
Pages.Internal.Platform.GeneratorApplication.app
|
|
394
|
+
{ data = ${moduleName}.run
|
|
395
|
+
, toJsPort = toJsPort
|
|
396
|
+
, fromJsPort = fromJsPort identity
|
|
397
|
+
, gotBatchSub = gotBatchSub identity
|
|
398
|
+
, sendPageData = sendPageData
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
port toJsPort : Encode.Value -> Cmd msg
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
port fromJsPort : (Decode.Value -> msg) -> Sub msg
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
port gotBatchSub : (Decode.Value -> msg) -> Sub msg
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
port sendPageData : { oldThing : Encode.Value, binaryPageData : Bytes.Bytes } -> Cmd msg
|
|
412
|
+
`;
|
|
413
|
+
}
|
|
414
|
+
function collect(value, previous) {
|
|
415
|
+
return previous.concat([value]);
|
|
416
|
+
}
|
|
221
417
|
|
|
222
418
|
main();
|
package/generator/src/codegen.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as fsExtra from "fs-extra/esm";
|
|
3
|
+
import { rewriteElmJson } from "./rewrite-elm-json.js";
|
|
4
|
+
import { rewriteClientElmJson } from "./rewrite-client-elm-json.js";
|
|
5
|
+
import { elmPagesCliFile, elmPagesUiFile } from "./elm-file-constants.js";
|
|
6
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
7
|
+
import { default as which } from "which";
|
|
8
|
+
import { generateTemplateModuleConnector } from "./generate-template-module-connector.js";
|
|
9
|
+
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { ensureDirSync, deleteIfExists } from "./file-helpers.js";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
13
|
global.builtAt = new Date();
|
|
14
14
|
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* @param {string} basePath
|
|
17
20
|
*/
|
|
18
|
-
async function generate(basePath) {
|
|
21
|
+
export async function generate(basePath) {
|
|
19
22
|
const cliCode = await generateTemplateModuleConnector(basePath, "cli");
|
|
20
23
|
const browserCode = await generateTemplateModuleConnector(
|
|
21
24
|
basePath,
|
|
@@ -63,7 +66,7 @@ async function generate(basePath) {
|
|
|
63
66
|
browserCode.fetcherModules
|
|
64
67
|
),
|
|
65
68
|
// write modified elm.json to elm-stuff/elm-pages/
|
|
66
|
-
|
|
69
|
+
rewriteElmJson("./elm.json", "./elm-stuff/elm-pages/elm.json"),
|
|
67
70
|
// ...(await listFiles("./Pages/Internal")).map(copyToBoth),
|
|
68
71
|
]);
|
|
69
72
|
}
|
|
@@ -85,7 +88,7 @@ async function newCopyBoth(modulePath) {
|
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
async function generateClientFolder(basePath) {
|
|
91
|
+
export async function generateClientFolder(basePath) {
|
|
89
92
|
const browserCode = await generateTemplateModuleConnector(
|
|
90
93
|
basePath,
|
|
91
94
|
"browser"
|
|
@@ -97,7 +100,7 @@ async function generateClientFolder(basePath) {
|
|
|
97
100
|
await newCopyBoth("SharedTemplate.elm");
|
|
98
101
|
await newCopyBoth("SiteConfig.elm");
|
|
99
102
|
|
|
100
|
-
await
|
|
103
|
+
await rewriteClientElmJson();
|
|
101
104
|
await fsExtra.copy("./app", "./elm-stuff/elm-pages/client/app", {
|
|
102
105
|
recursive: true,
|
|
103
106
|
});
|
|
@@ -174,15 +177,16 @@ async function copyToBoth(moduleToCopy) {
|
|
|
174
177
|
copyFileEnsureDir(
|
|
175
178
|
path.join(__dirname, moduleToCopy),
|
|
176
179
|
path.join(`./.elm-pages/`, moduleToCopy)
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
),
|
|
181
|
+
copyFileEnsureDir(
|
|
179
182
|
path.join(__dirname, moduleToCopy),
|
|
180
183
|
path.join(`./elm-stuff/elm-pages/client/.elm-pages`, moduleToCopy)
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
),
|
|
185
|
+
copyFileEnsureDir(
|
|
183
186
|
path.join(__dirname, moduleToCopy),
|
|
184
187
|
path.join(`./elm-stuff/elm-pages/.elm-pages/`, moduleToCopy)
|
|
185
|
-
|
|
188
|
+
),
|
|
189
|
+
]);
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
/**
|
|
@@ -190,10 +194,10 @@ async function copyToBoth(moduleToCopy) {
|
|
|
190
194
|
* @param {string} to
|
|
191
195
|
*/
|
|
192
196
|
async function copyFileEnsureDir(from, to) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
await fs.promises.mkdir(path.dirname(to), {
|
|
198
|
+
recursive: true,
|
|
199
|
+
});
|
|
200
|
+
await fs.promises.copyFile(from, to);
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
/**
|
|
@@ -229,5 +233,3 @@ async function listFiles(dir) {
|
|
|
229
233
|
function merge(arrays) {
|
|
230
234
|
return [].concat.apply([], arrays);
|
|
231
235
|
}
|
|
232
|
-
|
|
233
|
-
module.exports = { generate, generateClientFolder };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const compatibilityKey = 6;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"browser-elm.js"
|
|
12
|
-
);
|
|
1
|
+
import { spawn as spawnCallback } from "cross-spawn";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as fsHelpers from "./dir-helpers.js";
|
|
4
|
+
import * as fsPromises from "fs/promises";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import * as kleur from "kleur/colors";
|
|
7
|
+
import { inject } from "elm-hot";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
13
11
|
|
|
14
|
-
async function compileElmForBrowser(options) {
|
|
12
|
+
export async function compileElmForBrowser(options) {
|
|
13
|
+
// TODO do I need to make sure this is run from the right cwd? Before it was run outside of this function in the global scope, need to make sure that doesn't change semantics.
|
|
14
|
+
const pathToClientElm = path.join(
|
|
15
|
+
process.cwd(),
|
|
16
|
+
"elm-stuff/elm-pages/",
|
|
17
|
+
"browser-elm.js"
|
|
18
|
+
);
|
|
15
19
|
await runElm(options, "./.elm-pages/Main.elm", pathToClientElm);
|
|
16
20
|
return fs.promises.writeFile(
|
|
17
21
|
"./.elm-pages/cache/elm.js",
|
|
@@ -26,7 +30,7 @@ async function compileElmForBrowser(options) {
|
|
|
26
30
|
);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
async function compileCliApp(
|
|
33
|
+
export async function compileCliApp(
|
|
30
34
|
options,
|
|
31
35
|
elmEntrypointPath,
|
|
32
36
|
outputPath,
|
|
@@ -79,7 +83,7 @@ function _HtmlAsJson_toJson(html) {
|
|
|
79
83
|
`;
|
|
80
84
|
|
|
81
85
|
await fsPromises.writeFile(
|
|
82
|
-
readFrom,
|
|
86
|
+
readFrom.replace(/\.js$/, ".cjs"),
|
|
83
87
|
elmFileContent
|
|
84
88
|
.replace(
|
|
85
89
|
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
|
|
@@ -211,7 +215,7 @@ async function runElm(options, elmEntrypointPath, outputPath, cwd) {
|
|
|
211
215
|
/**
|
|
212
216
|
* @param {string} [ cwd ]
|
|
213
217
|
*/
|
|
214
|
-
async function runElmReview(cwd) {
|
|
218
|
+
export async function runElmReview(cwd) {
|
|
215
219
|
const startTime = Date.now();
|
|
216
220
|
return new Promise((resolve, reject) => {
|
|
217
221
|
const child = spawnCallback(
|
|
@@ -284,12 +288,6 @@ function elmOptimizeLevel2(outputPath, cwd) {
|
|
|
284
288
|
});
|
|
285
289
|
}
|
|
286
290
|
|
|
287
|
-
module.exports = {
|
|
288
|
-
compileElmForBrowser,
|
|
289
|
-
runElmReview,
|
|
290
|
-
compileCliApp,
|
|
291
|
-
};
|
|
292
|
-
|
|
293
291
|
/**
|
|
294
292
|
* @param {number} start
|
|
295
293
|
* @param {number} subtract
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
|
|
3
|
+
export async function resolveConfig() {
|
|
4
|
+
const initialConfig = await await import(
|
|
5
|
+
path.join(process.cwd(), "elm-pages.config.mjs")
|
|
6
|
+
)
|
|
7
|
+
.then(async (elmPagesConfig) => {
|
|
8
|
+
return (
|
|
9
|
+
elmPagesConfig.default || {
|
|
10
|
+
headTagsTemplate: defaultHeadTagsTemplate,
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
})
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
console.warn(
|
|
16
|
+
"No `elm-pages.config.mjs` file found. Using default config."
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
headTagsTemplate: defaultHeadTagsTemplate,
|
|
20
|
+
vite: {},
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
preloadTagForFile: function () {
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
headTagsTemplate: defaultHeadTagsTemplate,
|
|
29
|
+
vite: {},
|
|
30
|
+
...initialConfig,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function defaultHeadTagsTemplate(context) {
|
|
35
|
+
return `
|
|
36
|
+
<link rel="stylesheet" href="/style.css" />
|
|
37
|
+
<meta name="generator" content="elm-pages v${context.cliVersion}" />
|
|
38
|
+
`;
|
|
39
|
+
}
|