This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
preview.ts
81 lines (64 loc) · 2.36 KB
/
preview.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import process from 'process'
import { spawn } from 'child_process'
import { fromString, toString, SequenceFunc, fromChildProcess, writeln } from 'split-shell-buffer'
import { styledText } from './.lib/data'
const executable = require.resolve('./.data/executable')
function execute () {
return spawn('node', [executable])
}
async function main () {
console.info('STYLED TEXT')
console.info(styledText)
console.info()
console.info('STYLED TEXT → SPLITTED → TO STRING')
console.info(await toString(fromString(styledText)))
console.info()
console.info('STYLED TEXT → SPLITTED AND INDENTED → TO STRING')
console.info(await toString(fromString(styledText).withIndent(4)))
console.info()
console.info('STYLED TEXT → SPLITTED AND NUMBERED → TO STRING')
console.info(await toString(fromString(styledText).withPrefix(getNumberingPrefix())))
console.info()
console.info('STYLED TEXT → SPLITTED → WRITELN')
await writeln(process.stdout, fromString(styledText))
console.info()
console.info('STYLED TEXT → SPLITTED AND INDENTED → WRITELN')
await writeln(process.stdout, fromString(styledText).withIndent(4))
console.info()
console.info('STYLED TEXT → SPLITTED AND NUMBERED → WRITELN')
await writeln(process.stdout, fromString(styledText).withPrefix(getNumberingPrefix()))
console.info()
console.info('SPAWNED')
require(executable)
console.info()
console.info('SPAWNED → SPLITTED AND INDENTED → TO STRING')
console.info(await toString(fromChildProcess(execute()).withIndent(4)))
console.info()
console.info('SPAWNED → SPLITTED AND NUMBERED → TO STRING')
console.info(await toString(fromChildProcess(execute()).withPrefix(getNumberingPrefix())))
console.info()
console.info('SPAWNED → SPLITTED AND INDENTED → WRITELN')
await writeln(process.stdout, fromChildProcess(execute()).withIndent(4))
console.info()
console.info('SPAWNED → SPLITTED AND NUMBERED → WRITELN')
await writeln(process.stdout, fromChildProcess(execute()).withPrefix(getNumberingPrefix()))
console.info()
}
function getNumberingPrefix (): SequenceFunc {
let index = 0
return () => {
index += 1
return Buffer.from(`${index}. `)
}
}
enum ExitStatus {
Success = 0,
Failure = 1
}
main().then(
() => process.exit(ExitStatus.Success),
error => {
console.error(error)
process.exit(ExitStatus.Failure)
}
)