elm-pages 3.0.3 → 3.0.5
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/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/build.js +4 -1
- package/generator/src/cli.js +30 -7
- package/generator/src/parse-remote.js +43 -0
- package/generator/src/render.js +1 -1
- package/generator/src/resolve-elm-module.js +83 -2
- package/generator/src/rewrite-elm-json.js +6 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -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: 1561605696, 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
|
|
Binary file
|
|
@@ -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: 3204223018, 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
|
package/generator/src/build.js
CHANGED
|
@@ -635,7 +635,10 @@ export async function compileCliApp(options) {
|
|
|
635
635
|
// TODO should be --optimize, but there seems to be an issue with the html to JSON with --optimize
|
|
636
636
|
options.debug ? "debug" : "optimize",
|
|
637
637
|
options,
|
|
638
|
-
path.join(
|
|
638
|
+
path.join(
|
|
639
|
+
process.cwd(),
|
|
640
|
+
`elm-stuff/elm-pages/.elm-pages/${options.mainModule || "Main"}.elm`
|
|
641
|
+
),
|
|
639
642
|
path.join(process.cwd(), "elm-stuff/elm-pages/elm.js"),
|
|
640
643
|
path.join(process.cwd(), "elm-stuff/elm-pages")
|
|
641
644
|
);
|
package/generator/src/cli.js
CHANGED
|
@@ -101,7 +101,7 @@ async function main() {
|
|
|
101
101
|
await compileElmForScript(elmModulePath);
|
|
102
102
|
|
|
103
103
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
104
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
104
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
105
105
|
|
|
106
106
|
const portBackendTaskCompiled = esbuild
|
|
107
107
|
.build({
|
|
@@ -146,7 +146,11 @@ async function main() {
|
|
|
146
146
|
// TODO have option for compiling with --debug or not (maybe allow running with elm-optimize-level-2 as well?)
|
|
147
147
|
|
|
148
148
|
let executableName = await lamderaOrElmFallback();
|
|
149
|
-
await build.compileCliApp({
|
|
149
|
+
await build.compileCliApp({
|
|
150
|
+
debug: "debug",
|
|
151
|
+
executableName,
|
|
152
|
+
mainModule: "ScriptMain",
|
|
153
|
+
});
|
|
150
154
|
fs.renameSync(
|
|
151
155
|
`${projectDirectory}/elm-stuff/elm-pages/elm.js`,
|
|
152
156
|
`${projectDirectory}/elm-stuff/elm-pages/elm.cjs`
|
|
@@ -161,6 +165,7 @@ async function main() {
|
|
|
161
165
|
moduleName
|
|
162
166
|
);
|
|
163
167
|
} catch (error) {
|
|
168
|
+
console.trace(error);
|
|
164
169
|
console.log(restoreColorSafe(error));
|
|
165
170
|
process.exit(1);
|
|
166
171
|
}
|
|
@@ -186,7 +191,7 @@ async function main() {
|
|
|
186
191
|
)
|
|
187
192
|
.action(async (elmModulePath, options, options2) => {
|
|
188
193
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
189
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
194
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
190
195
|
await compileElmForScript(elmModulePath);
|
|
191
196
|
|
|
192
197
|
const cwd = process.cwd();
|
|
@@ -204,7 +209,7 @@ async function main() {
|
|
|
204
209
|
|
|
205
210
|
try {
|
|
206
211
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
207
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
212
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
208
213
|
|
|
209
214
|
const portBackendTaskFileFound =
|
|
210
215
|
globby.globbySync(
|
|
@@ -346,7 +351,7 @@ async function requireElm(compiledElmPath) {
|
|
|
346
351
|
* @param {string} moduleName
|
|
347
352
|
*/
|
|
348
353
|
function generatorWrapperFile(moduleName) {
|
|
349
|
-
return `port module
|
|
354
|
+
return `port module ScriptMain exposing (main)
|
|
350
355
|
|
|
351
356
|
import Pages.Internal.Platform.GeneratorApplication
|
|
352
357
|
import ${moduleName}
|
|
@@ -378,7 +383,7 @@ function collect(value, previous) {
|
|
|
378
383
|
|
|
379
384
|
async function compileElmForScript(elmModulePath) {
|
|
380
385
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
381
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
386
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
382
387
|
const splitModuleName = moduleName.split(".");
|
|
383
388
|
const expectedFilePath = path.join(
|
|
384
389
|
sourceDirectory,
|
|
@@ -396,7 +401,9 @@ async function compileElmForScript(elmModulePath) {
|
|
|
396
401
|
ensureDirSync(`${projectDirectory}/elm-stuff`);
|
|
397
402
|
ensureDirSync(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages`);
|
|
398
403
|
await fs.promises.writeFile(
|
|
399
|
-
path.join(
|
|
404
|
+
path.join(
|
|
405
|
+
`${projectDirectory}/elm-stuff/elm-pages/.elm-pages/ScriptMain.elm`
|
|
406
|
+
),
|
|
400
407
|
generatorWrapperFile(moduleName)
|
|
401
408
|
);
|
|
402
409
|
let executableName = await lamderaOrElmFallback();
|
|
@@ -406,6 +413,22 @@ async function compileElmForScript(elmModulePath) {
|
|
|
406
413
|
await which("elm");
|
|
407
414
|
executableName = "elm";
|
|
408
415
|
}
|
|
416
|
+
fs.rmSync(`${projectDirectory}/elm-stuff/elm-pages/parentDirectory`, {
|
|
417
|
+
recursive: true,
|
|
418
|
+
force: true,
|
|
419
|
+
});
|
|
420
|
+
fs.mkdirSync(`${projectDirectory}/elm-stuff/elm-pages/parentDirectory`);
|
|
421
|
+
// copy every file ending with '.elm' from `projectDirectory` to `elm-stuff/elm-pages/parentDirectory`
|
|
422
|
+
const elmFiles = globby.globbySync(`${projectDirectory}/*.elm`);
|
|
423
|
+
elmFiles.forEach((elmFile) => {
|
|
424
|
+
fs.copyFileSync(
|
|
425
|
+
elmFile,
|
|
426
|
+
`${projectDirectory}/elm-stuff/elm-pages/parentDirectory/${path.basename(
|
|
427
|
+
elmFile
|
|
428
|
+
)}`
|
|
429
|
+
);
|
|
430
|
+
});
|
|
431
|
+
|
|
409
432
|
await rewriteElmJson(
|
|
410
433
|
`${projectDirectory}/elm.json`,
|
|
411
434
|
`${projectDirectory}/elm-stuff/elm-pages/elm.json`,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} input
|
|
3
|
+
*/
|
|
4
|
+
export function parse(input) {
|
|
5
|
+
const patterns = [
|
|
6
|
+
/https?:\/\/github\.com\/(?<owner>[^/]+)\/(?<repo>[^/]+)(\/(blob|tree)\/(?<branch>[^/]+)(\/(?<filePath>.*)))?(#?.*)$/,
|
|
7
|
+
/github:(?<owner>[^\/]+)\/(?<repo>[^\/]+):(?<filePath>.*)$/,
|
|
8
|
+
/http(s)?:\/\/raw\.githubusercontent\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/(?<branch>[^\/]+)\/(?<filePath>.*)$/,
|
|
9
|
+
];
|
|
10
|
+
const match = patterns.map((pattern) => input.match(pattern)).find((m) => m);
|
|
11
|
+
|
|
12
|
+
if (match) {
|
|
13
|
+
const g = match.groups;
|
|
14
|
+
return {
|
|
15
|
+
remote: `https://github.com/${g.owner}/${g.repo}.git`,
|
|
16
|
+
filePath: g.filePath || null,
|
|
17
|
+
branch: g.branch || null,
|
|
18
|
+
owner: g.owner,
|
|
19
|
+
repo: g.repo,
|
|
20
|
+
};
|
|
21
|
+
} else {
|
|
22
|
+
const gistPatterns = [
|
|
23
|
+
/https?:\/\/gist\.github.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)(\/?#(?<filePath>.*))?$/,
|
|
24
|
+
/https?:\/\/gist\.github.com\/(?<repo>[^\/]+)(\/?#(?<filePath>.*))?$/,
|
|
25
|
+
/https?:\/\/gist\.githubusercontent\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/raw\/(?<sha>[^/]+)\/(?<filePath>.*)?$/,
|
|
26
|
+
];
|
|
27
|
+
const gistMatch = gistPatterns
|
|
28
|
+
.map((pattern) => input.match(pattern))
|
|
29
|
+
.find((m) => m);
|
|
30
|
+
if (gistMatch) {
|
|
31
|
+
const g = gistMatch.groups;
|
|
32
|
+
return {
|
|
33
|
+
remote: `https://gist.github.com/${g.repo}.git`,
|
|
34
|
+
filePath: g.filePath || "Main.elm",
|
|
35
|
+
branch: null,
|
|
36
|
+
owner: g.owner || "gist",
|
|
37
|
+
repo: g.repo,
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/generator/src/render.js
CHANGED
|
@@ -124,7 +124,7 @@ function runGeneratorAppHelp(
|
|
|
124
124
|
return new Promise((resolve, reject) => {
|
|
125
125
|
const isBytes = pagePath.match(/content\.dat\/?$/);
|
|
126
126
|
|
|
127
|
-
app = elmModule.Elm.
|
|
127
|
+
app = elmModule.Elm.ScriptMain.init({
|
|
128
128
|
flags: {
|
|
129
129
|
compatibilityKey,
|
|
130
130
|
argv: ["", `elm-pages run ${scriptModuleName}`, ...cliOptions],
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
+
import { spawn } from "cross-spawn";
|
|
4
|
+
import { parse } from "../src/parse-remote.js";
|
|
3
5
|
|
|
4
6
|
function findNearestElmJson(filePath) {
|
|
5
7
|
function searchForElmJson(directory) {
|
|
@@ -48,8 +50,14 @@ function getElmModuleName(inputPath) {
|
|
|
48
50
|
return { projectDirectory, moduleName, sourceDirectory: matchingSourceDir };
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
export function resolveInputPathOrModuleName(inputPathOrModuleName) {
|
|
52
|
-
|
|
53
|
+
export async function resolveInputPathOrModuleName(inputPathOrModuleName) {
|
|
54
|
+
const parsed = parse(inputPathOrModuleName);
|
|
55
|
+
if (parsed) {
|
|
56
|
+
const { filePath } = parsed;
|
|
57
|
+
const repoPath = await downloadRemoteScript(parsed);
|
|
58
|
+
const absolutePathForScript = path.join(repoPath, filePath);
|
|
59
|
+
return getElmModuleName(absolutePathForScript);
|
|
60
|
+
} else if (
|
|
53
61
|
/^[A-Z][a-zA-Z0-9_]*(\.[A-Z][a-zA-Z0-9_]*)*$/.test(inputPathOrModuleName)
|
|
54
62
|
) {
|
|
55
63
|
const absolutePathForScript = path.resolve("./script/src");
|
|
@@ -62,3 +70,76 @@ export function resolveInputPathOrModuleName(inputPathOrModuleName) {
|
|
|
62
70
|
return getElmModuleName(inputPathOrModuleName);
|
|
63
71
|
}
|
|
64
72
|
}
|
|
73
|
+
|
|
74
|
+
async function downloadRemoteScript({ remote, owner, repo, branch }) {
|
|
75
|
+
try {
|
|
76
|
+
const cloneToPath = path.join(
|
|
77
|
+
"elm-stuff",
|
|
78
|
+
"elm-pages",
|
|
79
|
+
"remote-scripts",
|
|
80
|
+
owner,
|
|
81
|
+
repo
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const repoExists = fs.existsSync(cloneToPath);
|
|
85
|
+
|
|
86
|
+
if (repoExists) {
|
|
87
|
+
await exec("git", ["pull"], {
|
|
88
|
+
cwd: cloneToPath,
|
|
89
|
+
});
|
|
90
|
+
const defaultBranch = (
|
|
91
|
+
await exec("git", ["remote", "show", "origin"], {
|
|
92
|
+
cwd: cloneToPath,
|
|
93
|
+
})
|
|
94
|
+
).match(/HEAD branch: (?<defaultBranch>.*)/).groups.defaultBranch;
|
|
95
|
+
await exec("git", ["checkout", branch || defaultBranch], {
|
|
96
|
+
cwd: cloneToPath,
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
if (branch) {
|
|
100
|
+
await exec("git", [
|
|
101
|
+
"clone",
|
|
102
|
+
"--branch",
|
|
103
|
+
branch,
|
|
104
|
+
"--depth=1",
|
|
105
|
+
remote,
|
|
106
|
+
cloneToPath,
|
|
107
|
+
]);
|
|
108
|
+
} else {
|
|
109
|
+
await exec("git", ["clone", "--depth=1", remote, cloneToPath]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return cloneToPath;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
throw `I encountered an error cloning the repo:\n\n ${error}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} command
|
|
121
|
+
* @param {readonly string[]} args
|
|
122
|
+
* @param {import("child_process").SpawnOptionsWithoutStdio} [ options ]
|
|
123
|
+
*/
|
|
124
|
+
function exec(command, args, options) {
|
|
125
|
+
return new Promise(async (resolve, reject) => {
|
|
126
|
+
let subprocess = spawn(command, args, options);
|
|
127
|
+
let commandOutput = "";
|
|
128
|
+
|
|
129
|
+
subprocess.stderr.on("data", function (data) {
|
|
130
|
+
commandOutput += data;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
subprocess.stdout.on("data", function (data) {
|
|
134
|
+
commandOutput += data;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
subprocess.on("close", async (code) => {
|
|
138
|
+
if (code === 0) {
|
|
139
|
+
resolve(commandOutput);
|
|
140
|
+
} else {
|
|
141
|
+
reject(commandOutput);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
@@ -28,8 +28,13 @@ function rewriteElmJsonHelp(elmJson, options) {
|
|
|
28
28
|
}
|
|
29
29
|
);
|
|
30
30
|
// 2. prepend ../../../ to remaining
|
|
31
|
+
|
|
31
32
|
elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
|
|
32
|
-
|
|
33
|
+
if (item === ".") {
|
|
34
|
+
return "parentDirectory";
|
|
35
|
+
} else {
|
|
36
|
+
return "../../" + item;
|
|
37
|
+
}
|
|
33
38
|
});
|
|
34
39
|
if (options && options.executableName === "elm") {
|
|
35
40
|
// elm, don't add lamdera/codecs
|
package/package.json
CHANGED