spawn-term 0.1.24 → 0.1.26
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/dist/cjs/components/App.cjs +1 -1
- package/dist/cjs/components/App.cjs.map +1 -1
- package/dist/cjs/components/ChildProcess.cjs +71 -46
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/lib/{addLines.cjs → addData.cjs} +2 -13
- package/dist/cjs/lib/addData.cjs.map +1 -0
- package/dist/cjs/types.cjs +6 -6
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/cjs/worker.cjs +16 -18
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/App.mjs +1 -1
- package/dist/esm/components/App.mjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +56 -37
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/lib/addData.mjs +10 -0
- package/dist/esm/lib/addData.mjs.map +1 -0
- package/dist/esm/types.mjs +4 -4
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/worker.mjs +17 -15
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/components/ChildProcess.d.ts +5 -4
- package/dist/types/types.d.ts +5 -5
- package/package.json +1 -1
- package/dist/cjs/lib/addLines.cjs.map +0 -1
- package/dist/esm/lib/addLines.mjs +0 -21
- package/dist/esm/lib/addLines.mjs.map +0 -1
- /package/dist/types/lib/{addLines.d.ts → addData.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box } from '../ink.mjs';\nimport type { AppState, ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport default function App() {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box } from '../ink.mjs';\nimport type { AppState, ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport default function App() {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["App","store","useContext","StoreContext","appState","useStore","Box","flexDirection","processes","map","item","ChildProcess","key","id"],"mappings":";;;;+BAOA;;;eAAwBA;;;6DAPU;uBACT;4DACA;mBACL;mEAEK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEV,SAASA;IACtB,IAAMC,QAAQC,IAAAA,iBAAU,EAACC,cAAY;IACrC,IAAMC,WAAWC,IAAAA,iBAAQ,EAACJ;IAE1B,qBACE,6BAACK,QAAG;QAACC,eAAc;OAChBH,SAASI,SAAS,CAACC,GAAG,CAAC,SAACC;6BACvB,6BAACC,qBAAY;YAACC,KAAKF,KAAKG,EAAE;YAAEH,MAAMA;;;AAI1C"}
|
|
@@ -5,12 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "default", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
-
var _zustand = require("zustand");
|
|
13
|
-
var _Store = /*#__PURE__*/ _interop_require_default(require("../contexts/Store.cjs"));
|
|
14
12
|
var _ink = require("../ink.cjs");
|
|
15
13
|
var _ansiRegex = /*#__PURE__*/ _interop_require_default(require("../lib/ansiRegex.cjs"));
|
|
16
14
|
var _figures = /*#__PURE__*/ _interop_require_default(require("../lib/figures.cjs"));
|
|
@@ -62,7 +60,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
62
60
|
}
|
|
63
61
|
return newObj;
|
|
64
62
|
}
|
|
65
|
-
var ansiRegex = (0, _ansiRegex.default)();
|
|
66
63
|
// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2
|
|
67
64
|
var spinner = {
|
|
68
65
|
interval: 80,
|
|
@@ -88,25 +85,26 @@ var ICONS = {
|
|
|
88
85
|
}, _figures.default.tick),
|
|
89
86
|
running: /*#__PURE__*/ _react.default.createElement(_Spinner.default, spinner)
|
|
90
87
|
};
|
|
91
|
-
function Header(param) {
|
|
92
|
-
var
|
|
93
|
-
var group = item.group, title = item.title, state = item.state;
|
|
88
|
+
var Header = /*#__PURE__*/ (0, _react.memo)(function Header(param) {
|
|
89
|
+
var group = param.group, title = param.title, state = param.state;
|
|
94
90
|
var icon = ICONS[state];
|
|
95
91
|
return /*#__PURE__*/ _react.default.createElement(_ink.Box, null, /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
96
92
|
marginRight: 1
|
|
97
93
|
}, icon), group && /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
98
94
|
bold: true
|
|
99
95
|
}, "".concat(group).concat(_figures.default.pointer, " ")), /*#__PURE__*/ _react.default.createElement(_ink.Text, null, title));
|
|
100
|
-
}
|
|
101
|
-
|
|
96
|
+
}, function(a, b) {
|
|
97
|
+
return a.group === b.group && a.title === b.title && a.state === b.state;
|
|
98
|
+
});
|
|
99
|
+
var Output = /*#__PURE__*/ (0, _react.memo)(function Output(param) {
|
|
102
100
|
var output = param.output;
|
|
103
101
|
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
104
102
|
marginLeft: 2
|
|
105
103
|
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
106
104
|
color: "gray"
|
|
107
105
|
}, output.text));
|
|
108
|
-
}
|
|
109
|
-
function Lines(param) {
|
|
106
|
+
});
|
|
107
|
+
var Lines = /*#__PURE__*/ (0, _react.memo)(function Lines(param) {
|
|
110
108
|
var lines = param.lines;
|
|
111
109
|
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
112
110
|
flexDirection: "column",
|
|
@@ -115,51 +113,78 @@ function Lines(param) {
|
|
|
115
113
|
return(// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
|
|
116
114
|
/*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
117
115
|
key: index,
|
|
118
|
-
flexDirection: "column"
|
|
119
|
-
height: 1
|
|
116
|
+
flexDirection: "column"
|
|
120
117
|
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
121
|
-
color: line.type === _types.
|
|
118
|
+
color: line.type === _types.DataType.stderr ? 'red' : 'black'
|
|
122
119
|
}, line.text)));
|
|
123
120
|
}));
|
|
124
|
-
}
|
|
125
|
-
function
|
|
126
|
-
var
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
});
|
|
122
|
+
var Expanded = /*#__PURE__*/ (0, _react.memo)(function Expanded(param) {
|
|
123
|
+
var item = param.item;
|
|
124
|
+
var data = item.data;
|
|
125
|
+
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
126
|
+
flexDirection: "column"
|
|
127
|
+
}, /*#__PURE__*/ _react.default.createElement(Header, {
|
|
128
|
+
group: item.group,
|
|
129
|
+
title: item.title,
|
|
130
|
+
state: item.state
|
|
131
|
+
}), /*#__PURE__*/ _react.default.createElement(Lines, {
|
|
132
|
+
lines: data
|
|
133
|
+
}));
|
|
134
|
+
});
|
|
135
|
+
var linesRegex = /\r\n|\n/g;
|
|
136
|
+
var ansiRegex = (0, _ansiRegex.default)();
|
|
137
|
+
var Contracted = /*#__PURE__*/ (0, _react.memo)(function Contracted(param) {
|
|
138
|
+
var item = param.item;
|
|
139
|
+
var state = item.state, data = item.data;
|
|
140
|
+
var lines = (0, _react.useMemo)(function() {
|
|
141
|
+
var lines = [];
|
|
142
|
+
data.forEach(function(x) {
|
|
143
|
+
x.text.split(linesRegex).forEach(function(text) {
|
|
144
|
+
return lines.push({
|
|
145
|
+
type: x.type,
|
|
146
|
+
text: text.replace(ansiRegex, '')
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
return lines;
|
|
151
|
+
}, [
|
|
152
|
+
data
|
|
153
|
+
]);
|
|
142
154
|
// remove ansi codes when displaying single lines
|
|
143
|
-
var
|
|
144
|
-
return {
|
|
145
|
-
type
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
+
var errors = (0, _react.useMemo)(function() {
|
|
156
|
+
return lines.filter(function(line) {
|
|
157
|
+
return line.type === _types.DataType.stderr;
|
|
158
|
+
});
|
|
159
|
+
}, [
|
|
160
|
+
lines
|
|
161
|
+
]);
|
|
162
|
+
var output = (0, _react.useMemo)(function() {
|
|
163
|
+
return lines.filter(function(line) {
|
|
164
|
+
return line.text.length > 0;
|
|
165
|
+
}).pop();
|
|
166
|
+
}, [
|
|
167
|
+
lines
|
|
168
|
+
]);
|
|
155
169
|
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
156
170
|
flexDirection: "column"
|
|
157
171
|
}, /*#__PURE__*/ _react.default.createElement(Header, {
|
|
158
|
-
|
|
172
|
+
group: item.group,
|
|
173
|
+
title: item.title,
|
|
174
|
+
state: item.state
|
|
159
175
|
}), state === 'running' && output && /*#__PURE__*/ _react.default.createElement(Output, {
|
|
160
176
|
output: output
|
|
161
177
|
}), errors.length > 0 && /*#__PURE__*/ _react.default.createElement(Lines, {
|
|
162
178
|
lines: errors
|
|
163
179
|
}));
|
|
164
|
-
}
|
|
180
|
+
});
|
|
181
|
+
var _default = /*#__PURE__*/ (0, _react.memo)(function ChildProcess(param) {
|
|
182
|
+
var item = param.item;
|
|
183
|
+
var expanded = item.expanded;
|
|
184
|
+
return expanded ? /*#__PURE__*/ _react.default.createElement(Expanded, {
|
|
185
|
+
item: item
|
|
186
|
+
}) : /*#__PURE__*/ _react.default.createElement(Contracted, {
|
|
187
|
+
item: item
|
|
188
|
+
});
|
|
189
|
+
});
|
|
165
190
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { memo, useMemo } from 'react';\nimport { Box, Text } from '../ink.mjs';\nimport _ansiRegex from '../lib/ansiRegex';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { ChildProcess as ChildProcessT, Data, State } from '../types';\nimport { DataType } from '../types';\n\ntype ItemProps = {\n item: ChildProcessT;\n};\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\ntype HeaderProps = {\n group?: string;\n title: string;\n state: State;\n};\n\nconst Header = memo(\n function Header({ group, title, state }: HeaderProps) {\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n },\n (a, b) => a.group === b.group && a.title === b.title && a.state === b.state\n);\n\ntype OutputProps = {\n output: Data;\n};\n\nconst Output = memo(function Output({ output }: OutputProps) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{output.text}</Text>\n </Box>\n );\n});\n\ntype LinesProps = {\n lines: Data[];\n};\n\nconst Lines = memo(function Lines({ lines }: LinesProps) {\n return (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\">\n <Text color={line.type === DataType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\n});\n\nconst Expanded = memo(function Expanded({ item }: ItemProps) {\n const { data } = item;\n\n return (\n <Box flexDirection=\"column\">\n <Header group={item.group} title={item.title} state={item.state} />\n <Lines lines={data} />\n </Box>\n );\n});\n\nconst linesRegex = /\\r\\n|\\n/g;\nconst ansiRegex = _ansiRegex();\n\nconst Contracted = memo(function Contracted({ item }: ItemProps) {\n const { state, data } = item;\n\n const lines = useMemo(() => {\n const lines = [];\n data.forEach((x) => {\n x.text.split(linesRegex).forEach((text) => lines.push({ type: x.type, text: text.replace(ansiRegex, '') }));\n });\n return lines;\n }, [data]);\n\n // remove ansi codes when displaying single lines\n const errors = useMemo(() => lines.filter((line) => line.type === DataType.stderr), [lines]);\n const output = useMemo(() => lines.filter((line) => line.text.length > 0).pop(), [lines]);\n\n return (\n <Box flexDirection=\"column\">\n <Header group={item.group} title={item.title} state={item.state} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\n </Box>\n );\n});\n\nexport default memo(function ChildProcess({ item }: ItemProps) {\n const { expanded } = item;\n return expanded ? <Expanded item={item} /> : <Contracted item={item} />;\n});\n"],"names":["spinner","interval","frames","ICONS","error","Text","color","figures","cross","success","tick","running","Spinner","Header","memo","group","title","state","icon","Box","marginRight","bold","pointer","a","b","Output","output","marginLeft","text","Lines","lines","flexDirection","map","line","index","key","type","DataType","stderr","Expanded","item","data","linesRegex","ansiRegex","_ansiRegex","Contracted","useMemo","forEach","x","split","push","replace","errors","filter","length","pop","ChildProcess","expanded"],"mappings":";;;;+BAiHA;;;eAAA;;;6DAjHqC;mBACX;gEACH;8DACH;8DACA;qBAGK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMzB,oHAAoH;AACpH,IAAMA,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,IAAMC,QAAQ;IACZC,qBAAO,6BAACC,SAAI;QAACC,OAAM;OAAOC,gBAAO,CAACC,KAAK;IACvCC,uBAAS,6BAACJ,SAAI;QAACC,OAAM;OAASC,gBAAO,CAACG,IAAI;IAC1CC,uBAAS,6BAACC,gBAAO,EAAKZ;AACxB;AAQA,IAAMa,uBAASC,IAAAA,WAAI,EACjB,SAASD,OAAO,KAAoC;QAAlCE,QAAF,MAAEA,OAAOC,QAAT,MAASA,OAAOC,QAAhB,MAAgBA;IAC9B,IAAMC,OAAOf,KAAK,CAACc,MAAM;IAEzB,qBACE,6BAACE,QAAG,sBACF,6BAACA,QAAG;QAACC,aAAa;OAAIF,OACrBH,uBAAS,6BAACV,SAAI;QAACgB,MAAAA;OAAM,AAAC,GAAUd,OAARQ,OAAwB,OAAhBR,gBAAO,CAACe,OAAO,EAAC,qBACjD,6BAACjB,SAAI,QAAEW;AAGb,GACA,SAACO,GAAGC;WAAMD,EAAER,KAAK,KAAKS,EAAET,KAAK,IAAIQ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YACZA,EAAEpB,IAAI,CAACqB,KAAK,CAACP,YAAYK,OAAO,CAAC,SAACnB;uBAASE,MAAMoB,IAAI,CAAC;oBAAEd,MAAMY,EAAEZ,IAAI;oBAAER,MAAMA,KAAKuB,OAAO,CAACR,WAAW;gBAAI;;QAC1G;QACA,OAAOb;IACT,GAAG;QAACW;KAAK;IAET,iDAAiD;IACjD,IAAMW,SAASN,IAAAA,cAAO,EAAC;eAAMhB,MAAMuB,MAAM,CAAC,SAACpB;mBAASA,KAAKG,IAAI,KAAKC,eAAQ,CAACC,MAAM;;OAAG;QAACR;KAAM;IAC3F,IAAMJ,SAASoB,IAAAA,cAAO,EAAC;eAAMhB,MAAMuB,MAAM,CAAC,SAACpB;mBAASA,KAAKL,IAAI,CAAC0B,MAAM,GAAG;WAAGC,GAAG;OAAI;QAACzB;KAAM;IAExF,qBACE,6BAACX,QAAG;QAACY,eAAc;qBACjB,6BAAClB;QAAOE,OAAOyB,KAAKzB,KAAK;QAAEC,OAAOwB,KAAKxB,KAAK;QAAEC,OAAOuB,KAAKvB,KAAK;QAC9DA,UAAU,aAAaS,wBAAU,6BAACD;QAAOC,QAAQA;QACjD0B,OAAOE,MAAM,GAAG,mBAAK,6BAACzB;QAAMC,OAAOsB;;AAG1C;IAEA,yBAAetC,IAAAA,WAAI,EAAC,SAAS0C,aAAa,KAAmB;QAAnB,AAAEhB,OAAF,MAAEA;IAC1C,IAAM,AAAEiB,WAAajB,KAAbiB;IACR,OAAOA,yBAAW,6BAAClB;QAASC,MAAMA;uBAAW,6BAACK;QAAWL,MAAMA;;AACjE"}
|
|
@@ -9,24 +9,13 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _readablestream = require("readable-stream");
|
|
12
|
-
var regEx = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g;
|
|
13
12
|
function addLines(fn) {
|
|
14
|
-
var last = '';
|
|
15
13
|
var stream = new _readablestream.Writable({
|
|
16
|
-
write: function write(
|
|
17
|
-
|
|
18
|
-
var lines = more.split(regEx);
|
|
19
|
-
last = lines.pop();
|
|
20
|
-
if (lines.length) fn(lines);
|
|
14
|
+
write: function write(data, _enc, callback) {
|
|
15
|
+
fn(data);
|
|
21
16
|
callback();
|
|
22
17
|
}
|
|
23
18
|
});
|
|
24
|
-
stream.on('finish', function() {
|
|
25
|
-
if (last.length) fn([
|
|
26
|
-
last
|
|
27
|
-
]);
|
|
28
|
-
last = '';
|
|
29
|
-
});
|
|
30
19
|
return stream;
|
|
31
20
|
}
|
|
32
21
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addData.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nexport default function addLines(fn) {\n const stream = new Writable({\n write(data, _enc, callback) {\n fn(data);\n callback();\n },\n });\n return stream;\n}\n"],"names":["addLines","fn","stream","Writable","write","data","_enc","callback"],"mappings":";;;;+BAEA;;;eAAwBA;;;8BAFC;AAEV,SAASA,SAASC,EAAE;IACjC,IAAMC,SAAS,IAAIC,wBAAQ,CAAC;QAC1BC,OAAAA,SAAAA,MAAMC,IAAI,EAAEC,IAAI,EAAEC,QAAQ;YACxBN,GAAGI;YACHE;QACF;IACF;IACA,OAAOL;AACT"}
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "DataType", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function() {
|
|
9
|
-
return
|
|
9
|
+
return DataType;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
12
|
+
var DataType = /*#__PURE__*/ function(DataType) {
|
|
13
|
+
DataType[DataType["stdout"] = 1] = "stdout";
|
|
14
|
+
DataType[DataType["stderr"] = 2] = "stderr";
|
|
15
|
+
return DataType;
|
|
16
16
|
}({});
|
|
17
17
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
package/dist/cjs/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: string;\n};\n\nexport enum
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: string;\n};\n\nexport enum DataType {\n stdout = 1,\n stderr = 2,\n}\nexport type Data = {\n type: DataType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n data: Data[];\n expanded?: string;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n"],"names":["DataType"],"mappings":"AAAA,aAAa;;;;;+BAQDA;;;eAAAA;;;AAAL,IAAA,AAAKA,kCAAAA;;;WAAAA"}
|
package/dist/cjs/worker.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var _liluuid = /*#__PURE__*/ _interop_require_default(require("lil-uuid"));
|
|
|
14
14
|
var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
15
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
16
16
|
var _createApp = /*#__PURE__*/ _interop_require_default(require("./createApp.cjs"));
|
|
17
|
-
var
|
|
17
|
+
var _addData = /*#__PURE__*/ _interop_require_default(require("./lib/addData.cjs"));
|
|
18
18
|
var _concatWritable = /*#__PURE__*/ _interop_require_default(require("./lib/concatWritable.cjs"));
|
|
19
19
|
var _formatArguments = /*#__PURE__*/ _interop_require_default(require("./lib/formatArguments.cjs"));
|
|
20
20
|
var _types = require("./types.cjs");
|
|
@@ -158,7 +158,7 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
158
158
|
command
|
|
159
159
|
].concat((0, _formatArguments.default)(args)).join(' '),
|
|
160
160
|
state: 'running',
|
|
161
|
-
|
|
161
|
+
data: []
|
|
162
162
|
}, options));
|
|
163
163
|
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
164
164
|
var outputs = {
|
|
@@ -167,18 +167,17 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
167
167
|
};
|
|
168
168
|
var queue = new _queuecb.default();
|
|
169
169
|
if (cp.stdout) {
|
|
170
|
-
outputs.stdout = (0,
|
|
170
|
+
outputs.stdout = (0, _addData.default)(function(data) {
|
|
171
171
|
var item = store.getState().processes.find(function(x) {
|
|
172
172
|
return x.id === id;
|
|
173
173
|
});
|
|
174
|
-
var lines = item.lines.concat(texts.map(function(text) {
|
|
175
|
-
return {
|
|
176
|
-
type: _types.LineType.stdout,
|
|
177
|
-
text: text
|
|
178
|
-
};
|
|
179
|
-
}));
|
|
180
174
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
181
|
-
|
|
175
|
+
data: item.data.concat([
|
|
176
|
+
{
|
|
177
|
+
type: _types.DataType.stdout,
|
|
178
|
+
text: data.toString('utf8')
|
|
179
|
+
}
|
|
180
|
+
])
|
|
182
181
|
}));
|
|
183
182
|
});
|
|
184
183
|
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
@@ -189,18 +188,17 @@ function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
|
189
188
|
]));
|
|
190
189
|
}
|
|
191
190
|
if (cp.stderr) {
|
|
192
|
-
outputs.stderr = (0,
|
|
191
|
+
outputs.stderr = (0, _addData.default)(function(data) {
|
|
193
192
|
var item = store.getState().processes.find(function(x) {
|
|
194
193
|
return x.id === id;
|
|
195
194
|
});
|
|
196
|
-
var lines = item.lines.concat(texts.map(function(text) {
|
|
197
|
-
return {
|
|
198
|
-
type: _types.LineType.stderr,
|
|
199
|
-
text: text
|
|
200
|
-
};
|
|
201
|
-
}));
|
|
202
195
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
203
|
-
|
|
196
|
+
data: item.data.concat([
|
|
197
|
+
{
|
|
198
|
+
type: _types.DataType.stderr,
|
|
199
|
+
text: data.toString('utf8')
|
|
200
|
+
}
|
|
201
|
+
])
|
|
204
202
|
}));
|
|
205
203
|
});
|
|
206
204
|
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
package/dist/cjs/worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addData from './lib/addData';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { DataType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', data: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addData((data) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, data: item.data.concat([{ type: DataType.stdout, text: data.toString('utf8') }]) });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addData((data) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, data: item.data.concat([{ type: DataType.stderr, text: data.toString('utf8') }]) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","uuid","getState","addProcess","title","concat","formatArguments","join","state","data","cp","crossSpawn","outputs","stdout","stderr","queue","Queue","addData","item","processes","find","x","updateProcess","type","DataType","text","toString","defer","oo","bind","pipe","spawn","worker","await","err","res","output","setTimeout","release","concatWritable"],"mappings":"AAAA,aAAa;;;;;+BAgBb;;;eAAwBA;;;oEAf4B;8DACnC;4DACF;8DACG;gEAEI;8DACF;qEACO;sEACC;qBAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,WAAWC,IAAAA,kBAAS;AAEX,SAASF,cAAcG,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,IAAQC,WAAkCH,aAAlCG,UAAUC,QAAwBJ,aAAxBI,OAAUC,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,SAACC;YACf,IAAMC,KAAKC,IAAAA,gBAAI;YACfF,MAAMG,QAAQ,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AQ,CAAC/B,YAAY;YACtD;YACAoB,MAAMY,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMnB,GAAGG,MAAM,CAACiB,IAAI,CAAClB,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIH,GAAGI,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAGyB,IAAAA,uBAAc,EAAC,SAACH;gBAC/BxB,QAAQE,MAAM,CAACsB,MAAM,GAAGA,OAAOV,QAAQ,CAAC/B,YAAY;YACtD;YACAoB,MAAMY,KAAK,CAACC,cAAE,CAACC,IAAI,CAAC,MAAMnB,GAAGI,MAAM,CAACgB,IAAI,CAAClB,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMY,KAAK,CAACI,qBAAK,CAACC,MAAM,CAACH,IAAI,CAAC,MAAMnB,IAAI,wCAAKb;YAAWF,UAAUA,YAAY;;QAC9EoB,MAAMkB,KAAK,CAAC,SAACC;YACX,IAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAItB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACuB,MAAM,GAAG;YACtDD,IAAIrB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACsB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAItB,MAAM;gBAAEsB,IAAIrB,MAAM;gBAAE;aAAK;YAC3CoB,MAAMxC,SAASwC,OAAOxC,SAAS,MAAMyC;QACvC;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box } from '../ink.mjs';\nimport type { AppState, ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport default function App() {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box } from '../ink.mjs';\nimport type { AppState, ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport default function App() {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n\n return (\n <Box flexDirection=\"column\">\n {appState.processes.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} item={item} />\n ))}\n </Box>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","ChildProcess","App","store","appState","flexDirection","processes","map","item","key","id"],"mappings":"AAAA,OAAOA,SAASC,UAAU,QAAQ,QAAQ;AAC1C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,oBAAoB;AAC7C,SAASC,GAAG,QAAQ,aAAa;AAEjC,OAAOC,kBAAkB,iBAAiB;AAE1C,eAAe,SAASC;IACtB,MAAMC,QAAQN,WAAWE;IACzB,MAAMK,WAAWN,SAASK;IAE1B,qBACE,oBAACH;QAAIK,eAAc;OAChBD,SAASE,SAAS,CAACC,GAAG,CAAC,CAACC,qBACvB,oBAACP;YAAaQ,KAAKD,KAAKE,EAAE;YAAEF,MAAMA;;AAI1C"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { useStore } from 'zustand';
|
|
3
|
-
import StoreContext from '../contexts/Store.mjs';
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
4
2
|
import { Box, Text } from '../ink.mjs';
|
|
5
3
|
import _ansiRegex from '../lib/ansiRegex.mjs';
|
|
6
4
|
import figures from '../lib/figures.mjs';
|
|
7
5
|
import Spinner from './Spinner.mjs';
|
|
8
|
-
import {
|
|
9
|
-
const ansiRegex = _ansiRegex();
|
|
6
|
+
import { DataType } from '../types.mjs';
|
|
10
7
|
// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2
|
|
11
8
|
const spinner = {
|
|
12
9
|
interval: 80,
|
|
@@ -32,63 +29,85 @@ const ICONS = {
|
|
|
32
29
|
}, figures.tick),
|
|
33
30
|
running: /*#__PURE__*/ React.createElement(Spinner, spinner)
|
|
34
31
|
};
|
|
35
|
-
function Header({
|
|
36
|
-
const { group, title, state } = item;
|
|
32
|
+
const Header = /*#__PURE__*/ memo(function Header({ group, title, state }) {
|
|
37
33
|
const icon = ICONS[state];
|
|
38
34
|
return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Box, {
|
|
39
35
|
marginRight: 1
|
|
40
36
|
}, icon), group && /*#__PURE__*/ React.createElement(Text, {
|
|
41
37
|
bold: true
|
|
42
38
|
}, `${group}${figures.pointer} `), /*#__PURE__*/ React.createElement(Text, null, title));
|
|
43
|
-
}
|
|
44
|
-
function Output({ output }) {
|
|
39
|
+
}, (a, b)=>a.group === b.group && a.title === b.title && a.state === b.state);
|
|
40
|
+
const Output = /*#__PURE__*/ memo(function Output({ output }) {
|
|
45
41
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
46
42
|
marginLeft: 2
|
|
47
43
|
}, /*#__PURE__*/ React.createElement(Text, {
|
|
48
44
|
color: "gray"
|
|
49
45
|
}, output.text));
|
|
50
|
-
}
|
|
51
|
-
function Lines({ lines }) {
|
|
46
|
+
});
|
|
47
|
+
const Lines = /*#__PURE__*/ memo(function Lines({ lines }) {
|
|
52
48
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
53
49
|
flexDirection: "column",
|
|
54
50
|
marginLeft: 2
|
|
55
51
|
}, lines.map((line, index)=>// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
|
|
56
52
|
/*#__PURE__*/ React.createElement(Box, {
|
|
57
53
|
key: index,
|
|
58
|
-
flexDirection: "column"
|
|
59
|
-
height: 1
|
|
54
|
+
flexDirection: "column"
|
|
60
55
|
}, /*#__PURE__*/ React.createElement(Text, {
|
|
61
|
-
color: line.type ===
|
|
56
|
+
color: line.type === DataType.stderr ? 'red' : 'black'
|
|
62
57
|
}, line.text))));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
});
|
|
59
|
+
const Expanded = /*#__PURE__*/ memo(function Expanded({ item }) {
|
|
60
|
+
const { data } = item;
|
|
61
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
62
|
+
flexDirection: "column"
|
|
63
|
+
}, /*#__PURE__*/ React.createElement(Header, {
|
|
64
|
+
group: item.group,
|
|
65
|
+
title: item.title,
|
|
66
|
+
state: item.state
|
|
67
|
+
}), /*#__PURE__*/ React.createElement(Lines, {
|
|
68
|
+
lines: data
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
const linesRegex = /\r\n|\n/g;
|
|
72
|
+
const ansiRegex = _ansiRegex();
|
|
73
|
+
const Contracted = /*#__PURE__*/ memo(function Contracted({ item }) {
|
|
74
|
+
const { state, data } = item;
|
|
75
|
+
const lines = useMemo(()=>{
|
|
76
|
+
const lines = [];
|
|
77
|
+
data.forEach((x)=>{
|
|
78
|
+
x.text.split(linesRegex).forEach((text)=>lines.push({
|
|
79
|
+
type: x.type,
|
|
80
|
+
text: text.replace(ansiRegex, '')
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
83
|
+
return lines;
|
|
84
|
+
}, [
|
|
85
|
+
data
|
|
86
|
+
]);
|
|
78
87
|
// remove ansi codes when displaying single lines
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
const errors = useMemo(()=>lines.filter((line)=>line.type === DataType.stderr), [
|
|
89
|
+
lines
|
|
90
|
+
]);
|
|
91
|
+
const output = useMemo(()=>lines.filter((line)=>line.text.length > 0).pop(), [
|
|
92
|
+
lines
|
|
93
|
+
]);
|
|
85
94
|
return /*#__PURE__*/ React.createElement(Box, {
|
|
86
95
|
flexDirection: "column"
|
|
87
96
|
}, /*#__PURE__*/ React.createElement(Header, {
|
|
88
|
-
|
|
97
|
+
group: item.group,
|
|
98
|
+
title: item.title,
|
|
99
|
+
state: item.state
|
|
89
100
|
}), state === 'running' && output && /*#__PURE__*/ React.createElement(Output, {
|
|
90
101
|
output: output
|
|
91
102
|
}), errors.length > 0 && /*#__PURE__*/ React.createElement(Lines, {
|
|
92
103
|
lines: errors
|
|
93
104
|
}));
|
|
94
|
-
}
|
|
105
|
+
});
|
|
106
|
+
export default /*#__PURE__*/ memo(function ChildProcess({ item }) {
|
|
107
|
+
const { expanded } = item;
|
|
108
|
+
return expanded ? /*#__PURE__*/ React.createElement(Expanded, {
|
|
109
|
+
item: item
|
|
110
|
+
}) : /*#__PURE__*/ React.createElement(Contracted, {
|
|
111
|
+
item: item
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { memo, useMemo } from 'react';\nimport { Box, Text } from '../ink.mjs';\nimport _ansiRegex from '../lib/ansiRegex';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { ChildProcess as ChildProcessT, Data, State } from '../types';\nimport { DataType } from '../types';\n\ntype ItemProps = {\n item: ChildProcessT;\n};\n\n// From: https://github.com/sindresorhus/cli-spinners/blob/00de8fbeee16fa49502fa4f687449f70f2c8ca2c/spinners.json#L2\nconst spinner = {\n interval: 80,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n};\n\nconst ICONS = {\n error: <Text color=\"red\">{figures.cross}</Text>,\n success: <Text color=\"green\">{figures.tick}</Text>,\n running: <Spinner {...spinner} />,\n};\n\ntype HeaderProps = {\n group?: string;\n title: string;\n state: State;\n};\n\nconst Header = memo(\n function Header({ group, title, state }: HeaderProps) {\n const icon = ICONS[state];\n\n return (\n <Box>\n <Box marginRight={1}>{icon}</Box>\n {group && <Text bold>{`${group}${figures.pointer} `}</Text>}\n <Text>{title}</Text>\n </Box>\n );\n },\n (a, b) => a.group === b.group && a.title === b.title && a.state === b.state\n);\n\ntype OutputProps = {\n output: Data;\n};\n\nconst Output = memo(function Output({ output }: OutputProps) {\n return (\n <Box marginLeft={2}>\n <Text color=\"gray\">{output.text}</Text>\n </Box>\n );\n});\n\ntype LinesProps = {\n lines: Data[];\n};\n\nconst Lines = memo(function Lines({ lines }: LinesProps) {\n return (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\">\n <Text color={line.type === DataType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n );\n});\n\nconst Expanded = memo(function Expanded({ item }: ItemProps) {\n const { data } = item;\n\n return (\n <Box flexDirection=\"column\">\n <Header group={item.group} title={item.title} state={item.state} />\n <Lines lines={data} />\n </Box>\n );\n});\n\nconst linesRegex = /\\r\\n|\\n/g;\nconst ansiRegex = _ansiRegex();\n\nconst Contracted = memo(function Contracted({ item }: ItemProps) {\n const { state, data } = item;\n\n const lines = useMemo(() => {\n const lines = [];\n data.forEach((x) => {\n x.text.split(linesRegex).forEach((text) => lines.push({ type: x.type, text: text.replace(ansiRegex, '') }));\n });\n return lines;\n }, [data]);\n\n // remove ansi codes when displaying single lines\n const errors = useMemo(() => lines.filter((line) => line.type === DataType.stderr), [lines]);\n const output = useMemo(() => lines.filter((line) => line.text.length > 0).pop(), [lines]);\n\n return (\n <Box flexDirection=\"column\">\n <Header group={item.group} title={item.title} state={item.state} />\n {state === 'running' && output && <Output output={output} />}\n {errors.length > 0 && <Lines lines={errors} />}\n </Box>\n );\n});\n\nexport default memo(function ChildProcess({ item }: ItemProps) {\n const { expanded } = item;\n return expanded ? <Expanded item={item} /> : <Contracted item={item} />;\n});\n"],"names":["React","memo","useMemo","Box","Text","_ansiRegex","figures","Spinner","DataType","spinner","interval","frames","ICONS","error","color","cross","success","tick","running","Header","group","title","state","icon","marginRight","bold","pointer","a","b","Output","output","marginLeft","text","Lines","lines","flexDirection","map","line","index","key","type","stderr","Expanded","item","data","linesRegex","ansiRegex","Contracted","forEach","x","split","push","replace","errors","filter","length","pop","ChildProcess","expanded"],"mappings":"AAAA,OAAOA,SAASC,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAa;AACvC,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,aAAa,YAAY;AAGhC,SAASC,QAAQ,QAAQ,WAAW;AAMpC,oHAAoH;AACpH,MAAMC,UAAU;IACdC,UAAU;IACVC,QAAQ;QAAC;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;QAAK;KAAI;AAC5D;AAEA,MAAMC,QAAQ;IACZC,qBAAO,oBAACT;QAAKU,OAAM;OAAOR,QAAQS,KAAK;IACvCC,uBAAS,oBAACZ;QAAKU,OAAM;OAASR,QAAQW,IAAI;IAC1CC,uBAAS,oBAACX,SAAYE;AACxB;AAQA,MAAMU,uBAASlB,KACb,SAASkB,OAAO,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAe;IAClD,MAAMC,OAAOX,KAAK,CAACU,MAAM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AGD;IAExB,MAAMT,QAAQhC,QAAQ;QACpB,MAAMgC,QAAQ,EAAE;QAChBU,KAAKI,OAAO,CAAC,CAACC;YACZA,EAAEjB,IAAI,CAACkB,KAAK,CAACL,YAAYG,OAAO,CAAC,CAAChB,OAASE,MAAMiB,IAAI,CAAC;oBAAEX,MAAMS,EAAET,IAAI;oBAAER,MAAMA,KAAKoB,OAAO,CAACN,WAAW;gBAAI;QAC1G;QACA,OAAOZ;IACT,GAAG;QAACU;KAAK;IAET,iDAAiD;IACjD,MAAMS,SAASnD,QAAQ,IAAMgC,MAAMoB,MAAM,CAAC,CAACjB,OAASA,KAAKG,IAAI,KAAKhC,SAASiC,MAAM,GAAG;QAACP;KAAM;IAC3F,MAAMJ,SAAS5B,QAAQ,IAAMgC,MAAMoB,MAAM,CAAC,CAACjB,OAASA,KAAKL,IAAI,CAACuB,MAAM,GAAG,GAAGC,GAAG,IAAI;QAACtB;KAAM;IAExF,qBACE,oBAAC/B;QAAIgC,eAAc;qBACjB,oBAAChB;QAAOC,OAAOuB,KAAKvB,KAAK;QAAEC,OAAOsB,KAAKtB,KAAK;QAAEC,OAAOqB,KAAKrB,KAAK;QAC9DA,UAAU,aAAaQ,wBAAU,oBAACD;QAAOC,QAAQA;QACjDuB,OAAOE,MAAM,GAAG,mBAAK,oBAACtB;QAAMC,OAAOmB;;AAG1C;AAEA,6BAAepD,KAAK,SAASwD,aAAa,EAAEd,IAAI,EAAa;IAC3D,MAAM,EAAEe,QAAQ,EAAE,GAAGf;IACrB,OAAOe,yBAAW,oBAAChB;QAASC,MAAMA;uBAAW,oBAACI;QAAWJ,MAAMA;;AACjE,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addData.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nexport default function addLines(fn) {\n const stream = new Writable({\n write(data, _enc, callback) {\n fn(data);\n callback();\n },\n });\n return stream;\n}\n"],"names":["Writable","addLines","fn","stream","write","data","_enc","callback"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,eAAe,SAASC,SAASC,EAAE;IACjC,MAAMC,SAAS,IAAIH,SAAS;QAC1BI,OAAMC,IAAI,EAAEC,IAAI,EAAEC,QAAQ;YACxBL,GAAGG;YACHE;QACF;IACF;IACA,OAAOJ;AACT"}
|
package/dist/esm/types.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
export var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
2
|
+
export var DataType = /*#__PURE__*/ function(DataType) {
|
|
3
|
+
DataType[DataType["stdout"] = 1] = "stdout";
|
|
4
|
+
DataType[DataType["stderr"] = 2] = "stderr";
|
|
5
|
+
return DataType;
|
|
6
6
|
}({});
|
package/dist/esm/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: string;\n};\n\nexport enum
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/types.ts"],"sourcesContent":["// @ts-ignore\nexport type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';\n\nexport type TerminalOptions = {\n group?: string;\n expanded?: string;\n};\n\nexport enum DataType {\n stdout = 1,\n stderr = 2,\n}\nexport type Data = {\n type: DataType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n group?: string;\n title: string;\n state: State;\n data: Data[];\n expanded?: string;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n"],"names":["DataType"],"mappings":"AAAA,aAAa;AAQb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -83,10 +83,10 @@ import uuid from 'lil-uuid';
|
|
|
83
83
|
import oo from 'on-one';
|
|
84
84
|
import Queue from 'queue-cb';
|
|
85
85
|
import createApp from './createApp.mjs';
|
|
86
|
-
import
|
|
86
|
+
import addData from './lib/addData.mjs';
|
|
87
87
|
import concatWritable from './lib/concatWritable.mjs';
|
|
88
88
|
import formatArguments from './lib/formatArguments.mjs';
|
|
89
|
-
import {
|
|
89
|
+
import { DataType } from './types.mjs';
|
|
90
90
|
const terminal = createApp();
|
|
91
91
|
export default function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
92
92
|
const { encoding, stdio } = spawnOptions, csOptions = _object_without_properties(spawnOptions, [
|
|
@@ -102,7 +102,7 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
102
102
|
command
|
|
103
103
|
].concat(formatArguments(args)).join(' '),
|
|
104
104
|
state: 'running',
|
|
105
|
-
|
|
105
|
+
data: []
|
|
106
106
|
}, options));
|
|
107
107
|
const cp = crossSpawn(command, args, csOptions);
|
|
108
108
|
const outputs = {
|
|
@@ -111,14 +111,15 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
111
111
|
};
|
|
112
112
|
const queue = new Queue();
|
|
113
113
|
if (cp.stdout) {
|
|
114
|
-
outputs.stdout =
|
|
114
|
+
outputs.stdout = addData((data)=>{
|
|
115
115
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
116
|
-
const lines = item.lines.concat(texts.map((text)=>({
|
|
117
|
-
type: LineType.stdout,
|
|
118
|
-
text
|
|
119
|
-
})));
|
|
120
116
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
121
|
-
|
|
117
|
+
data: item.data.concat([
|
|
118
|
+
{
|
|
119
|
+
type: DataType.stdout,
|
|
120
|
+
text: data.toString('utf8')
|
|
121
|
+
}
|
|
122
|
+
])
|
|
122
123
|
}));
|
|
123
124
|
});
|
|
124
125
|
queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
@@ -129,14 +130,15 @@ export default function spawnTerminal(command, args, spawnOptions, options, call
|
|
|
129
130
|
]));
|
|
130
131
|
}
|
|
131
132
|
if (cp.stderr) {
|
|
132
|
-
outputs.stderr =
|
|
133
|
+
outputs.stderr = addData((data)=>{
|
|
133
134
|
const item = store.getState().processes.find((x)=>x.id === id);
|
|
134
|
-
const lines = item.lines.concat(texts.map((text)=>({
|
|
135
|
-
type: LineType.stderr,
|
|
136
|
-
text
|
|
137
|
-
})));
|
|
138
135
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
139
|
-
|
|
136
|
+
data: item.data.concat([
|
|
137
|
+
{
|
|
138
|
+
type: DataType.stderr,
|
|
139
|
+
text: data.toString('utf8')
|
|
140
|
+
}
|
|
141
|
+
])
|
|
140
142
|
}));
|
|
141
143
|
});
|
|
142
144
|
queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), [
|
package/dist/esm/worker.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/worker.ts"],"sourcesContent":["// @ts-ignore\nimport spawn, { crossSpawn, type SpawnResult } from 'cross-spawn-cb';\nimport uuid from 'lil-uuid';\nimport oo from 'on-one';\nimport Queue from 'queue-cb';\n\nimport createApp from './createApp';\nimport addData from './lib/addData';\nimport concatWritable from './lib/concatWritable';\nimport formatArguments from './lib/formatArguments';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { DataType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback) {\n const { encoding, stdio, ...csOptions } = spawnOptions;\n\n if (stdio === 'inherit') {\n terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(formatArguments(args)).join(' '), state: 'running', data: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = addData((data) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, data: item.data.concat([{ type: DataType.stdout, text: data.toString('utf8') }]) });\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = addData((data) => {\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, data: item.data.concat([{ type: DataType.stderr, text: data.toString('utf8') }]) });\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n const item = store.getState().processes.find((x) => x.id === id);\n store.getState().updateProcess({ ...item, state: err ? 'error' : 'success' });\n\n // let rendering complete\n setTimeout(() => {\n terminal.release();\n err ? callback(err) : callback(null, res);\n });\n });\n });\n } else {\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n const queue = new Queue();\n if (cp.stdout) {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\n queue.defer(oo.bind(null, cp.stderr.pipe(outputs.stderr), ['error', 'end', 'close', 'finish']));\n }\n queue.defer(spawn.worker.bind(null, cp, { ...csOptions, encoding: encoding || 'utf8' }));\n queue.await((err) => {\n const res = (err ? err : {}) as SpawnResult;\n res.stdout = outputs.stdout ? outputs.stdout.output : null;\n res.stderr = outputs.stderr ? outputs.stderr.output : null;\n res.output = [res.stdout, res.stderr, null];\n err ? callback(err) : callback(null, res);\n });\n }\n}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addData","concatWritable","formatArguments","DataType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","data","cp","outputs","stdout","stderr","queue","item","processes","find","x","updateProcess","type","text","toString","defer","bind","pipe","worker","await","err","res","output","setTimeout","release"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW,WAAW;AAE7B,OAAOC,eAAe,cAAc;AACpC,OAAOC,aAAa,gBAAgB;AACpC,OAAOC,oBAAoB,uBAAuB;AAClD,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,WAAWL;AAEjB,eAAe,SAASM,cAAcC,OAAe,EAAEC,IAAc,EAAEC,YAA0B,EAAEC,OAAwB,EAAEC,QAAQ;IACnI,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAgB,GAAGJ,cAAdK,uCAAcL;QAAlCG;QAAUC;;IAElB,IAAIA,UAAU,WAAW;QACvBR,SAASU,MAAM,CAAC,CAACC;YAC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AAI,CAACd,QAAQC,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACA,IAAIF,GAAGG,MAAM,EAAE;YACbF,QAAQE,MAAM,GAAG1B,eAAe,CAAC2C;gBAC/BnB,QAAQE,MAAM,CAACiB,MAAM,GAAGA,OAAOR,QAAQ,CAACzB,YAAY;YACtD;YACAiB,MAAMS,KAAK,CAACxC,GAAGyC,IAAI,CAAC,MAAMd,GAAGG,MAAM,CAACY,IAAI,CAACd,QAAQE,MAAM,GAAG;gBAAC;gBAAS;gBAAO;gBAAS;aAAS;QAC/F;QACAC,MAAMS,KAAK,CAAC3C,MAAM8C,MAAM,CAACF,IAAI,CAAC,MAAMd,IAAI,wCAAKX;YAAWF,UAAUA,YAAY;;QAC9EiB,MAAMa,KAAK,CAAC,CAACC;YACX,MAAMC,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIjB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACkB,MAAM,GAAG;YACtDD,IAAIhB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACiB,MAAM,GAAG;YACtDD,IAAIC,MAAM,GAAG;gBAACD,IAAIjB,MAAM;gBAAEiB,IAAIhB,MAAM;gBAAE;aAAK;YAC3Ce,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMiC;QACvC;IACF;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
1
|
+
import type { ChildProcess as ChildProcessT } from '../types';
|
|
2
|
+
type ItemProps = {
|
|
3
|
+
item: ChildProcessT;
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
-
export
|
|
5
|
+
declare const _default: import("react").NamedExoticComponent<ItemProps>;
|
|
6
|
+
export default _default;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -3,21 +3,21 @@ export type TerminalOptions = {
|
|
|
3
3
|
group?: string;
|
|
4
4
|
expanded?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare enum
|
|
6
|
+
export declare enum DataType {
|
|
7
7
|
stdout = 1,
|
|
8
8
|
stderr = 2
|
|
9
9
|
}
|
|
10
|
-
export type
|
|
11
|
-
type:
|
|
10
|
+
export type Data = {
|
|
11
|
+
type: DataType;
|
|
12
12
|
text: string;
|
|
13
13
|
};
|
|
14
14
|
export type State = 'running' | 'error' | 'success';
|
|
15
15
|
export type ChildProcess = {
|
|
16
16
|
id: string;
|
|
17
|
+
group?: string;
|
|
17
18
|
title: string;
|
|
18
19
|
state: State;
|
|
19
|
-
|
|
20
|
-
group?: string;
|
|
20
|
+
data: Data[];
|
|
21
21
|
expanded?: string;
|
|
22
22
|
};
|
|
23
23
|
export interface AppState {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nconst regEx = /\\r\\n|[\\n\\v\\f\\r\\x85\\u2028\\u2029]/g;\n\nexport default function addLines(fn) {\n let last = '';\n\n const stream = new Writable({\n write(chunk, _enc, callback) {\n const more = last + chunk.toString('utf8');\n const lines = more.split(regEx);\n last = lines.pop();\n if (lines.length) fn(lines);\n callback();\n },\n });\n stream.on('finish', () => {\n if (last.length) fn([last]);\n last = '';\n });\n return stream;\n}\n"],"names":["addLines","regEx","fn","last","stream","Writable","write","chunk","_enc","callback","more","toString","lines","split","pop","length","on"],"mappings":";;;;+BAIA;;;eAAwBA;;;8BAJC;AAEzB,IAAMC,QAAQ;AAEC,SAASD,SAASE,EAAE;IACjC,IAAIC,OAAO;IAEX,IAAMC,SAAS,IAAIC,wBAAQ,CAAC;QAC1BC,OAAAA,SAAAA,MAAMC,KAAK,EAAEC,IAAI,EAAEC,QAAQ;YACzB,IAAMC,OAAOP,OAAOI,MAAMI,QAAQ,CAAC;YACnC,IAAMC,QAAQF,KAAKG,KAAK,CAACZ;YACzBE,OAAOS,MAAME,GAAG;YAChB,IAAIF,MAAMG,MAAM,EAAEb,GAAGU;YACrBH;QACF;IACF;IACAL,OAAOY,EAAE,CAAC,UAAU;QAClB,IAAIb,KAAKY,MAAM,EAAEb,GAAG;YAACC;SAAK;QAC1BA,OAAO;IACT;IACA,OAAOC;AACT"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Writable } from 'readable-stream';
|
|
2
|
-
const regEx = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g;
|
|
3
|
-
export default function addLines(fn) {
|
|
4
|
-
let last = '';
|
|
5
|
-
const stream = new Writable({
|
|
6
|
-
write (chunk, _enc, callback) {
|
|
7
|
-
const more = last + chunk.toString('utf8');
|
|
8
|
-
const lines = more.split(regEx);
|
|
9
|
-
last = lines.pop();
|
|
10
|
-
if (lines.length) fn(lines);
|
|
11
|
-
callback();
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
stream.on('finish', ()=>{
|
|
15
|
-
if (last.length) fn([
|
|
16
|
-
last
|
|
17
|
-
]);
|
|
18
|
-
last = '';
|
|
19
|
-
});
|
|
20
|
-
return stream;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/lib/addLines.ts"],"sourcesContent":["import { Writable } from 'readable-stream';\n\nconst regEx = /\\r\\n|[\\n\\v\\f\\r\\x85\\u2028\\u2029]/g;\n\nexport default function addLines(fn) {\n let last = '';\n\n const stream = new Writable({\n write(chunk, _enc, callback) {\n const more = last + chunk.toString('utf8');\n const lines = more.split(regEx);\n last = lines.pop();\n if (lines.length) fn(lines);\n callback();\n },\n });\n stream.on('finish', () => {\n if (last.length) fn([last]);\n last = '';\n });\n return stream;\n}\n"],"names":["Writable","regEx","addLines","fn","last","stream","write","chunk","_enc","callback","more","toString","lines","split","pop","length","on"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAE3C,MAAMC,QAAQ;AAEd,eAAe,SAASC,SAASC,EAAE;IACjC,IAAIC,OAAO;IAEX,MAAMC,SAAS,IAAIL,SAAS;QAC1BM,OAAMC,KAAK,EAAEC,IAAI,EAAEC,QAAQ;YACzB,MAAMC,OAAON,OAAOG,MAAMI,QAAQ,CAAC;YACnC,MAAMC,QAAQF,KAAKG,KAAK,CAACZ;YACzBG,OAAOQ,MAAME,GAAG;YAChB,IAAIF,MAAMG,MAAM,EAAEZ,GAAGS;YACrBH;QACF;IACF;IACAJ,OAAOW,EAAE,CAAC,UAAU;QAClB,IAAIZ,KAAKW,MAAM,EAAEZ,GAAG;YAACC;SAAK;QAC1BA,OAAO;IACT;IACA,OAAOC;AACT"}
|
|
File without changes
|