elm-pages 3.0.3 → 3.0.4
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/cli.js +25 -6
- 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: 2355856432, 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: 4060045988, 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/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({
|
|
@@ -161,6 +161,7 @@ async function main() {
|
|
|
161
161
|
moduleName
|
|
162
162
|
);
|
|
163
163
|
} catch (error) {
|
|
164
|
+
console.trace(error);
|
|
164
165
|
console.log(restoreColorSafe(error));
|
|
165
166
|
process.exit(1);
|
|
166
167
|
}
|
|
@@ -186,7 +187,7 @@ async function main() {
|
|
|
186
187
|
)
|
|
187
188
|
.action(async (elmModulePath, options, options2) => {
|
|
188
189
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
189
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
190
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
190
191
|
await compileElmForScript(elmModulePath);
|
|
191
192
|
|
|
192
193
|
const cwd = process.cwd();
|
|
@@ -204,7 +205,7 @@ async function main() {
|
|
|
204
205
|
|
|
205
206
|
try {
|
|
206
207
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
207
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
208
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
208
209
|
|
|
209
210
|
const portBackendTaskFileFound =
|
|
210
211
|
globby.globbySync(
|
|
@@ -346,7 +347,7 @@ async function requireElm(compiledElmPath) {
|
|
|
346
347
|
* @param {string} moduleName
|
|
347
348
|
*/
|
|
348
349
|
function generatorWrapperFile(moduleName) {
|
|
349
|
-
return `port module
|
|
350
|
+
return `port module ScriptMain exposing (main)
|
|
350
351
|
|
|
351
352
|
import Pages.Internal.Platform.GeneratorApplication
|
|
352
353
|
import ${moduleName}
|
|
@@ -378,7 +379,7 @@ function collect(value, previous) {
|
|
|
378
379
|
|
|
379
380
|
async function compileElmForScript(elmModulePath) {
|
|
380
381
|
const { moduleName, projectDirectory, sourceDirectory } =
|
|
381
|
-
resolveInputPathOrModuleName(elmModulePath);
|
|
382
|
+
await resolveInputPathOrModuleName(elmModulePath);
|
|
382
383
|
const splitModuleName = moduleName.split(".");
|
|
383
384
|
const expectedFilePath = path.join(
|
|
384
385
|
sourceDirectory,
|
|
@@ -396,7 +397,9 @@ async function compileElmForScript(elmModulePath) {
|
|
|
396
397
|
ensureDirSync(`${projectDirectory}/elm-stuff`);
|
|
397
398
|
ensureDirSync(`${projectDirectory}/elm-stuff/elm-pages/.elm-pages`);
|
|
398
399
|
await fs.promises.writeFile(
|
|
399
|
-
path.join(
|
|
400
|
+
path.join(
|
|
401
|
+
`${projectDirectory}/elm-stuff/elm-pages/.elm-pages/ScriptMain.elm`
|
|
402
|
+
),
|
|
400
403
|
generatorWrapperFile(moduleName)
|
|
401
404
|
);
|
|
402
405
|
let executableName = await lamderaOrElmFallback();
|
|
@@ -406,6 +409,22 @@ async function compileElmForScript(elmModulePath) {
|
|
|
406
409
|
await which("elm");
|
|
407
410
|
executableName = "elm";
|
|
408
411
|
}
|
|
412
|
+
fs.rmSync(`${projectDirectory}/elm-stuff/elm-pages/parentDirectory`, {
|
|
413
|
+
recursive: true,
|
|
414
|
+
force: true,
|
|
415
|
+
});
|
|
416
|
+
fs.mkdirSync(`${projectDirectory}/elm-stuff/elm-pages/parentDirectory`);
|
|
417
|
+
// copy every file ending with '.elm' from `projectDirectory` to `elm-stuff/elm-pages/parentDirectory`
|
|
418
|
+
const elmFiles = globby.globbySync(`${projectDirectory}/*.elm`);
|
|
419
|
+
elmFiles.forEach((elmFile) => {
|
|
420
|
+
fs.copyFileSync(
|
|
421
|
+
elmFile,
|
|
422
|
+
`${projectDirectory}/elm-stuff/elm-pages/parentDirectory/${path.basename(
|
|
423
|
+
elmFile
|
|
424
|
+
)}`
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
|
|
409
428
|
await rewriteElmJson(
|
|
410
429
|
`${projectDirectory}/elm.json`,
|
|
411
430
|
`${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