elm-pages 3.0.12 → 3.0.14
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 +2 -26
- package/codegen/elm-pages-codegen.cjs +10741 -10302
- package/generator/src/build.js +15 -5
- package/generator/src/cli.js +3 -5
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/dev-server.js +3 -0
- package/generator/src/render.js +681 -50
- package/generator/src/request-cache.js +13 -6
- package/generator/src/spinnies/index.js +200 -0
- package/generator/src/spinnies/utils.js +123 -0
- package/generator/src/validate-stream.js +25 -0
- package/generator/template/elm.json +4 -4
- package/generator/template/package.json +6 -6
- package/generator/template/script/elm.json +7 -8
- package/package.json +4 -3
- package/src/BackendTask/Custom.elm +38 -0
- package/src/BackendTask/Do.elm +233 -0
- package/src/BackendTask/File.elm +24 -9
- package/src/BackendTask/Glob.elm +208 -25
- package/src/BackendTask/Http.elm +32 -21
- package/src/BackendTask/Internal/Glob.elm +16 -4
- package/src/BackendTask/Stream.elm +1179 -0
- package/src/BackendTask.elm +214 -7
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform.elm +11 -2
- package/src/Pages/Script/Spinner.elm +505 -0
- package/src/Pages/Script.elm +199 -2
- package/src/Pages/StaticHttp/Request.elm +7 -0
- package/src/RequestsAndPending.elm +1 -1
- package/src/Scaffold/Form.elm +2 -3
- package/src/TerminalText.elm +8 -0
- package/src/Vendored/Result/Extra.elm +75 -0
- 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.elmi +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/Reporter.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.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/lock +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 +0 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -28657
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +0 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
- 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/Pages-Review-NoContractViolationsTest.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.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/lock +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 +0 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -30511
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
- package/generator/review/elm-stuff/tests-0.19.1/js/package.json +0 -1
- package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
- package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
- package/src/Result/Extra.elm +0 -26
|
@@ -9,7 +9,7 @@ const defaultHttpCachePath = "./.elm-pages/http-cache";
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @param {string} mode
|
|
12
|
-
* @param {{url: string;headers: {[x: string]: string;};method: string;body: Body;}} rawRequest
|
|
12
|
+
* @param {{url: string;headers: {[x: string]: string;};method: string;body: Body; }} rawRequest
|
|
13
13
|
* @param {Record<string, unknown>} portsFile
|
|
14
14
|
* @param {boolean} hasFsAccess
|
|
15
15
|
* @returns {Promise<Response>}
|
|
@@ -92,12 +92,18 @@ export function lookupOrPerform(
|
|
|
92
92
|
}),
|
|
93
93
|
});
|
|
94
94
|
} else {
|
|
95
|
-
|
|
95
|
+
!rawRequest.quiet &&
|
|
96
|
+
console.time(`BackendTask.Custom.run "${portName}"`);
|
|
97
|
+
let context = {
|
|
98
|
+
cwd: path.resolve(...rawRequest.dir),
|
|
99
|
+
quiet: rawRequest.quiet,
|
|
100
|
+
env: { ...process.env, ...rawRequest.env },
|
|
101
|
+
};
|
|
96
102
|
try {
|
|
97
103
|
resolve({
|
|
98
104
|
kind: "response-json",
|
|
99
105
|
value: jsonResponse(
|
|
100
|
-
toElmJson(await portBackendTask[portName](input))
|
|
106
|
+
toElmJson(await portBackendTask[portName](input, context))
|
|
101
107
|
),
|
|
102
108
|
});
|
|
103
109
|
} catch (portCallError) {
|
|
@@ -129,7 +135,8 @@ export function lookupOrPerform(
|
|
|
129
135
|
});
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
|
-
|
|
138
|
+
!rawRequest.quiet &&
|
|
139
|
+
console.timeEnd(`BackendTask.Custom.run "${portName}"`);
|
|
133
140
|
}
|
|
134
141
|
} catch (error) {
|
|
135
142
|
console.trace(error);
|
|
@@ -140,7 +147,7 @@ export function lookupOrPerform(
|
|
|
140
147
|
}
|
|
141
148
|
} else {
|
|
142
149
|
try {
|
|
143
|
-
console.time(`fetch ${request.url}`);
|
|
150
|
+
!rawRequest.quiet && console.time(`fetch ${request.url}`);
|
|
144
151
|
const response = await safeFetch(makeFetchHappen, request.url, {
|
|
145
152
|
method: request.method,
|
|
146
153
|
body: request.body,
|
|
@@ -151,7 +158,7 @@ export function lookupOrPerform(
|
|
|
151
158
|
...rawRequest.cacheOptions,
|
|
152
159
|
});
|
|
153
160
|
|
|
154
|
-
console.timeEnd(`fetch ${request.url}`);
|
|
161
|
+
!rawRequest.quiet && console.timeEnd(`fetch ${request.url}`);
|
|
155
162
|
const expectString = request.headers["elm-pages-internal"];
|
|
156
163
|
|
|
157
164
|
let body;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import * as readline from 'readline';
|
|
4
|
+
import * as chalk from "kleur/colors";
|
|
5
|
+
import cliCursor from 'cli-cursor';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { purgeSpinnerOptions, purgeSpinnersOptions, colorOptions, breakText, getLinesLength, terminalSupportsUnicode } from './utils.js';
|
|
9
|
+
import { dots, dashes, writeStream, cleanStream } from './utils.js';
|
|
10
|
+
|
|
11
|
+
export class Spinnies {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
options = purgeSpinnersOptions(options);
|
|
14
|
+
this.options = {
|
|
15
|
+
// TODO kleur doesn't support brightGreen, only nested function or chained syntax
|
|
16
|
+
// spinnerColor: 'brightGreen',
|
|
17
|
+
spinnerColor: 'green',
|
|
18
|
+
succeedColor: 'green',
|
|
19
|
+
failColor: 'red',
|
|
20
|
+
spinner: terminalSupportsUnicode() ? dots : dashes,
|
|
21
|
+
disableSpins: false,
|
|
22
|
+
...options
|
|
23
|
+
};
|
|
24
|
+
this.spinners = {};
|
|
25
|
+
this.isCursorHidden = false;
|
|
26
|
+
this.currentInterval = null;
|
|
27
|
+
this.stream = process.stderr;
|
|
28
|
+
this.lineCount = 0;
|
|
29
|
+
this.currentFrameIndex = 0;
|
|
30
|
+
this.spin = !this.options.disableSpins && !process.env.CI && process.stderr && process.stderr.isTTY;
|
|
31
|
+
this.bindSigint();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pick(name) {
|
|
35
|
+
return this.spinners[name];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
add(name, options = {}) {
|
|
39
|
+
if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
|
|
40
|
+
if (!options.text) options.text = name;
|
|
41
|
+
const spinnerProperties = {
|
|
42
|
+
...colorOptions(this.options),
|
|
43
|
+
succeedPrefix: this.options.succeedPrefix,
|
|
44
|
+
failPrefix: this.options.failPrefix,
|
|
45
|
+
status: 'spinning',
|
|
46
|
+
...purgeSpinnerOptions(options),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.spinners[name] = spinnerProperties;
|
|
50
|
+
this.updateSpinnerState();
|
|
51
|
+
|
|
52
|
+
return spinnerProperties;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
update(name, options = {}) {
|
|
56
|
+
const { status } = options;
|
|
57
|
+
this.setSpinnerProperties(name, options, status);
|
|
58
|
+
this.updateSpinnerState();
|
|
59
|
+
|
|
60
|
+
return this.spinners[name];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
succeed(name, options = {}) {
|
|
64
|
+
this.setSpinnerProperties(name, options, 'succeed');
|
|
65
|
+
this.updateSpinnerState();
|
|
66
|
+
|
|
67
|
+
return this.spinners[name];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fail(name, options = {}) {
|
|
71
|
+
this.setSpinnerProperties(name, options, 'fail');
|
|
72
|
+
this.updateSpinnerState();
|
|
73
|
+
|
|
74
|
+
return this.spinners[name];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
remove(name) {
|
|
78
|
+
if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
|
|
79
|
+
const spinner = this.spinners[name];
|
|
80
|
+
delete this.spinners[name];
|
|
81
|
+
|
|
82
|
+
return spinner;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
stopAll(newStatus = 'stopped') {
|
|
86
|
+
Object.keys(this.spinners).forEach(name => {
|
|
87
|
+
const { status: currentStatus } = this.spinners[name];
|
|
88
|
+
if (currentStatus !== 'fail' && currentStatus !== 'succeed' && currentStatus !== 'non-spinnable') {
|
|
89
|
+
if (newStatus === 'succeed' || newStatus === 'fail') {
|
|
90
|
+
this.spinners[name].status = newStatus;
|
|
91
|
+
this.spinners[name].color = this.options[`${newStatus}Color`];
|
|
92
|
+
} else {
|
|
93
|
+
this.spinners[name].status = 'stopped';
|
|
94
|
+
this.spinners[name].color = 'grey';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.checkIfActiveSpinners();
|
|
99
|
+
|
|
100
|
+
return this.spinners;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
hasActiveSpinners() {
|
|
104
|
+
return !!Object.values(this.spinners).find(({ status }) => status === 'spinning');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setSpinnerProperties(name, options, status) {
|
|
108
|
+
if (typeof name !== 'string') throw Error('A spinner reference name must be specified');
|
|
109
|
+
if (!this.spinners[name]) throw Error(`No spinner initialized with name ${name}`);
|
|
110
|
+
options = purgeSpinnerOptions(options);
|
|
111
|
+
status = status || 'spinning';
|
|
112
|
+
|
|
113
|
+
this.spinners[name] = { ...this.spinners[name], ...options, status };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
updateSpinnerState(name, options = {}, status) {
|
|
117
|
+
if (this.spin) {
|
|
118
|
+
clearInterval(this.currentInterval);
|
|
119
|
+
this.currentInterval = this.loopStream();
|
|
120
|
+
if (!this.isCursorHidden) cliCursor.hide();
|
|
121
|
+
this.isCursorHidden = true;
|
|
122
|
+
this.checkIfActiveSpinners();
|
|
123
|
+
} else {
|
|
124
|
+
this.setRawStreamOutput();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
loopStream() {
|
|
129
|
+
const { frames, interval } = this.options.spinner;
|
|
130
|
+
return setInterval(() => {
|
|
131
|
+
this.setStreamOutput(frames[this.currentFrameIndex]);
|
|
132
|
+
this.currentFrameIndex = this.currentFrameIndex === frames.length - 1 ? 0 : ++this.currentFrameIndex
|
|
133
|
+
}, interval);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
setStreamOutput(frame = '') {
|
|
137
|
+
let output = '';
|
|
138
|
+
const linesLength = [];
|
|
139
|
+
const hasActiveSpinners = this.hasActiveSpinners();
|
|
140
|
+
Object
|
|
141
|
+
.values(this.spinners)
|
|
142
|
+
.map(({ text, status, color, spinnerColor, succeedColor, failColor, succeedPrefix, failPrefix, indent }) => {
|
|
143
|
+
let line;
|
|
144
|
+
let prefixLength = indent || 0;
|
|
145
|
+
if (status === 'spinning') {
|
|
146
|
+
prefixLength += frame.length + 1;
|
|
147
|
+
text = breakText(text, prefixLength);
|
|
148
|
+
line = `${chalk[spinnerColor](frame)} ${color ? chalk[color](text) : text}`;
|
|
149
|
+
} else {
|
|
150
|
+
if (status === 'succeed') {
|
|
151
|
+
prefixLength += succeedPrefix.length + 1;
|
|
152
|
+
if (hasActiveSpinners) text = breakText(text, prefixLength);
|
|
153
|
+
line = `${chalk.green(succeedPrefix)} ${chalk[succeedColor](text)}`;
|
|
154
|
+
} else if (status === 'fail') {
|
|
155
|
+
prefixLength += failPrefix.length + 1;
|
|
156
|
+
if (hasActiveSpinners) text = breakText(text, prefixLength);
|
|
157
|
+
line = `${chalk.red(failPrefix)} ${chalk[failColor](text)}`;
|
|
158
|
+
} else {
|
|
159
|
+
if (hasActiveSpinners) text = breakText(text, prefixLength);
|
|
160
|
+
line = color ? chalk[color](text) : text;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
linesLength.push(...getLinesLength(text, prefixLength));
|
|
164
|
+
output += indent ? `${" ".repeat(indent)}${line}\n` : `${line}\n`;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if(!hasActiveSpinners) readline.clearScreenDown(this.stream);
|
|
168
|
+
writeStream(this.stream, output, linesLength);
|
|
169
|
+
if (hasActiveSpinners) cleanStream(this.stream, linesLength);
|
|
170
|
+
this.lineCount = linesLength.length;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setRawStreamOutput() {
|
|
174
|
+
Object.values(this.spinners).forEach(i => {
|
|
175
|
+
process.stderr.write(`- ${i.text}\n`);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
checkIfActiveSpinners() {
|
|
180
|
+
if (!this.hasActiveSpinners()) {
|
|
181
|
+
if (this.spin) {
|
|
182
|
+
this.setStreamOutput();
|
|
183
|
+
readline.moveCursor(this.stream, 0, this.lineCount);
|
|
184
|
+
clearInterval(this.currentInterval);
|
|
185
|
+
this.isCursorHidden = false;
|
|
186
|
+
cliCursor.show();
|
|
187
|
+
}
|
|
188
|
+
this.spinners = {};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
bindSigint(lines) {
|
|
193
|
+
process.removeAllListeners('SIGINT');
|
|
194
|
+
process.on('SIGINT', () => {
|
|
195
|
+
cliCursor.show();
|
|
196
|
+
readline.moveCursor(process.stderr, 0, this.lineCount);
|
|
197
|
+
process.exit(0);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// source: https://github.com/jbcarpanelli/spinnies/blob/master/utils.js
|
|
4
|
+
// Code vemodified to ESM syntax from original repo
|
|
5
|
+
|
|
6
|
+
import * as readline from "readline";
|
|
7
|
+
// original code dependend on this for `getLinesLength`. Is this necessary?
|
|
8
|
+
// const stripAnsi = require('strip-ansi');
|
|
9
|
+
export const { dashes,dots } =
|
|
10
|
+
{
|
|
11
|
+
"dots": {
|
|
12
|
+
"interval": 50,
|
|
13
|
+
"frames": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
|
14
|
+
},
|
|
15
|
+
"dashes": {
|
|
16
|
+
"interval": 80,
|
|
17
|
+
"frames": ["-", "_"]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const VALID_STATUSES = ['succeed', 'fail', 'spinning', 'non-spinnable', 'stopped'];
|
|
22
|
+
const VALID_COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright'];
|
|
23
|
+
|
|
24
|
+
export function purgeSpinnerOptions(options) {
|
|
25
|
+
const { text, status, indent } = options;
|
|
26
|
+
const opts = { text, status, indent };
|
|
27
|
+
const colors = colorOptions(options);
|
|
28
|
+
|
|
29
|
+
if (!VALID_STATUSES.includes(status)) delete opts.status;
|
|
30
|
+
if (typeof text !== 'string') delete opts.text;
|
|
31
|
+
if (typeof indent !== 'number') delete opts.indent;
|
|
32
|
+
|
|
33
|
+
return { ...colors, ...opts };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function purgeSpinnersOptions({ spinner, disableSpins, ...others }) {
|
|
37
|
+
const colors = colorOptions(others);
|
|
38
|
+
const prefixes = prefixOptions(others);
|
|
39
|
+
const disableSpinsOption = typeof disableSpins === 'boolean' ? { disableSpins } : {};
|
|
40
|
+
spinner = turnToValidSpinner(spinner);
|
|
41
|
+
|
|
42
|
+
return { ...colors, ...prefixes, ...disableSpinsOption, spinner }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function turnToValidSpinner(spinner = {}) {
|
|
46
|
+
const platformSpinner = terminalSupportsUnicode() ? dots : dashes;
|
|
47
|
+
if (!typeof spinner === 'object') return platformSpinner;
|
|
48
|
+
let { interval, frames } = spinner;
|
|
49
|
+
if (!Array.isArray(frames) || frames.length < 1) frames = platformSpinner.frames;
|
|
50
|
+
if (typeof interval !== 'number') interval = platformSpinner.interval;
|
|
51
|
+
|
|
52
|
+
return { interval, frames };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function colorOptions({ color, succeedColor, failColor, spinnerColor }) {
|
|
56
|
+
const colors = { color, succeedColor, failColor, spinnerColor };
|
|
57
|
+
Object.keys(colors).forEach(key => {
|
|
58
|
+
if (!VALID_COLORS.includes(colors[key])) delete colors[key];
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return colors;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function prefixOptions({ succeedPrefix, failPrefix }) {
|
|
65
|
+
if(terminalSupportsUnicode()) {
|
|
66
|
+
succeedPrefix = succeedPrefix || '✓';
|
|
67
|
+
failPrefix = failPrefix || '✖';
|
|
68
|
+
} else {
|
|
69
|
+
succeedPrefix = succeedPrefix || '√';
|
|
70
|
+
failPrefix = failPrefix || '×';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { succeedPrefix, failPrefix };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function breakText(text, prefixLength) {
|
|
77
|
+
return text.split('\n')
|
|
78
|
+
.map((line, index) => index === 0 ? breakLine(line, prefixLength) : breakLine(line, 0))
|
|
79
|
+
.join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function breakLine(line, prefixLength) {
|
|
83
|
+
const columns = process.stderr.columns || 95;
|
|
84
|
+
return line.length >= columns - prefixLength
|
|
85
|
+
? `${line.substring(0, columns - prefixLength - 1)}\n${
|
|
86
|
+
breakLine(line.substring(columns - prefixLength - 1, line.length), 0)
|
|
87
|
+
}`
|
|
88
|
+
: line;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// function getLinesLength(text, prefixLength) {
|
|
92
|
+
// return stripAnsi(text)
|
|
93
|
+
// .split('\n')
|
|
94
|
+
// .map((line, index) => index === 0 ? line.length + prefixLength : line.length);
|
|
95
|
+
// }
|
|
96
|
+
export function getLinesLength(text, prefixLength) {
|
|
97
|
+
return text.split('\n')
|
|
98
|
+
.map((line, index) => index === 0 ? line.length + prefixLength : line.length);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function writeStream(stream, output, rawLines) {
|
|
102
|
+
stream.write(output);
|
|
103
|
+
readline.moveCursor(stream, 0, -rawLines.length);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function cleanStream(stream, rawLines) {
|
|
107
|
+
rawLines.forEach((lineLength, index) => {
|
|
108
|
+
readline.moveCursor(stream, lineLength, index);
|
|
109
|
+
readline.clearLine(stream, 1);
|
|
110
|
+
readline.moveCursor(stream, -lineLength, -index);
|
|
111
|
+
});
|
|
112
|
+
readline.moveCursor(stream, 0, rawLines.length);
|
|
113
|
+
readline.clearScreenDown(stream);
|
|
114
|
+
readline.moveCursor(stream, 0, -rawLines.length);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function terminalSupportsUnicode() {
|
|
118
|
+
// The default command prompt and powershell in Windows do not support Unicode characters.
|
|
119
|
+
// However, the VSCode integrated terminal and the Windows Terminal both do.
|
|
120
|
+
return process.platform !== 'win32'
|
|
121
|
+
|| process.env.TERM_PROGRAM === 'vscode'
|
|
122
|
+
|| !!process.env.WT_SESSION
|
|
123
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// source: https://www.30secondsofcode.org/js/s/typecheck-nodejs-streams/
|
|
2
|
+
|
|
3
|
+
export function isReadableStream(val) {
|
|
4
|
+
return (
|
|
5
|
+
val !== null &&
|
|
6
|
+
typeof val === "object" &&
|
|
7
|
+
typeof val.pipe === "function" &&
|
|
8
|
+
typeof val._read === "function" &&
|
|
9
|
+
typeof val._readableState === "object"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isWritableStream(val) {
|
|
14
|
+
return (
|
|
15
|
+
val !== null &&
|
|
16
|
+
typeof val === "object" &&
|
|
17
|
+
typeof val.pipe === "function" &&
|
|
18
|
+
typeof val._write === "function" &&
|
|
19
|
+
typeof val._writableState === "object"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isDuplexStream(val) {
|
|
24
|
+
return isReadableStream(val) && isWritableStream(val);
|
|
25
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dillonkearns/elm-bcp47-language-tag": "2.0.0",
|
|
15
15
|
"dillonkearns/elm-form": "3.0.0",
|
|
16
16
|
"dillonkearns/elm-markdown": "7.0.1",
|
|
17
|
-
"dillonkearns/elm-pages": "10.0
|
|
17
|
+
"dillonkearns/elm-pages": "10.1.0",
|
|
18
18
|
"elm/browser": "1.0.2",
|
|
19
19
|
"elm/bytes": "1.0.8",
|
|
20
20
|
"elm/core": "1.0.5",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"elm-community/list-extra": "8.7.0",
|
|
31
31
|
"elm-community/result-extra": "2.4.0",
|
|
32
32
|
"jluckyiv/elm-utc-date-strings": "1.0.0",
|
|
33
|
-
"justinmimbs/date": "4.0
|
|
34
|
-
"mdgriffith/elm-codegen": "4.
|
|
33
|
+
"justinmimbs/date": "4.1.0",
|
|
34
|
+
"mdgriffith/elm-codegen": "4.2.1",
|
|
35
35
|
"miniBill/elm-codec": "2.1.0",
|
|
36
36
|
"noahzgordon/elm-color-extra": "1.0.2",
|
|
37
37
|
"robinheghan/fnv1a": "1.0.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"elm-community/basics-extra": "4.1.0",
|
|
50
50
|
"elm-community/maybe-extra": "5.3.0",
|
|
51
51
|
"fredcy/elm-parseint": "2.0.1",
|
|
52
|
-
"miniBill/elm-unicode": "1.1.
|
|
52
|
+
"miniBill/elm-unicode": "1.1.1",
|
|
53
53
|
"robinheghan/murmur3": "1.0.0",
|
|
54
54
|
"rtfeldman/elm-hex": "1.0.0",
|
|
55
55
|
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
|
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
"build": "elm-pages build"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"elm-codegen": "^0.5.
|
|
10
|
+
"elm-codegen": "^0.5.3",
|
|
11
11
|
"elm-optimize-level-2": "^0.3.5",
|
|
12
|
-
"elm-pages": "^3.0.
|
|
13
|
-
"elm-review": "^2.
|
|
14
|
-
"elm-tooling": "^1.15.
|
|
12
|
+
"elm-pages": "^3.0.14",
|
|
13
|
+
"elm-review": "^2.11.1",
|
|
14
|
+
"elm-tooling": "^1.15.1",
|
|
15
15
|
"lamdera": "^0.19.1-1.2.1-1",
|
|
16
|
-
"vite": "^5.
|
|
16
|
+
"vite": "^5.2.10"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@netlify/functions": "^
|
|
19
|
+
"@netlify/functions": "^2.4.1"
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"direct": {
|
|
10
10
|
"dillonkearns/elm-cli-options-parser": "3.2.0",
|
|
11
|
-
"dillonkearns/elm-pages": "10.0
|
|
11
|
+
"dillonkearns/elm-pages": "10.1.0",
|
|
12
12
|
"elm/bytes": "1.0.8",
|
|
13
13
|
"elm/core": "1.0.5",
|
|
14
14
|
"elm/html": "1.0.0",
|
|
15
15
|
"elm/json": "1.1.3",
|
|
16
|
-
"mdgriffith/elm-codegen": "4.
|
|
16
|
+
"mdgriffith/elm-codegen": "4.2.1"
|
|
17
17
|
},
|
|
18
18
|
"indirect": {
|
|
19
19
|
"Chadtech/elm-bool-extra": "2.4.2",
|
|
@@ -37,20 +37,19 @@
|
|
|
37
37
|
"elm-community/maybe-extra": "5.3.0",
|
|
38
38
|
"fredcy/elm-parseint": "2.0.1",
|
|
39
39
|
"jluckyiv/elm-utc-date-strings": "1.0.0",
|
|
40
|
-
"justinmimbs/date": "4.0
|
|
41
|
-
"miniBill/elm-codec": "2.
|
|
42
|
-
"miniBill/elm-unicode": "1.
|
|
40
|
+
"justinmimbs/date": "4.1.0",
|
|
41
|
+
"miniBill/elm-codec": "2.1.0",
|
|
42
|
+
"miniBill/elm-unicode": "1.1.1",
|
|
43
43
|
"noahzgordon/elm-color-extra": "1.0.2",
|
|
44
44
|
"robinheghan/fnv1a": "1.0.0",
|
|
45
45
|
"robinheghan/murmur3": "1.0.0",
|
|
46
46
|
"rtfeldman/elm-css": "18.0.0",
|
|
47
47
|
"rtfeldman/elm-hex": "1.0.0",
|
|
48
48
|
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
|
|
49
|
-
"stil4m/elm-syntax": "7.2
|
|
49
|
+
"stil4m/elm-syntax": "7.3.2",
|
|
50
50
|
"stil4m/structured-writer": "1.0.3",
|
|
51
|
-
"the-sett/elm-pretty-printer": "3.
|
|
51
|
+
"the-sett/elm-pretty-printer": "3.1.0",
|
|
52
52
|
"the-sett/elm-syntax-dsl": "6.0.2",
|
|
53
|
-
"turboMaCk/non-empty-list-alias": "1.3.1",
|
|
54
53
|
"vito/elm-ansi": "10.0.1"
|
|
55
54
|
}
|
|
56
55
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elm-pages",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.14",
|
|
5
5
|
"homepage": "https://elm-pages.com",
|
|
6
6
|
"moduleResolution": "node",
|
|
7
7
|
"description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"author": "Dillon Kearns",
|
|
26
26
|
"license": "BSD-3-Clause",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@sindresorhus/merge-streams": "^3.0.0",
|
|
28
29
|
"busboy": "^1.6.0",
|
|
29
30
|
"chokidar": "^3.5.3",
|
|
31
|
+
"cli-cursor": "^4.0.0",
|
|
30
32
|
"commander": "^11.1.0",
|
|
31
33
|
"connect": "^3.7.0",
|
|
32
34
|
"cookie-signature": "^1.2.1",
|
|
@@ -56,13 +58,12 @@
|
|
|
56
58
|
"@types/node": "^20.10.7",
|
|
57
59
|
"@types/serve-static": "^1.15.5",
|
|
58
60
|
"cypress": "^13.6.2",
|
|
59
|
-
"elm-codegen": "0.
|
|
61
|
+
"elm-codegen": "^0.5.0",
|
|
60
62
|
"elm-optimize-level-2": "^0.3.5",
|
|
61
63
|
"elm-review": "^2.10.3",
|
|
62
64
|
"elm-test": "^0.19.1-revision12",
|
|
63
65
|
"elm-tooling": "^1.15.0",
|
|
64
66
|
"elm-verify-examples": "^5.3.0",
|
|
65
|
-
"elmi-to-json": "^1.4.3",
|
|
66
67
|
"lamdera": "^0.19.1-1.2.1-1",
|
|
67
68
|
"typescript": "^5.3.3",
|
|
68
69
|
"vite": "^5.0.11",
|
|
@@ -55,6 +55,44 @@ ${Object.keys(process.env).join("\n")}
|
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
## Context Parameter
|
|
59
|
+
|
|
60
|
+
If you define a second parameter in an exported `custom-backend-task` file function, you can access the `context` object. This object is a JSON object that contains the following fields:
|
|
61
|
+
|
|
62
|
+
- `cwd` - the current working directory for the `BackendTask`, set by calls to [`BackendTask.inDir`](BackendTask#inDir). If you don't use `BackendTask.inDir`, this will be the directory from which you are invoking `elm-pages`.
|
|
63
|
+
- `env` - the environment variables for the `BackendTask`, set by calls to [`BackendTask.withEnv`](BackendTask#withEnv)
|
|
64
|
+
- `quiet` - a boolean that is `true` if the `BackendTask` is running in quiet mode, set by calls to [`BackendTask.quiet`](BackendTask#quiet)
|
|
65
|
+
|
|
66
|
+
If your `BackendTask.Custom` implementation depends on relative file paths, `process.env`, or has logging, it is recommended to use the `context.cwd` and `context.env` fields to ensure
|
|
67
|
+
that the behavior of your `BackendTask.Custom` is consistent with the core `BackendTask` definitions provided by the framework. For example, the [`BackendTask.Glob`](BackendTask-Glob)
|
|
68
|
+
API will resolve glob patterns relative to the `cwd` context.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import toml from 'toml';
|
|
72
|
+
import fs from 'node:fs/promises';
|
|
73
|
+
import path from 'node:path';
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
export async function readTomlFile(relativeFilePath, context) {
|
|
77
|
+
const filePath = path.resolve(context.cwd, relativeFilePath);
|
|
78
|
+
// toml.parse returns a JSON representation of the TOML input
|
|
79
|
+
return toml.parse(fs.readFile(filePath));
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
import BackendTask exposing (BackendTask)
|
|
84
|
+
import BackendTask.Custom
|
|
85
|
+
import Json.Encode
|
|
86
|
+
import OptimizedDecoder as Decode
|
|
87
|
+
|
|
88
|
+
data : BackendTask FatalError String
|
|
89
|
+
data =
|
|
90
|
+
BackendTask.Custom.run "parseTomlFile"
|
|
91
|
+
(Json.Encode.string "my-file.toml")
|
|
92
|
+
myJsonDecoder
|
|
93
|
+
|> BackendTask.allowFatal
|
|
94
|
+
|
|
95
|
+
|
|
58
96
|
## Performance
|
|
59
97
|
|
|
60
98
|
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server. `elm-pages` performs all `BackendTask`'s in parallel whenever possible.
|