elm-pages 3.0.19 → 3.0.21
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 +1 -1
- package/generator/dead-code-review/elm.json +2 -3
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +1 -1
- package/generator/review/elm.json +4 -4
- package/generator/src/build.js +27 -17
- package/generator/src/cli.js +3 -1
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/dev-server.js +6 -4
- package/generator/src/generate-template-module-connector.js +3 -1
- package/generator/src/pre-render-html.js +6 -5
- package/generator/src/request-cache.js +12 -6
- package/generator/src/spinnies/index.js +76 -43
- package/generator/src/spinnies/utils.js +74 -41
- package/generator/static-code/hmr.js +2 -3
- package/generator/template/elm.json +8 -7
- package/generator/template/index.ts +2 -1
- package/generator/template/package.json +6 -6
- package/generator/template/script/.elm-pages/compiled-ports/custom-backend-task.mjs +1 -3
- package/generator/template/script/elm.json +7 -7
- package/generator/template/script/src/AddRoute.elm +77 -73
- package/generator/template/script/src/AddStaticRoute.elm +5 -3
- package/package.json +21 -19
- package/src/AriaLiveAnnouncer.elm +1 -0
- package/src/Pages/Internal/Platform/Cli.elm +2 -1
- package/src/Pages/Internal/Platform.elm +10 -2
- package/src/TerminalText.elm +47 -43
- package/generator/src/codegen-template-builder.js +0 -0
- package/generator/src/hello.ts +0 -5
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
- [elm-pages Docs Site](https://elm-pages.com/docs)
|
|
13
13
|
- [elm-pages site showcase](https://elm-pages.com/showcase/)
|
|
14
|
-
- [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.
|
|
14
|
+
- [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.0/)
|
|
15
15
|
- [Quick start repo](https://github.com/dillonkearns/elm-pages-starter) [(live site hosted here)](https://elm-pages-starter.netlify.com)
|
|
16
16
|
- [Introducing `elm-pages` blog post](https://elm-pages.com/blog/introducing-elm-pages)
|
|
17
17
|
- [`examples` folder](https://github.com/dillonkearns/elm-pages/blob/master/examples/) (includes https://elm-pages.com site source) Use `git clone --recurse-submodules https://github.com/dillonkearns/elm-pages.git` so that there aren't missing files when you try to build the examples.
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"elm/core": "1.0.5",
|
|
11
11
|
"elm/json": "1.1.3",
|
|
12
12
|
"elm-community/result-extra": "2.4.0",
|
|
13
|
-
"jfmengels/elm-review": "2.
|
|
14
|
-
"stil4m/elm-syntax": "7.3.
|
|
13
|
+
"jfmengels/elm-review": "2.15.1",
|
|
14
|
+
"stil4m/elm-syntax": "7.3.8"
|
|
15
15
|
},
|
|
16
16
|
"indirect": {
|
|
17
17
|
"elm/bytes": "1.0.8",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"elm/time": "1.0.0",
|
|
24
24
|
"elm/virtual-dom": "1.0.3",
|
|
25
25
|
"elm-explorations/test": "2.2.0",
|
|
26
|
-
"miniBill/elm-unicode": "1.1.1",
|
|
27
26
|
"rtfeldman/elm-hex": "1.0.0",
|
|
28
27
|
"stil4m/structured-writer": "1.0.3"
|
|
29
28
|
}
|
|
@@ -11,9 +11,9 @@
|
|
|
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": "5.
|
|
16
|
-
"stil4m/elm-syntax": "7.3.
|
|
14
|
+
"jfmengels/elm-review": "2.15.1",
|
|
15
|
+
"mdgriffith/elm-codegen": "5.2.0",
|
|
16
|
+
"stil4m/elm-syntax": "7.3.8",
|
|
17
17
|
"the-sett/elm-syntax-dsl": "6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"indirect": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"miniBill/elm-unicode": "1.1.1",
|
|
31
31
|
"rtfeldman/elm-hex": "1.0.0",
|
|
32
32
|
"stil4m/structured-writer": "1.0.3",
|
|
33
|
-
"the-sett/elm-pretty-printer": "3.1.
|
|
33
|
+
"the-sett/elm-pretty-printer": "3.1.1"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"test-dependencies": {
|
package/generator/src/build.js
CHANGED
|
@@ -73,7 +73,11 @@ export async function run(options) {
|
|
|
73
73
|
// This is a temporary hack to avoid this warning. elm-pages manages compiling the Elm code without Vite's involvement, so it is external to Vite.
|
|
74
74
|
// There is a pending issue to allow having external scripts in Vite, once this issue is fixed we can remove this hack:
|
|
75
75
|
// https://github.com/vitejs/vite/issues/3533
|
|
76
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
messages &&
|
|
78
|
+
messages[0] &&
|
|
79
|
+
!messages[0].startsWith(`<script src="/elm.js">`)
|
|
80
|
+
) {
|
|
77
81
|
console.info(...messages);
|
|
78
82
|
}
|
|
79
83
|
};
|
|
@@ -97,13 +101,11 @@ export async function run(options) {
|
|
|
97
101
|
configFile: false,
|
|
98
102
|
root: process.cwd(),
|
|
99
103
|
base: options.base,
|
|
100
|
-
assetsInclude: [
|
|
101
|
-
'/elm-pages.js'
|
|
102
|
-
],
|
|
104
|
+
assetsInclude: ["/elm-pages.js"],
|
|
103
105
|
ssr: false,
|
|
104
106
|
|
|
105
107
|
build: {
|
|
106
|
-
manifest:
|
|
108
|
+
manifest: "___vite-manifest___.json",
|
|
107
109
|
outDir: "dist",
|
|
108
110
|
rollupOptions: {
|
|
109
111
|
input: "elm-stuff/elm-pages/index.html",
|
|
@@ -126,7 +128,10 @@ export async function run(options) {
|
|
|
126
128
|
fullOutputPath,
|
|
127
129
|
withoutExtension
|
|
128
130
|
);
|
|
129
|
-
const assetManifestPath = path.join(
|
|
131
|
+
const assetManifestPath = path.join(
|
|
132
|
+
process.cwd(),
|
|
133
|
+
"dist/___vite-manifest___.json"
|
|
134
|
+
);
|
|
130
135
|
const manifest = JSON.parse(
|
|
131
136
|
await fsPromises.readFile(assetManifestPath, { encoding: "utf-8" })
|
|
132
137
|
);
|
|
@@ -292,7 +297,7 @@ export async function render(request) {
|
|
|
292
297
|
processedIndexTemplate
|
|
293
298
|
);
|
|
294
299
|
} catch (error) {
|
|
295
|
-
if(error) {
|
|
300
|
+
if (error) {
|
|
296
301
|
console.error(restoreColorSafe(error));
|
|
297
302
|
}
|
|
298
303
|
buildError = true;
|
|
@@ -486,9 +491,7 @@ async function spawnElmMake(mode, options, elmEntrypointPath, outputPath, cwd) {
|
|
|
486
491
|
}
|
|
487
492
|
await fsPromises.writeFile(
|
|
488
493
|
outputPath,
|
|
489
|
-
(
|
|
490
|
-
await fsPromises.readFile(outputPath, "utf-8")
|
|
491
|
-
).replace(
|
|
494
|
+
(await fsPromises.readFile(outputPath, "utf-8")).replace(
|
|
492
495
|
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_FORM_TO_STRING.\)/g,
|
|
493
496
|
"function appendSubmitter (myFormData, event) { event.submitter && event.submitter.name && event.submitter.name.length > 0 ? myFormData.append(event.submitter.name, event.submitter.value) : myFormData; return myFormData }; return " +
|
|
494
497
|
(options.debug
|
|
@@ -685,19 +688,26 @@ function _HtmlAsJson_toJson(html) {
|
|
|
685
688
|
|
|
686
689
|
await fsPromises.writeFile(
|
|
687
690
|
ELM_FILE_PATH().replace(/\.js$/, ".cjs"),
|
|
688
|
-
applyScriptPatches(
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
691
|
+
applyScriptPatches(
|
|
692
|
+
options,
|
|
693
|
+
elmFileContent
|
|
694
|
+
.replace(
|
|
695
|
+
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,
|
|
696
|
+
`return ${forceThunksSource}
|
|
692
697
|
return _Json_wrap(forceThunks(html));
|
|
693
698
|
`
|
|
694
|
-
|
|
695
|
-
|
|
699
|
+
)
|
|
700
|
+
.replace(`console.log('App dying')`, "")
|
|
701
|
+
)
|
|
702
|
+
);
|
|
696
703
|
}
|
|
697
704
|
|
|
698
705
|
function applyScriptPatches(options, input) {
|
|
699
706
|
if (options.isScript) {
|
|
700
|
-
return input.replace(
|
|
707
|
+
return input.replace(
|
|
708
|
+
`_Debug_crash(8, moduleName, region, message)`,
|
|
709
|
+
"console.error('TODO in module `' + moduleName + '` ' + _Debug_regionToString(region) + '\\n\\n' + message); process.exitCode = 1; debugger; throw 'CRASH!';"
|
|
710
|
+
);
|
|
701
711
|
} else {
|
|
702
712
|
return input;
|
|
703
713
|
}
|
package/generator/src/cli.js
CHANGED
|
@@ -344,7 +344,9 @@ async function requireElm(compiledElmPath) {
|
|
|
344
344
|
const warnOriginal = console.warn;
|
|
345
345
|
console.warn = function () {};
|
|
346
346
|
|
|
347
|
-
let Elm = (
|
|
347
|
+
let Elm = (
|
|
348
|
+
await import(url.pathToFileURL(path.resolve(compiledElmPath)).href)
|
|
349
|
+
).default;
|
|
348
350
|
console.warn = warnOriginal;
|
|
349
351
|
return Elm;
|
|
350
352
|
}
|
|
@@ -37,7 +37,11 @@ const __dirname = path.dirname(__filename);
|
|
|
37
37
|
*/
|
|
38
38
|
export async function start(options) {
|
|
39
39
|
console.error = function (...messages) {
|
|
40
|
-
if (
|
|
40
|
+
if (
|
|
41
|
+
messages &&
|
|
42
|
+
messages[0] &&
|
|
43
|
+
!messages[0].startsWith("Failed to load url")
|
|
44
|
+
) {
|
|
41
45
|
console.info(...messages);
|
|
42
46
|
}
|
|
43
47
|
};
|
|
@@ -175,9 +179,7 @@ export async function start(options) {
|
|
|
175
179
|
base: options.base,
|
|
176
180
|
port: options.port,
|
|
177
181
|
},
|
|
178
|
-
assetsInclude: [
|
|
179
|
-
'/elm-pages.js'
|
|
180
|
-
],
|
|
182
|
+
assetsInclude: ["/elm-pages.js"],
|
|
181
183
|
appType: "custom",
|
|
182
184
|
configFile: false,
|
|
183
185
|
root: process.cwd(),
|
|
@@ -66,7 +66,9 @@ export async function generateTemplateModuleConnector(basePath, phase) {
|
|
|
66
66
|
async function runElmCodegenCli(templates, basePath, phase) {
|
|
67
67
|
const __filename = fileURLToPath(import.meta.url);
|
|
68
68
|
const __dirname = path.dirname(__filename);
|
|
69
|
-
const filePath = pathToFileURL(
|
|
69
|
+
const filePath = pathToFileURL(
|
|
70
|
+
path.join(__dirname, `../../codegen/elm-pages-codegen.cjs`)
|
|
71
|
+
).href;
|
|
70
72
|
|
|
71
73
|
const promise = new Promise(async (resolve, reject) => {
|
|
72
74
|
const elmPagesCodegen = (await import(filePath)).default.Elm.Generate;
|
|
@@ -48,11 +48,12 @@ export function templateHtml(devMode, userHeadTagsTemplate) {
|
|
|
48
48
|
${indent(userHeadTagsTemplate({ cliVersion: packageVersion }))}
|
|
49
49
|
<!-- PLACEHOLDER_HEAD_AND_DATA -->
|
|
50
50
|
</head>
|
|
51
|
-
<body
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
</html
|
|
51
|
+
<body><div data-elm data-url="" style="display: none;"></div><div data-elm id="elm-pages-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 0; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); whiteSpace: nowrap; border: 0;"></div><!-- PLACEHOLDER_HTML --></body></html>`;
|
|
52
|
+
// NOTE: The above line needs to:
|
|
53
|
+
// - Be in sync with `view` in Platform.elm (render the same elements).
|
|
54
|
+
// - Have `data-elm` on each child of `<body>`.
|
|
55
|
+
// - Not include any extra whitespace. Even whitespace between </body> and </html> is parsed by browsers as a text node _inside_ <body>.
|
|
56
|
+
// This is to avoid unnecessary rerenders on init (when the first `view` call is diffed with the virtualized form of the above HTML).
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -21,6 +21,14 @@ export function lookupOrPerform(
|
|
|
21
21
|
hasFsAccess,
|
|
22
22
|
useCache
|
|
23
23
|
) {
|
|
24
|
+
const uniqueTimeId =
|
|
25
|
+
Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
26
|
+
const timeStart = (message) => {
|
|
27
|
+
!rawRequest.quiet && console.time(`${message} ${uniqueTimeId}`);
|
|
28
|
+
};
|
|
29
|
+
const timeEnd = (message) => {
|
|
30
|
+
!rawRequest.quiet && console.timeEnd(`${message} ${uniqueTimeId}`);
|
|
31
|
+
};
|
|
24
32
|
const makeFetchHappen = makeFetchHappenOriginal.defaults({
|
|
25
33
|
cache: mode === "build" ? "no-cache" : "default",
|
|
26
34
|
});
|
|
@@ -92,8 +100,7 @@ export function lookupOrPerform(
|
|
|
92
100
|
}),
|
|
93
101
|
});
|
|
94
102
|
} else {
|
|
95
|
-
|
|
96
|
-
console.time(`BackendTask.Custom.run "${portName}"`);
|
|
103
|
+
timeStart(`BackendTask.Custom.run "${portName}"`);
|
|
97
104
|
let context = {
|
|
98
105
|
cwd: path.resolve(...rawRequest.dir),
|
|
99
106
|
quiet: rawRequest.quiet,
|
|
@@ -135,8 +142,7 @@ export function lookupOrPerform(
|
|
|
135
142
|
});
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
|
-
|
|
139
|
-
console.timeEnd(`BackendTask.Custom.run "${portName}"`);
|
|
145
|
+
timeEnd(`BackendTask.Custom.run "${portName}"`);
|
|
140
146
|
}
|
|
141
147
|
} catch (error) {
|
|
142
148
|
console.trace(error);
|
|
@@ -147,7 +153,7 @@ export function lookupOrPerform(
|
|
|
147
153
|
}
|
|
148
154
|
} else {
|
|
149
155
|
try {
|
|
150
|
-
|
|
156
|
+
timeStart(`fetch ${request.url}`);
|
|
151
157
|
const response = await safeFetch(makeFetchHappen, request.url, {
|
|
152
158
|
method: request.method,
|
|
153
159
|
body: request.body,
|
|
@@ -158,7 +164,7 @@ export function lookupOrPerform(
|
|
|
158
164
|
...rawRequest.cacheOptions,
|
|
159
165
|
});
|
|
160
166
|
|
|
161
|
-
|
|
167
|
+
timeEnd(`fetch ${request.url}`);
|
|
162
168
|
const expectString = request.headers["elm-pages-internal"];
|
|
163
169
|
|
|
164
170
|
let body;
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
import * as readline from
|
|
3
|
+
import * as readline from "readline";
|
|
4
4
|
import * as chalk from "kleur/colors";
|
|
5
|
-
import cliCursor from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import cliCursor from "cli-cursor";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
purgeSpinnerOptions,
|
|
9
|
+
purgeSpinnersOptions,
|
|
10
|
+
colorOptions,
|
|
11
|
+
breakText,
|
|
12
|
+
getLinesLength,
|
|
13
|
+
terminalSupportsUnicode,
|
|
14
|
+
} from "./utils.js";
|
|
15
|
+
import { dots, dashes, writeStream, cleanStream } from "./utils.js";
|
|
10
16
|
|
|
11
17
|
export class Spinnies {
|
|
12
18
|
constructor(options = {}) {
|
|
13
19
|
options = purgeSpinnersOptions(options);
|
|
14
20
|
this.options = {
|
|
15
|
-
|
|
16
|
-
// spinnerColor: 'brightGreen',
|
|
17
|
-
spinnerColor:
|
|
18
|
-
succeedColor:
|
|
19
|
-
failColor:
|
|
21
|
+
// TODO kleur doesn't support brightGreen, only nested function or chained syntax
|
|
22
|
+
// spinnerColor: 'brightGreen',
|
|
23
|
+
spinnerColor: "green",
|
|
24
|
+
succeedColor: "green",
|
|
25
|
+
failColor: "red",
|
|
20
26
|
spinner: terminalSupportsUnicode() ? dots : dashes,
|
|
21
27
|
disableSpins: false,
|
|
22
|
-
...options
|
|
28
|
+
...options,
|
|
23
29
|
};
|
|
24
30
|
this.spinners = {};
|
|
25
31
|
this.isCursorHidden = false;
|
|
@@ -27,7 +33,11 @@ export class Spinnies {
|
|
|
27
33
|
this.stream = process.stderr;
|
|
28
34
|
this.lineCount = 0;
|
|
29
35
|
this.currentFrameIndex = 0;
|
|
30
|
-
this.spin =
|
|
36
|
+
this.spin =
|
|
37
|
+
!this.options.disableSpins &&
|
|
38
|
+
!process.env.CI &&
|
|
39
|
+
process.stderr &&
|
|
40
|
+
process.stderr.isTTY;
|
|
31
41
|
this.bindSigint();
|
|
32
42
|
}
|
|
33
43
|
|
|
@@ -36,13 +46,14 @@ export class Spinnies {
|
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
add(name, options = {}) {
|
|
39
|
-
if (typeof name !==
|
|
49
|
+
if (typeof name !== "string")
|
|
50
|
+
throw Error("A spinner reference name must be specified");
|
|
40
51
|
if (!options.text) options.text = name;
|
|
41
52
|
const spinnerProperties = {
|
|
42
53
|
...colorOptions(this.options),
|
|
43
54
|
succeedPrefix: this.options.succeedPrefix,
|
|
44
55
|
failPrefix: this.options.failPrefix,
|
|
45
|
-
status:
|
|
56
|
+
status: "spinning",
|
|
46
57
|
...purgeSpinnerOptions(options),
|
|
47
58
|
};
|
|
48
59
|
|
|
@@ -61,37 +72,42 @@ export class Spinnies {
|
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
succeed(name, options = {}) {
|
|
64
|
-
this.setSpinnerProperties(name, options,
|
|
75
|
+
this.setSpinnerProperties(name, options, "succeed");
|
|
65
76
|
this.updateSpinnerState();
|
|
66
77
|
|
|
67
78
|
return this.spinners[name];
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
fail(name, options = {}) {
|
|
71
|
-
this.setSpinnerProperties(name, options,
|
|
82
|
+
this.setSpinnerProperties(name, options, "fail");
|
|
72
83
|
this.updateSpinnerState();
|
|
73
84
|
|
|
74
85
|
return this.spinners[name];
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
remove(name) {
|
|
78
|
-
if (typeof name !==
|
|
89
|
+
if (typeof name !== "string")
|
|
90
|
+
throw Error("A spinner reference name must be specified");
|
|
79
91
|
const spinner = this.spinners[name];
|
|
80
92
|
delete this.spinners[name];
|
|
81
93
|
|
|
82
94
|
return spinner;
|
|
83
95
|
}
|
|
84
96
|
|
|
85
|
-
stopAll(newStatus =
|
|
86
|
-
Object.keys(this.spinners).forEach(name => {
|
|
97
|
+
stopAll(newStatus = "stopped") {
|
|
98
|
+
Object.keys(this.spinners).forEach((name) => {
|
|
87
99
|
const { status: currentStatus } = this.spinners[name];
|
|
88
|
-
if (
|
|
89
|
-
|
|
100
|
+
if (
|
|
101
|
+
currentStatus !== "fail" &&
|
|
102
|
+
currentStatus !== "succeed" &&
|
|
103
|
+
currentStatus !== "non-spinnable"
|
|
104
|
+
) {
|
|
105
|
+
if (newStatus === "succeed" || newStatus === "fail") {
|
|
90
106
|
this.spinners[name].status = newStatus;
|
|
91
107
|
this.spinners[name].color = this.options[`${newStatus}Color`];
|
|
92
108
|
} else {
|
|
93
|
-
this.spinners[name].status =
|
|
94
|
-
this.spinners[name].color =
|
|
109
|
+
this.spinners[name].status = "stopped";
|
|
110
|
+
this.spinners[name].color = "grey";
|
|
95
111
|
}
|
|
96
112
|
}
|
|
97
113
|
});
|
|
@@ -101,14 +117,18 @@ export class Spinnies {
|
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
hasActiveSpinners() {
|
|
104
|
-
return !!Object.values(this.spinners).find(
|
|
120
|
+
return !!Object.values(this.spinners).find(
|
|
121
|
+
({ status }) => status === "spinning"
|
|
122
|
+
);
|
|
105
123
|
}
|
|
106
124
|
|
|
107
125
|
setSpinnerProperties(name, options, status) {
|
|
108
|
-
if (typeof name !==
|
|
109
|
-
|
|
126
|
+
if (typeof name !== "string")
|
|
127
|
+
throw Error("A spinner reference name must be specified");
|
|
128
|
+
if (!this.spinners[name])
|
|
129
|
+
throw Error(`No spinner initialized with name ${name}`);
|
|
110
130
|
options = purgeSpinnerOptions(options);
|
|
111
|
-
status = status ||
|
|
131
|
+
status = status || "spinning";
|
|
112
132
|
|
|
113
133
|
this.spinners[name] = { ...this.spinners[name], ...options, status };
|
|
114
134
|
}
|
|
@@ -129,29 +149,41 @@ export class Spinnies {
|
|
|
129
149
|
const { frames, interval } = this.options.spinner;
|
|
130
150
|
return setInterval(() => {
|
|
131
151
|
this.setStreamOutput(frames[this.currentFrameIndex]);
|
|
132
|
-
this.currentFrameIndex =
|
|
152
|
+
this.currentFrameIndex =
|
|
153
|
+
this.currentFrameIndex === frames.length - 1
|
|
154
|
+
? 0
|
|
155
|
+
: ++this.currentFrameIndex;
|
|
133
156
|
}, interval);
|
|
134
157
|
}
|
|
135
158
|
|
|
136
|
-
setStreamOutput(frame =
|
|
137
|
-
let output =
|
|
159
|
+
setStreamOutput(frame = "") {
|
|
160
|
+
let output = "";
|
|
138
161
|
const linesLength = [];
|
|
139
162
|
const hasActiveSpinners = this.hasActiveSpinners();
|
|
140
|
-
Object
|
|
141
|
-
|
|
142
|
-
|
|
163
|
+
Object.values(this.spinners).map(
|
|
164
|
+
({
|
|
165
|
+
text,
|
|
166
|
+
status,
|
|
167
|
+
color,
|
|
168
|
+
spinnerColor,
|
|
169
|
+
succeedColor,
|
|
170
|
+
failColor,
|
|
171
|
+
succeedPrefix,
|
|
172
|
+
failPrefix,
|
|
173
|
+
indent,
|
|
174
|
+
}) => {
|
|
143
175
|
let line;
|
|
144
176
|
let prefixLength = indent || 0;
|
|
145
|
-
if (status ===
|
|
177
|
+
if (status === "spinning") {
|
|
146
178
|
prefixLength += frame.length + 1;
|
|
147
179
|
text = breakText(text, prefixLength);
|
|
148
180
|
line = `${chalk[spinnerColor](frame)} ${color ? chalk[color](text) : text}`;
|
|
149
181
|
} else {
|
|
150
|
-
if (status ===
|
|
182
|
+
if (status === "succeed") {
|
|
151
183
|
prefixLength += succeedPrefix.length + 1;
|
|
152
184
|
if (hasActiveSpinners) text = breakText(text, prefixLength);
|
|
153
185
|
line = `${chalk.green(succeedPrefix)} ${chalk[succeedColor](text)}`;
|
|
154
|
-
} else if (status ===
|
|
186
|
+
} else if (status === "fail") {
|
|
155
187
|
prefixLength += failPrefix.length + 1;
|
|
156
188
|
if (hasActiveSpinners) text = breakText(text, prefixLength);
|
|
157
189
|
line = `${chalk.red(failPrefix)} ${chalk[failColor](text)}`;
|
|
@@ -162,16 +194,17 @@ export class Spinnies {
|
|
|
162
194
|
}
|
|
163
195
|
linesLength.push(...getLinesLength(text, prefixLength));
|
|
164
196
|
output += indent ? `${" ".repeat(indent)}${line}\n` : `${line}\n`;
|
|
165
|
-
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
166
199
|
|
|
167
|
-
if(!hasActiveSpinners) readline.clearScreenDown(this.stream);
|
|
200
|
+
if (!hasActiveSpinners) readline.clearScreenDown(this.stream);
|
|
168
201
|
writeStream(this.stream, output, linesLength);
|
|
169
202
|
if (hasActiveSpinners) cleanStream(this.stream, linesLength);
|
|
170
203
|
this.lineCount = linesLength.length;
|
|
171
204
|
}
|
|
172
205
|
|
|
173
206
|
setRawStreamOutput() {
|
|
174
|
-
Object.values(this.spinners).forEach(i => {
|
|
207
|
+
Object.values(this.spinners).forEach((i) => {
|
|
175
208
|
process.stderr.write(`- ${i.text}\n`);
|
|
176
209
|
});
|
|
177
210
|
}
|
|
@@ -190,8 +223,8 @@ export class Spinnies {
|
|
|
190
223
|
}
|
|
191
224
|
|
|
192
225
|
bindSigint(lines) {
|
|
193
|
-
process.removeAllListeners(
|
|
194
|
-
process.on(
|
|
226
|
+
process.removeAllListeners("SIGINT");
|
|
227
|
+
process.on("SIGINT", () => {
|
|
195
228
|
cliCursor.show();
|
|
196
229
|
readline.moveCursor(process.stderr, 0, this.lineCount);
|
|
197
230
|
process.exit(0);
|