elm-pages 3.0.0-beta.30 → 3.0.0-beta.32
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/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/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 +4 -104
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +7125 -6415
- 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 +4 -4
- 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 +4 -104
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +16847 -16037
- 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 +5 -5
- package/generator/src/build.js +2 -1
- package/generator/src/cli.js +104 -97
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/compile-elm.js +18 -1
- package/generator/src/render.js +0 -2
- package/generator/src/resolve-elm-module.js +64 -0
- package/generator/src/rewrite-client-elm-json.js +1 -0
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +13 -3
- package/generator/template/elm.json +1 -2
- package/package.json +17 -16
- package/src/Pages/Internal/Platform/Cli.elm +91 -0
- package/src/Pages/Internal/Platform.elm +1 -0
- package/src/Scaffold/Form.elm +190 -128
- package/src/Scaffold/Route.elm +280 -254
- package/src/Server/Session.elm +29 -9
- package/src/Server/SetCookie.elm +11 -3
|
@@ -75,7 +75,7 @@ console.elmlog = (str) => logs.push(str + "\n");
|
|
|
75
75
|
const { Elm } = require("./Runner.elm.js");
|
|
76
76
|
|
|
77
77
|
// Start the Elm app
|
|
78
|
-
const flags = { initialSeed:
|
|
78
|
+
const flags = { initialSeed: 3355512856, fuzzRuns: 100, filter: null };
|
|
79
79
|
const app = Elm.Runner.init({ flags: flags });
|
|
80
80
|
|
|
81
81
|
// Record the timing at which we received the last "runTest" message
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"elm/html": "1.0.0",
|
|
12
12
|
"elm/json": "1.1.3",
|
|
13
13
|
"elm/regex": "1.0.0",
|
|
14
|
-
"jfmengels/elm-review": "2.
|
|
15
|
-
"mdgriffith/elm-codegen": "
|
|
14
|
+
"jfmengels/elm-review": "2.12.2",
|
|
15
|
+
"mdgriffith/elm-codegen": "3.0.0",
|
|
16
16
|
"stil4m/elm-syntax": "7.2.9",
|
|
17
17
|
"the-sett/elm-syntax-dsl": "6.0.2"
|
|
18
18
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"elm-community/basics-extra": "4.1.0",
|
|
28
28
|
"elm-community/list-extra": "8.7.0",
|
|
29
29
|
"elm-community/maybe-extra": "5.3.0",
|
|
30
|
-
"elm-explorations/test": "2.1.
|
|
31
|
-
"miniBill/elm-unicode": "1.0.
|
|
30
|
+
"elm-explorations/test": "2.1.1",
|
|
31
|
+
"miniBill/elm-unicode": "1.0.3",
|
|
32
32
|
"rtfeldman/elm-hex": "1.0.0",
|
|
33
33
|
"stil4m/structured-writer": "1.0.3",
|
|
34
34
|
"the-sett/elm-pretty-printer": "3.0.0"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"test-dependencies": {
|
|
38
38
|
"direct": {
|
|
39
|
-
"elm-explorations/test": "2.1.
|
|
39
|
+
"elm-explorations/test": "2.1.1"
|
|
40
40
|
},
|
|
41
41
|
"indirect": {}
|
|
42
42
|
}
|
package/generator/src/build.js
CHANGED
|
@@ -446,8 +446,9 @@ function modeToOptions(mode) {
|
|
|
446
446
|
*/
|
|
447
447
|
function runElmMake(mode, options, elmEntrypointPath, outputPath, cwd) {
|
|
448
448
|
return new Promise(async (resolve, reject) => {
|
|
449
|
+
const executableName = options.executableName || "lamdera";
|
|
449
450
|
const subprocess = spawnCallback(
|
|
450
|
-
|
|
451
|
+
executableName,
|
|
451
452
|
[
|
|
452
453
|
"make",
|
|
453
454
|
elmEntrypointPath,
|
package/generator/src/cli.js
CHANGED
|
@@ -14,10 +14,11 @@ import * as esbuild from "esbuild";
|
|
|
14
14
|
import { rewriteElmJson } from "./rewrite-elm-json.js";
|
|
15
15
|
import { ensureDirSync } from "./file-helpers.js";
|
|
16
16
|
import * as url from "url";
|
|
17
|
-
|
|
17
|
+
import { default as which } from "which";
|
|
18
18
|
import * as commander from "commander";
|
|
19
19
|
import { runElmCodegenInstall } from "./elm-codegen.js";
|
|
20
20
|
import { packageVersion } from "./compatibility-key.js";
|
|
21
|
+
import { resolveInputPathOrModuleName } from "./resolve-elm-module.js";
|
|
21
22
|
|
|
22
23
|
const Argument = commander.Argument;
|
|
23
24
|
const Option = commander.Option;
|
|
@@ -85,52 +86,31 @@ async function main() {
|
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
program
|
|
88
|
-
.command("run <
|
|
89
|
+
.command("run <elmModulePath>")
|
|
89
90
|
.description("run an elm-pages script")
|
|
90
91
|
.allowUnknownOption()
|
|
91
92
|
.allowExcessArguments()
|
|
92
|
-
.action(async (
|
|
93
|
+
.action(async (elmModulePath, options, options2) => {
|
|
93
94
|
const unprocessedCliOptions = options2.args.splice(
|
|
94
95
|
options2.processedArgs.length,
|
|
95
96
|
options2.args.length
|
|
96
97
|
);
|
|
97
|
-
if (!/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(moduleName)) {
|
|
98
|
-
throw `Invalid module name "${moduleName}", must be in the format of an Elm module`;
|
|
99
|
-
}
|
|
100
|
-
const splitModuleName = moduleName.split(".");
|
|
101
|
-
const expectedFilePath = path.join(
|
|
102
|
-
process.cwd(),
|
|
103
|
-
"script/src/",
|
|
104
|
-
`${splitModuleName.join("/")}.elm`
|
|
105
|
-
);
|
|
106
|
-
if (!fs.existsSync(expectedFilePath)) {
|
|
107
|
-
throw `I couldn't find a module named ${expectedFilePath}`;
|
|
108
|
-
}
|
|
109
98
|
try {
|
|
110
|
-
|
|
111
|
-
ensureDirSync(
|
|
112
|
-
path.join(process.cwd(), ".elm-pages", "http-response-cache")
|
|
113
|
-
);
|
|
114
|
-
if (fs.existsSync("./codegen/")) {
|
|
115
|
-
await runElmCodegenInstall();
|
|
116
|
-
}
|
|
99
|
+
await compileElmForScript(elmModulePath);
|
|
117
100
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await fs.promises.writeFile(
|
|
121
|
-
path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
|
|
122
|
-
generatorWrapperFile(moduleName)
|
|
123
|
-
);
|
|
124
|
-
await rewriteElmJson(
|
|
125
|
-
"./script/elm.json",
|
|
126
|
-
"./script/elm-stuff/elm-pages/elm.json"
|
|
127
|
-
);
|
|
101
|
+
const { moduleName, projectDirectory, sourceDirectory } =
|
|
102
|
+
resolveInputPathOrModuleName(elmModulePath);
|
|
128
103
|
|
|
129
104
|
const portBackendTaskCompiled = esbuild
|
|
130
105
|
.build({
|
|
131
|
-
entryPoints: [
|
|
106
|
+
entryPoints: [
|
|
107
|
+
path.resolve(projectDirectory, "./custom-backend-task"),
|
|
108
|
+
],
|
|
132
109
|
platform: "node",
|
|
133
|
-
outfile:
|
|
110
|
+
outfile: path.resolve(
|
|
111
|
+
projectDirectory,
|
|
112
|
+
".elm-pages/compiled-ports/custom-backend-task.mjs"
|
|
113
|
+
),
|
|
134
114
|
assetNames: "[name]-[hash]",
|
|
135
115
|
chunkNames: "chunks/[name]-[hash]",
|
|
136
116
|
metafile: true,
|
|
@@ -148,32 +128,34 @@ async function main() {
|
|
|
148
128
|
})
|
|
149
129
|
.catch((error) => {
|
|
150
130
|
const portBackendTaskFileFound =
|
|
151
|
-
globby.globbySync(
|
|
131
|
+
globby.globbySync(
|
|
132
|
+
path.resolve(projectDirectory, "./custom-backend-task.*")
|
|
133
|
+
).length > 0;
|
|
152
134
|
if (portBackendTaskFileFound) {
|
|
153
135
|
// don't present error if there are no files matching custom-backend-task
|
|
154
136
|
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
155
|
-
console.error(
|
|
156
|
-
"Failed to start custom-backend-task watcher",
|
|
157
|
-
error
|
|
158
|
-
);
|
|
137
|
+
console.error("Failed to load custom-backend-task file.", error);
|
|
159
138
|
}
|
|
160
139
|
});
|
|
161
140
|
const portsPath = await portBackendTaskCompiled;
|
|
162
141
|
|
|
163
|
-
process.
|
|
142
|
+
const cwd = process.cwd();
|
|
143
|
+
process.chdir(projectDirectory);
|
|
164
144
|
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
165
|
-
|
|
166
|
-
|
|
145
|
+
|
|
146
|
+
let executableName = await lamderaOrElmFallback();
|
|
147
|
+
await build.compileCliApp({ debug: "debug", executableName });
|
|
167
148
|
fs.renameSync(
|
|
168
|
-
|
|
169
|
-
|
|
149
|
+
`${projectDirectory}/elm-stuff/elm-pages/elm.js`,
|
|
150
|
+
`${projectDirectory}/elm-stuff/elm-pages/elm.cjs`
|
|
170
151
|
);
|
|
152
|
+
process.chdir(cwd);
|
|
171
153
|
await renderer.runGenerator(
|
|
172
154
|
unprocessedCliOptions,
|
|
173
155
|
portsPath
|
|
174
156
|
? await import(url.pathToFileURL(path.resolve(portsPath)).href)
|
|
175
157
|
: null,
|
|
176
|
-
await requireElm(
|
|
158
|
+
await requireElm(`${projectDirectory}/elm-stuff/elm-pages/elm.cjs`),
|
|
177
159
|
moduleName
|
|
178
160
|
);
|
|
179
161
|
} catch (error) {
|
|
@@ -200,65 +182,44 @@ async function main() {
|
|
|
200
182
|
collect,
|
|
201
183
|
[]
|
|
202
184
|
)
|
|
203
|
-
.action(async (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
185
|
+
.action(async (elmModulePath, options, options2) => {
|
|
186
|
+
const { moduleName, projectDirectory, sourceDirectory } =
|
|
187
|
+
resolveInputPathOrModuleName(elmModulePath);
|
|
188
|
+
await compileElmForScript(elmModulePath);
|
|
189
|
+
|
|
190
|
+
const cwd = process.cwd();
|
|
191
|
+
process.chdir(projectDirectory);
|
|
192
|
+
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
193
|
+
|
|
194
|
+
let executableName = await lamderaOrElmFallback();
|
|
195
|
+
await build.compileCliApp({ debug: options.debug, executableName });
|
|
196
|
+
fs.renameSync(
|
|
197
|
+
`${projectDirectory}/elm-stuff/elm-pages/elm.js`,
|
|
198
|
+
`${projectDirectory}/elm-stuff/elm-pages/elm.cjs`
|
|
212
199
|
);
|
|
213
|
-
|
|
214
|
-
throw `I couldn't find a module named ${expectedFilePath}`;
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
if (fs.existsSync("./codegen/")) {
|
|
218
|
-
await runElmCodegenInstall();
|
|
219
|
-
}
|
|
200
|
+
process.chdir(cwd);
|
|
220
201
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
path.join("./script/elm-stuff/elm-pages/.elm-pages/Main.elm"),
|
|
225
|
-
generatorWrapperFile(moduleName)
|
|
226
|
-
);
|
|
227
|
-
await rewriteElmJson(
|
|
228
|
-
"./script/elm.json",
|
|
229
|
-
"./script/elm-stuff/elm-pages/elm.json"
|
|
230
|
-
);
|
|
202
|
+
try {
|
|
203
|
+
const { moduleName, projectDirectory, sourceDirectory } =
|
|
204
|
+
resolveInputPathOrModuleName(elmModulePath);
|
|
231
205
|
|
|
232
|
-
process.chdir("./script");
|
|
233
|
-
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
234
|
-
console.log("Compiling...");
|
|
235
|
-
await build.compileCliApp({ debug: options.debug });
|
|
236
|
-
process.chdir("../");
|
|
237
|
-
if (!options.debug) {
|
|
238
|
-
console.log("Running elm-optimize-level-2...");
|
|
239
|
-
await build.elmOptimizeLevel2(
|
|
240
|
-
"./script/elm-stuff/elm-pages/elm.js",
|
|
241
|
-
process.cwd()
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
fs.renameSync(
|
|
245
|
-
"./script/elm-stuff/elm-pages/elm.js",
|
|
246
|
-
"./script/elm-stuff/elm-pages/elm.cjs"
|
|
247
|
-
);
|
|
248
|
-
// TODO allow no custom-backend-task
|
|
249
206
|
const portBackendTaskFileFound =
|
|
250
|
-
globby.globbySync(
|
|
207
|
+
globby.globbySync(
|
|
208
|
+
path.resolve(projectDirectory, "custom-backend-task.*")
|
|
209
|
+
).length > 0;
|
|
251
210
|
|
|
252
211
|
const scriptRunner = `${
|
|
253
212
|
portBackendTaskFileFound
|
|
254
213
|
? `import * as customBackendTask from "${path.resolve(
|
|
214
|
+
projectDirectory,
|
|
255
215
|
"./custom-backend-task"
|
|
256
216
|
)}";`
|
|
257
217
|
: "const customBackendTask = {};"
|
|
258
218
|
}
|
|
259
219
|
import * as renderer from "./render.js";
|
|
260
|
-
import { default as Elm } from "${path.
|
|
261
|
-
|
|
220
|
+
import { default as Elm } from "${path.join(
|
|
221
|
+
projectDirectory,
|
|
222
|
+
"elm-stuff/elm-pages/elm.cjs"
|
|
262
223
|
)}";
|
|
263
224
|
|
|
264
225
|
await renderer.runGenerator(
|
|
@@ -278,9 +239,12 @@ await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await impo
|
|
|
278
239
|
platform: "node",
|
|
279
240
|
stdin: { contents: scriptRunner, resolveDir: __dirname },
|
|
280
241
|
bundle: true,
|
|
281
|
-
outfile
|
|
242
|
+
// TODO do I need to make the outfile joined with the current working directory?
|
|
243
|
+
|
|
244
|
+
outfile: path.resolve(cwd, options.output),
|
|
282
245
|
external: ["node:*", ...options.external],
|
|
283
246
|
minify: true,
|
|
247
|
+
absWorkingDir: projectDirectory,
|
|
284
248
|
banner: { js: `#!/usr/bin/env node\n\n${ESM_REQUIRE_SHIM}` },
|
|
285
249
|
});
|
|
286
250
|
} catch (error) {
|
|
@@ -361,7 +325,6 @@ async function requireElm(compiledElmPath) {
|
|
|
361
325
|
function generatorWrapperFile(moduleName) {
|
|
362
326
|
return `port module Main exposing (main)
|
|
363
327
|
|
|
364
|
-
import Bytes
|
|
365
328
|
import BackendTask exposing (BackendTask)
|
|
366
329
|
import FatalError
|
|
367
330
|
import Cli.Program as Program
|
|
@@ -378,7 +341,7 @@ main =
|
|
|
378
341
|
, toJsPort = toJsPort
|
|
379
342
|
, fromJsPort = fromJsPort identity
|
|
380
343
|
, gotBatchSub = gotBatchSub identity
|
|
381
|
-
, sendPageData =
|
|
344
|
+
, sendPageData = \\_ -> Cmd.none
|
|
382
345
|
}
|
|
383
346
|
|
|
384
347
|
|
|
@@ -389,13 +352,57 @@ port fromJsPort : (Decode.Value -> msg) -> Sub msg
|
|
|
389
352
|
|
|
390
353
|
|
|
391
354
|
port gotBatchSub : (Decode.Value -> msg) -> Sub msg
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
port sendPageData : { oldThing : Encode.Value, binaryPageData : Bytes.Bytes } -> Cmd msg
|
|
395
355
|
`;
|
|
396
356
|
}
|
|
397
357
|
function collect(value, previous) {
|
|
398
358
|
return previous.concat([value]);
|
|
399
359
|
}
|
|
400
360
|
|
|
361
|
+
async function compileElmForScript(elmModulePath) {
|
|
362
|
+
const { moduleName, projectDirectory, sourceDirectory } =
|
|
363
|
+
resolveInputPathOrModuleName(elmModulePath);
|
|
364
|
+
const splitModuleName = moduleName.split(".");
|
|
365
|
+
const expectedFilePath = path.join(
|
|
366
|
+
sourceDirectory,
|
|
367
|
+
`${splitModuleName.join("/")}.elm`
|
|
368
|
+
);
|
|
369
|
+
if (!fs.existsSync(expectedFilePath)) {
|
|
370
|
+
throw `I couldn't find a module named ${expectedFilePath}`;
|
|
371
|
+
}
|
|
372
|
+
// await codegen.generate("");
|
|
373
|
+
ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache"));
|
|
374
|
+
if (fs.existsSync("./codegen/")) {
|
|
375
|
+
await runElmCodegenInstall();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
ensureDirSync(`${projectDirectory}/elm-stuff`);
|
|
379
|
+
ensureDirSync(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages`);
|
|
380
|
+
await fs.promises.writeFile(
|
|
381
|
+
path.join(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages/Main.elm`),
|
|
382
|
+
generatorWrapperFile(moduleName)
|
|
383
|
+
);
|
|
384
|
+
let executableName = await lamderaOrElmFallback();
|
|
385
|
+
try {
|
|
386
|
+
await which("lamdera");
|
|
387
|
+
} catch (error) {
|
|
388
|
+
await which("elm");
|
|
389
|
+
executableName = "elm";
|
|
390
|
+
}
|
|
391
|
+
await rewriteElmJson(
|
|
392
|
+
`${projectDirectory}/elm.json`,
|
|
393
|
+
`${projectDirectory}/elm-stuff/elm-pages/elm.json`,
|
|
394
|
+
{ executableName }
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function lamderaOrElmFallback() {
|
|
399
|
+
try {
|
|
400
|
+
await which("lamdera");
|
|
401
|
+
return "lamdera";
|
|
402
|
+
} catch (error) {
|
|
403
|
+
await which("elm");
|
|
404
|
+
return "elm";
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
401
408
|
main();
|
|
@@ -6,6 +6,8 @@ import * as path from "path";
|
|
|
6
6
|
import * as kleur from "kleur/colors";
|
|
7
7
|
import { inject } from "elm-hot";
|
|
8
8
|
import { fileURLToPath } from "url";
|
|
9
|
+
import { rewriteElmJson } from "./rewrite-elm-json-help.js";
|
|
10
|
+
import { ensureDirSync } from "./file-helpers.js";
|
|
9
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
12
|
const __dirname = path.dirname(__filename);
|
|
11
13
|
|
|
@@ -16,7 +18,22 @@ export async function compileElmForBrowser(options) {
|
|
|
16
18
|
"elm-stuff/elm-pages/",
|
|
17
19
|
"browser-elm.js"
|
|
18
20
|
);
|
|
19
|
-
|
|
21
|
+
const secretDir = path.join(process.cwd(), "elm-stuff/elm-pages/browser-elm");
|
|
22
|
+
await fsHelpers.tryMkdir(secretDir);
|
|
23
|
+
rewriteElmJson(process.cwd(), secretDir, function (elmJson) {
|
|
24
|
+
elmJson["source-directories"] = elmJson["source-directories"].map(
|
|
25
|
+
(item) => {
|
|
26
|
+
return "../../../" + item;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
return elmJson;
|
|
30
|
+
});
|
|
31
|
+
await runElm(
|
|
32
|
+
options,
|
|
33
|
+
"../../../.elm-pages/Main.elm",
|
|
34
|
+
pathToClientElm,
|
|
35
|
+
secretDir
|
|
36
|
+
);
|
|
20
37
|
return fs.promises.writeFile(
|
|
21
38
|
"./.elm-pages/cache/elm.js",
|
|
22
39
|
inject(await fs.promises.readFile(pathToClientElm, "utf-8")).replace(
|
package/generator/src/render.js
CHANGED
|
@@ -133,7 +133,6 @@ function runGeneratorAppHelp(
|
|
|
133
133
|
|
|
134
134
|
killApp = () => {
|
|
135
135
|
app.ports.toJsPort.unsubscribe(portHandler);
|
|
136
|
-
app.ports.sendPageData.unsubscribe(portHandler);
|
|
137
136
|
app.die();
|
|
138
137
|
app = null;
|
|
139
138
|
// delete require.cache[require.resolve(compiledElmPath)];
|
|
@@ -209,7 +208,6 @@ function runGeneratorAppHelp(
|
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
app.ports.toJsPort.subscribe(portHandler);
|
|
212
|
-
app.ports.sendPageData.subscribe(portHandler);
|
|
213
211
|
}).finally(() => {
|
|
214
212
|
try {
|
|
215
213
|
killApp();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
|
|
4
|
+
function findNearestElmJson(filePath) {
|
|
5
|
+
function searchForElmJson(directory) {
|
|
6
|
+
if (directory === "/") {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const elmJsonPath = path.join(directory, "elm.json");
|
|
11
|
+
return fs.existsSync(elmJsonPath)
|
|
12
|
+
? elmJsonPath
|
|
13
|
+
: searchForElmJson(path.dirname(directory));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return searchForElmJson(path.dirname(filePath));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getElmModuleName(inputPath) {
|
|
20
|
+
const filePath = path.normalize(
|
|
21
|
+
path.isAbsolute(inputPath) ? inputPath : path.resolve(inputPath)
|
|
22
|
+
);
|
|
23
|
+
const elmJsonPath = findNearestElmJson(filePath);
|
|
24
|
+
|
|
25
|
+
if (!elmJsonPath) {
|
|
26
|
+
throw new Error("No elm.json found");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const elmJson = JSON.parse(fs.readFileSync(elmJsonPath, "utf8"));
|
|
30
|
+
const sourceDirectories = elmJson["source-directories"];
|
|
31
|
+
const projectDirectory = path.dirname(elmJsonPath);
|
|
32
|
+
|
|
33
|
+
const matchingSourceDir = sourceDirectories
|
|
34
|
+
.map((sourceDir) => path.join(projectDirectory, sourceDir))
|
|
35
|
+
.find((absoluteSourceDir) => filePath.startsWith(absoluteSourceDir));
|
|
36
|
+
|
|
37
|
+
if (!matchingSourceDir) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"File is not in any source-directories specified in elm.json"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const relativePath = path.relative(matchingSourceDir, filePath);
|
|
44
|
+
const moduleName = relativePath
|
|
45
|
+
.replace(path.extname(relativePath), "")
|
|
46
|
+
.replace("/", ".");
|
|
47
|
+
|
|
48
|
+
return { projectDirectory, moduleName, sourceDirectory: matchingSourceDir };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function resolveInputPathOrModuleName(inputPathOrModuleName) {
|
|
52
|
+
if (
|
|
53
|
+
/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(inputPathOrModuleName)
|
|
54
|
+
) {
|
|
55
|
+
const absolutePathForScript = path.resolve("./script/src");
|
|
56
|
+
return {
|
|
57
|
+
moduleName: inputPathOrModuleName,
|
|
58
|
+
projectDirectory: path.resolve("./script"),
|
|
59
|
+
sourceDirectory: path.resolve("./script/src"),
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
62
|
+
return getElmModuleName(inputPathOrModuleName);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -27,6 +27,7 @@ function rewriteClientElmJsonHelp(elmJson) {
|
|
|
27
27
|
elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
|
|
28
28
|
return "../../../" + item;
|
|
29
29
|
});
|
|
30
|
+
elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
|
|
30
31
|
// 3. add our own secret My.elm module 😈
|
|
31
32
|
elmJson["source-directories"].push(".elm-pages");
|
|
32
33
|
elmJson["source-directories"].push("app");
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} sourceElmJsonPath
|
|
6
|
+
* @param {string} targetElmJsonPath
|
|
7
|
+
* @param {( (arg0: JSON) => JSON )?} modifyElmJson
|
|
8
|
+
*/
|
|
9
|
+
export async function rewriteElmJson(
|
|
10
|
+
sourceElmJsonPath,
|
|
11
|
+
targetElmJsonPath,
|
|
12
|
+
modifyElmJson
|
|
13
|
+
) {
|
|
14
|
+
if (!modifyElmJson) {
|
|
15
|
+
modifyElmJson = function (json) {
|
|
16
|
+
return json;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var elmJson = JSON.parse(
|
|
20
|
+
(
|
|
21
|
+
await fs.promises.readFile(path.join(sourceElmJsonPath, "elm.json"))
|
|
22
|
+
).toString()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let modifiedElmJson = modifyElmJson(elmJson);
|
|
26
|
+
// always add `lamdera/codecs` dependency
|
|
27
|
+
modifiedElmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
|
|
28
|
+
|
|
29
|
+
// write new elm.json
|
|
30
|
+
await writeFileIfChanged(
|
|
31
|
+
path.join(targetElmJsonPath, "elm.json"),
|
|
32
|
+
JSON.stringify(modifiedElmJson)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {fs.PathLike | fs.promises.FileHandle} filePath
|
|
38
|
+
* @param {string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream").Stream} content
|
|
39
|
+
*/
|
|
40
|
+
async function writeFileIfChanged(filePath, content) {
|
|
41
|
+
if (
|
|
42
|
+
!(await fileExists(filePath)) ||
|
|
43
|
+
(await fs.promises.readFile(filePath, "utf8")) !== content
|
|
44
|
+
) {
|
|
45
|
+
await fs.promises.writeFile(filePath, content);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param {fs.PathLike} file
|
|
50
|
+
*/
|
|
51
|
+
function fileExists(file) {
|
|
52
|
+
return fs.promises
|
|
53
|
+
.access(file, fs.constants.F_OK)
|
|
54
|
+
.then(() => true)
|
|
55
|
+
.catch(() => false);
|
|
56
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
|
|
3
|
-
export async function rewriteElmJson(
|
|
3
|
+
export async function rewriteElmJson(
|
|
4
|
+
sourceElmJsonPath,
|
|
5
|
+
targetElmJsonPath,
|
|
6
|
+
options
|
|
7
|
+
) {
|
|
4
8
|
var elmJson = JSON.parse(
|
|
5
9
|
(await fs.promises.readFile(sourceElmJsonPath)).toString()
|
|
6
10
|
);
|
|
@@ -9,11 +13,11 @@ export async function rewriteElmJson(sourceElmJsonPath, targetElmJsonPath) {
|
|
|
9
13
|
|
|
10
14
|
await writeFileIfChanged(
|
|
11
15
|
targetElmJsonPath,
|
|
12
|
-
JSON.stringify(rewriteElmJsonHelp(elmJson))
|
|
16
|
+
JSON.stringify(rewriteElmJsonHelp(elmJson, options))
|
|
13
17
|
);
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
function rewriteElmJsonHelp(elmJson) {
|
|
20
|
+
function rewriteElmJsonHelp(elmJson, options) {
|
|
17
21
|
// The internal generated file will be at:
|
|
18
22
|
// ./elm-stuff/elm-pages/
|
|
19
23
|
// So, we need to take the existing elmJson and
|
|
@@ -27,6 +31,12 @@ function rewriteElmJsonHelp(elmJson) {
|
|
|
27
31
|
elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
|
|
28
32
|
return "../../" + item;
|
|
29
33
|
});
|
|
34
|
+
if (options && options.executableName === "elm") {
|
|
35
|
+
// elm, don't add lamdera/codecs
|
|
36
|
+
} else {
|
|
37
|
+
// lamdera, add codecs dependency
|
|
38
|
+
elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
|
|
39
|
+
}
|
|
30
40
|
// 3. add our own secret My.elm module 😈
|
|
31
41
|
elmJson["source-directories"].push(".elm-pages");
|
|
32
42
|
return elmJson;
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"elm-community/result-extra": "2.4.0",
|
|
31
31
|
"jluckyiv/elm-utc-date-strings": "1.0.0",
|
|
32
32
|
"justinmimbs/date": "4.0.1",
|
|
33
|
-
"lamdera/codecs": "1.0.0",
|
|
34
33
|
"mdgriffith/elm-codegen": "2.0.0",
|
|
35
34
|
"miniBill/elm-codec": "2.0.0",
|
|
36
35
|
"noahzgordon/elm-color-extra": "1.0.2",
|
|
@@ -62,4 +61,4 @@
|
|
|
62
61
|
"direct": {},
|
|
63
62
|
"indirect": {}
|
|
64
63
|
}
|
|
65
|
-
}
|
|
64
|
+
}
|