spawn-term 0.1.5 → 0.1.6
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/ChildProcess.cjs +42 -14
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/cjs/worker.cjs +8 -5
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +36 -11
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/worker.mjs +8 -5
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/types.d.ts +3 -1
- package/dist/types/worker.d.ts +1 -1
- package/package.json +1 -1
|
@@ -94,28 +94,21 @@ var POINTERS = {
|
|
|
94
94
|
color: "yellow"
|
|
95
95
|
}, _figures.default.pointer)
|
|
96
96
|
};
|
|
97
|
-
function
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var item = appState.processes.find(function(x) {
|
|
102
|
-
return x.id === id;
|
|
103
|
-
});
|
|
104
|
-
var title = item.title, state = item.state, lines = item.lines, isExpanded = item.isExpanded;
|
|
105
|
-
var icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];
|
|
97
|
+
function Content(param) {
|
|
98
|
+
var item = param.item;
|
|
99
|
+
var title = item.title, state = item.state, lines = item.lines, expanded = item.expanded;
|
|
100
|
+
var icon = ICONS[state];
|
|
106
101
|
var output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;
|
|
107
102
|
var errors = state !== 'running' ? lines.filter(function(line) {
|
|
108
103
|
return line.type === _types.LineType.stderr;
|
|
109
104
|
}) : [];
|
|
110
|
-
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
111
|
-
flexDirection: "column"
|
|
112
|
-
}, /*#__PURE__*/ _react.default.createElement(_ink.Box, null, /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
105
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_ink.Box, null, /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
113
106
|
marginRight: 1
|
|
114
107
|
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, null, icon)), /*#__PURE__*/ _react.default.createElement(_ink.Text, null, title)), output ? /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
115
108
|
marginLeft: 2
|
|
116
109
|
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
117
110
|
color: "gray"
|
|
118
|
-
}, "".concat(_figures.default.arrowRight, " ").concat(output.text))) : undefined,
|
|
111
|
+
}, "".concat(_figures.default.arrowRight, " ").concat(output.text))) : undefined, expanded && /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
119
112
|
flexDirection: "column",
|
|
120
113
|
marginLeft: 2
|
|
121
114
|
}, lines.map(function(line, index) {
|
|
@@ -124,7 +117,42 @@ function ChildProcess(param) {
|
|
|
124
117
|
key: index,
|
|
125
118
|
flexDirection: "column",
|
|
126
119
|
height: 1
|
|
127
|
-
}, /*#__PURE__*/ _react.default.createElement(_ink.Text,
|
|
120
|
+
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
121
|
+
color: line.type === _types.LineType.stderr ? 'red' : 'black'
|
|
122
|
+
}, line.text)));
|
|
123
|
+
})), !expanded && errors.length > 0 && /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
124
|
+
flexDirection: "column",
|
|
125
|
+
marginLeft: 2
|
|
126
|
+
}, errors.map(function(line, index) {
|
|
127
|
+
return(// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
|
|
128
|
+
/*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
129
|
+
key: index,
|
|
130
|
+
flexDirection: "column",
|
|
131
|
+
height: 1
|
|
132
|
+
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, {
|
|
133
|
+
color: line.type === _types.LineType.stderr ? 'red' : 'black'
|
|
134
|
+
}, line.text)));
|
|
128
135
|
})));
|
|
129
136
|
}
|
|
137
|
+
function ChildProcess(param) {
|
|
138
|
+
var id = param.id;
|
|
139
|
+
var store = (0, _react.useContext)(_Store.default);
|
|
140
|
+
var appState = (0, _zustand.useStore)(store);
|
|
141
|
+
var item = appState.processes.find(function(x) {
|
|
142
|
+
return x.id === id;
|
|
143
|
+
});
|
|
144
|
+
var state = item.state, group = item.group;
|
|
145
|
+
var pointer = POINTERS[state] || POINTERS.default;
|
|
146
|
+
return /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
147
|
+
flexDirection: "column"
|
|
148
|
+
}, group && /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
149
|
+
flexDirection: "column"
|
|
150
|
+
}, /*#__PURE__*/ _react.default.createElement(_ink.Box, null, /*#__PURE__*/ _react.default.createElement(_ink.Box, {
|
|
151
|
+
marginRight: 1
|
|
152
|
+
}, /*#__PURE__*/ _react.default.createElement(_ink.Text, null, pointer)), /*#__PURE__*/ _react.default.createElement(_ink.Text, null, group)), /*#__PURE__*/ _react.default.createElement(Content, {
|
|
153
|
+
item: item
|
|
154
|
+
})), !group && /*#__PURE__*/ _react.default.createElement(Content, {
|
|
155
|
+
item: item
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
130
158
|
/* 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, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\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\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\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\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Content({ item }) {\n const { title, state, lines, expanded } = item;\n const icon = ICONS[state];\n const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;\n const errors = state !== 'running' ? lines.filter((line) => line.type === LineType.stderr) : [];\n\n return (\n <React.Fragment>\n <Box>\n <Box marginRight={1}>\n <Text>{icon}</Text>\n </Box>\n <Text>{title}</Text>\n </Box>\n {output ? (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n ) : undefined}\n {expanded && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n {!expanded && errors.length > 0 && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {errors.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n </React.Fragment>\n );\n}\n\nexport default function ChildProcess({ id }: ChildProcessProps) {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const item = appState.processes.find((x) => x.id === id);\n const { state, group } = item;\n const pointer = POINTERS[state] || POINTERS.default;\n\n return (\n <Box flexDirection=\"column\">\n {group && (\n <Box flexDirection=\"column\">\n <Box>\n <Box marginRight={1}>\n <Text>{pointer}</Text>\n </Box>\n <Text>{group}</Text>\n </Box>\n <Content item={item} />\n </Box>\n )}\n {!group && <Content item={item} />}\n </Box>\n );\n}\n"],"names":["ChildProcess","spinner","interval","frames","ICONS","error","Text","color","figures","cross","success","tick","running","Spinner","POINTERS","pointer","default","Content","item","title","state","lines","expanded","icon","output","length","undefined","errors","filter","line","type","LineType","stderr","React","Fragment","Box","marginRight","marginLeft","arrowRight","text","flexDirection","map","index","key","height","id","store","useContext","StoreContext","appState","useStore","processes","find","x","group"],"mappings":";;;;+BA0EA;;;eAAwBA;;;6DA1EU;uBACT;4DACA;mBACC;8DACN;8DACA;qBAGK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,oHAAoH;AACp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|
|
|
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};\n\nexport enum LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n
|
|
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 LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n group?: string;\n expanded?: string;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n"],"names":["LineType"],"mappings":"AAAA,aAAa;;;;;+BAQDA;;;eAAAA;;;AAAL,IAAA,AAAKA,kCAAAA;;;WAAAA"}
|
package/dist/cjs/worker.cjs
CHANGED
|
@@ -143,21 +143,21 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
143
143
|
return target;
|
|
144
144
|
}
|
|
145
145
|
var terminal = (0, _createApp.default)();
|
|
146
|
-
function spawnTerminal(command, args, spawnOptions,
|
|
146
|
+
function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
147
147
|
var encoding = spawnOptions.encoding, stdio = spawnOptions.stdio, csOptions = _object_without_properties(spawnOptions, [
|
|
148
148
|
"encoding",
|
|
149
149
|
"stdio"
|
|
150
150
|
]);
|
|
151
151
|
terminal.retain(function(store) {
|
|
152
152
|
var id = (0, _liluuid.default)();
|
|
153
|
-
store.getState().addProcess({
|
|
153
|
+
store.getState().addProcess(_object_spread({
|
|
154
154
|
id: id,
|
|
155
155
|
title: [
|
|
156
156
|
command
|
|
157
157
|
].concat(args).join(' '),
|
|
158
158
|
state: 'running',
|
|
159
159
|
lines: []
|
|
160
|
-
});
|
|
160
|
+
}, options));
|
|
161
161
|
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
162
162
|
var outputs = {
|
|
163
163
|
stdout: null,
|
|
@@ -246,8 +246,11 @@ function spawnTerminal(command, args, spawnOptions, _options, callback) {
|
|
|
246
246
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
247
247
|
state: err ? 'error' : 'success'
|
|
248
248
|
}));
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
// let rendering complete
|
|
250
|
+
setTimeout(function() {
|
|
251
|
+
terminal.release();
|
|
252
|
+
err ? callback(err) : callback(null, res);
|
|
253
|
+
});
|
|
251
254
|
});
|
|
252
255
|
});
|
|
253
256
|
}
|
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 addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions,
|
|
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 addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } 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 terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\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 if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\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}\n"],"names":["spawnTerminal","terminal","createApp","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","uuid","getState","addProcess","title","concat","join","state","lines","cp","crossSpawn","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","Queue","addLines","texts","item","processes","find","x","map","text","type","LineType","updateProcess","concatWritable","output","toString","defer","oo","bind","pipe","spawn","worker","await","err","res","setTimeout","release"],"mappings":"AAAA,aAAa;;;;;+BAeb;;;eAAwBA;;;oEAd4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;qBAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;IAElBR,SAASU,MAAM,CAAC,SAACC;QACf,IAAMC,KAAKC,IAAAA,gBAAI;QACfF,MAAMG,QAAQ,GAAGC,UAAU,CAAC;YAAEH,IAAAA;YAAII,OAAO;gBAACd;aAAQ,CAACe,MAAM,CAACd,MAAMe,IAAI,CAAC;YAAM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,MAAM,GAAG;gBAACU,IAAI7B,MAAM;gBAAE6B,IAAI5B,MAAM;gBAAE;aAAK;YAC3C,IAAMQ,OAAOtB,MAAMG,QAAQ,GAAGoB,SAAS,CAACC,IAAI,CAAC,SAACC;uBAAMA,EAAExB,EAAE,KAAKA;;YAC7DD,MAAMG,QAAQ,GAAG2B,aAAa,CAAC,wCAAKR;gBAAMd,OAAOiC,MAAM,UAAU;;YAEjE,yBAAyB;YACzBE,WAAW;gBACTtD,SAASuD,OAAO;gBAChBH,MAAM9C,SAAS8C,OAAO9C,SAAS,MAAM+C;YACvC;QACF;IACF;AACF"}
|
|
@@ -38,23 +38,18 @@ const POINTERS = {
|
|
|
38
38
|
color: "yellow"
|
|
39
39
|
}, figures.pointer)
|
|
40
40
|
};
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const item = appState.processes.find((x)=>x.id === id);
|
|
45
|
-
const { title, state, lines, isExpanded } = item;
|
|
46
|
-
const icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];
|
|
41
|
+
function Content({ item }) {
|
|
42
|
+
const { title, state, lines, expanded } = item;
|
|
43
|
+
const icon = ICONS[state];
|
|
47
44
|
const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;
|
|
48
45
|
const errors = state !== 'running' ? lines.filter((line)=>line.type === LineType.stderr) : [];
|
|
49
|
-
return /*#__PURE__*/ React.createElement(Box, {
|
|
50
|
-
flexDirection: "column"
|
|
51
|
-
}, /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Box, {
|
|
46
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Box, {
|
|
52
47
|
marginRight: 1
|
|
53
48
|
}, /*#__PURE__*/ React.createElement(Text, null, icon)), /*#__PURE__*/ React.createElement(Text, null, title)), output ? /*#__PURE__*/ React.createElement(Box, {
|
|
54
49
|
marginLeft: 2
|
|
55
50
|
}, /*#__PURE__*/ React.createElement(Text, {
|
|
56
51
|
color: "gray"
|
|
57
|
-
}, `${figures.arrowRight} ${output.text}`)) : undefined,
|
|
52
|
+
}, `${figures.arrowRight} ${output.text}`)) : undefined, expanded && /*#__PURE__*/ React.createElement(Box, {
|
|
58
53
|
flexDirection: "column",
|
|
59
54
|
marginLeft: 2
|
|
60
55
|
}, lines.map((line, index)=>// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
|
|
@@ -62,5 +57,35 @@ export default function ChildProcess({ id }) {
|
|
|
62
57
|
key: index,
|
|
63
58
|
flexDirection: "column",
|
|
64
59
|
height: 1
|
|
65
|
-
}, /*#__PURE__*/ React.createElement(Text,
|
|
60
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
61
|
+
color: line.type === LineType.stderr ? 'red' : 'black'
|
|
62
|
+
}, line.text)))), !expanded && errors.length > 0 && /*#__PURE__*/ React.createElement(Box, {
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
marginLeft: 2
|
|
65
|
+
}, errors.map((line, index)=>// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
|
|
66
|
+
/*#__PURE__*/ React.createElement(Box, {
|
|
67
|
+
key: index,
|
|
68
|
+
flexDirection: "column",
|
|
69
|
+
height: 1
|
|
70
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
71
|
+
color: line.type === LineType.stderr ? 'red' : 'black'
|
|
72
|
+
}, line.text)))));
|
|
73
|
+
}
|
|
74
|
+
export default function ChildProcess({ id }) {
|
|
75
|
+
const store = useContext(StoreContext);
|
|
76
|
+
const appState = useStore(store);
|
|
77
|
+
const item = appState.processes.find((x)=>x.id === id);
|
|
78
|
+
const { state, group } = item;
|
|
79
|
+
const pointer = POINTERS[state] || POINTERS.default;
|
|
80
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
81
|
+
flexDirection: "column"
|
|
82
|
+
}, group && /*#__PURE__*/ React.createElement(Box, {
|
|
83
|
+
flexDirection: "column"
|
|
84
|
+
}, /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Box, {
|
|
85
|
+
marginRight: 1
|
|
86
|
+
}, /*#__PURE__*/ React.createElement(Text, null, pointer)), /*#__PURE__*/ React.createElement(Text, null, group)), /*#__PURE__*/ React.createElement(Content, {
|
|
87
|
+
item: item
|
|
88
|
+
})), !group && /*#__PURE__*/ React.createElement(Content, {
|
|
89
|
+
item: item
|
|
90
|
+
}));
|
|
66
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\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\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport { useStore } from 'zustand';\nimport StoreContext from '../contexts/Store';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type { AppState } from '../types';\nimport { LineType } from '../types';\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\nconst POINTERS = {\n error: <Text color=\"red\">{figures.pointer}</Text>,\n default: <Text color=\"yellow\">{figures.pointer}</Text>,\n};\n\ntype ChildProcessProps = {\n id: string;\n};\n\nfunction Content({ item }) {\n const { title, state, lines, expanded } = item;\n const icon = ICONS[state];\n const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;\n const errors = state !== 'running' ? lines.filter((line) => line.type === LineType.stderr) : [];\n\n return (\n <React.Fragment>\n <Box>\n <Box marginRight={1}>\n <Text>{icon}</Text>\n </Box>\n <Text>{title}</Text>\n </Box>\n {output ? (\n <Box marginLeft={2}>\n <Text color=\"gray\">{`${figures.arrowRight} ${output.text}`}</Text>\n </Box>\n ) : undefined}\n {expanded && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {lines.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n {!expanded && errors.length > 0 && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {errors.map((line, index) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>\n <Box key={index} flexDirection=\"column\" height={1}>\n <Text color={line.type === LineType.stderr ? 'red' : 'black'}>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\n </React.Fragment>\n );\n}\n\nexport default function ChildProcess({ id }: ChildProcessProps) {\n const store = useContext(StoreContext);\n const appState = useStore(store) as AppState;\n const item = appState.processes.find((x) => x.id === id);\n const { state, group } = item;\n const pointer = POINTERS[state] || POINTERS.default;\n\n return (\n <Box flexDirection=\"column\">\n {group && (\n <Box flexDirection=\"column\">\n <Box>\n <Box marginRight={1}>\n <Text>{pointer}</Text>\n </Box>\n <Text>{group}</Text>\n </Box>\n <Content item={item} />\n </Box>\n )}\n {!group && <Content item={item} />}\n </Box>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","Text","figures","Spinner","LineType","spinner","interval","frames","ICONS","error","color","cross","success","tick","running","POINTERS","pointer","default","Content","item","title","state","lines","expanded","icon","output","length","undefined","errors","filter","line","type","stderr","Fragment","marginRight","marginLeft","arrowRight","text","flexDirection","map","index","key","height","ChildProcess","id","store","appState","processes","find","x","group"],"mappings":"AAAA,OAAOA,SAASC,UAAU,QAAQ,QAAQ;AAC1C,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,kBAAkB,oBAAoB;AAC7C,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAa;AACvC,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,aAAa,YAAY;AAGhC,SAASC,QAAQ,QAAQ,WAAW;AAEpC,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,oBAACR;QAAKS,OAAM;OAAOR,QAAQS,KAAK;IACvCC,uBAAS,oBAACX;QAAKS,OAAM;OAASR,QAAQW,IAAI;IAC1CC,uBAAS,oBAACX,SAAYE;AACxB;AAEA,MAAMU,WAAW;IACfN,qBAAO,oBAACR;QAAKS,OAAM;OAAOR,QAAQc,OAAO;IACzCC,uBAAS,oBAAChB;QAAKS,OAAM;OAAUR,QAAQc,OAAO;AAChD;AAMA,SAASE,QAAQ,EAAEC,IAAI,EAAE;IACvB,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGJ;IAC1C,MAAMK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AC,CAACC,IAAMA,EAAEL,EAAE,KAAKA;IACrD,MAAM,EAAEvB,KAAK,EAAE6B,KAAK,EAAE,GAAG/B;IACzB,MAAMH,UAAUD,QAAQ,CAACM,MAAM,IAAIN,SAASE,OAAO;IAEnD,qBACE,oBAACjB;QAAIsC,eAAc;OAChBY,uBACC,oBAAClD;QAAIsC,eAAc;qBACjB,oBAACtC,yBACC,oBAACA;QAAIkC,aAAa;qBAChB,oBAACjC,YAAMe,yBAET,oBAACf,YAAMiD,uBAET,oBAAChC;QAAQC,MAAMA;SAGlB,CAAC+B,uBAAS,oBAAChC;QAAQC,MAAMA;;AAGhC"}
|
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};\n\nexport enum LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n
|
|
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 LineType {\n stdout = 1,\n stderr = 2,\n}\nexport type Line = {\n type: LineType;\n text: string;\n};\n\nexport type State = 'running' | 'error' | 'success';\nexport type ChildProcess = {\n id: string;\n title: string;\n state: State;\n lines: Line[];\n group?: string;\n expanded?: string;\n};\n\nexport interface AppState {\n processes: ChildProcess[];\n addProcess: (process: ChildProcess) => void;\n updateProcess: (process: ChildProcess) => void;\n}\n"],"names":["LineType"],"mappings":"AAAA,aAAa;AAQb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}
|
package/dist/esm/worker.mjs
CHANGED
|
@@ -87,21 +87,21 @@ import addLines from './lib/addLines.mjs';
|
|
|
87
87
|
import concatWritable from './lib/concatWritable.mjs';
|
|
88
88
|
import { LineType } from './types.mjs';
|
|
89
89
|
const terminal = createApp();
|
|
90
|
-
export default function spawnTerminal(command, args, spawnOptions,
|
|
90
|
+
export default function spawnTerminal(command, args, spawnOptions, options, callback) {
|
|
91
91
|
const { encoding, stdio } = spawnOptions, csOptions = _object_without_properties(spawnOptions, [
|
|
92
92
|
"encoding",
|
|
93
93
|
"stdio"
|
|
94
94
|
]);
|
|
95
95
|
terminal.retain((store)=>{
|
|
96
96
|
const id = uuid();
|
|
97
|
-
store.getState().addProcess({
|
|
97
|
+
store.getState().addProcess(_object_spread({
|
|
98
98
|
id,
|
|
99
99
|
title: [
|
|
100
100
|
command
|
|
101
101
|
].concat(args).join(' '),
|
|
102
102
|
state: 'running',
|
|
103
103
|
lines: []
|
|
104
|
-
});
|
|
104
|
+
}, options));
|
|
105
105
|
const cp = crossSpawn(command, args, csOptions);
|
|
106
106
|
const outputs = {
|
|
107
107
|
stdout: null,
|
|
@@ -180,8 +180,11 @@ export default function spawnTerminal(command, args, spawnOptions, _options, cal
|
|
|
180
180
|
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
181
181
|
state: err ? 'error' : 'success'
|
|
182
182
|
}));
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
// let rendering complete
|
|
184
|
+
setTimeout(()=>{
|
|
185
|
+
terminal.release();
|
|
186
|
+
err ? callback(err) : callback(null, res);
|
|
187
|
+
});
|
|
185
188
|
});
|
|
186
189
|
});
|
|
187
190
|
}
|
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 addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } from './types';\n\nconst terminal = createApp();\n\nexport default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions,
|
|
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 addLines from './lib/addLines';\nimport concatWritable from './lib/concatWritable';\n\nimport type { SpawnOptions, TerminalOptions } from './types';\nimport { LineType } 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 terminal.retain((store) => {\n const id = uuid();\n store.getState().addProcess({ id, title: [command].concat(args).join(' '), state: 'running', lines: [], ...options });\n\n const cp = crossSpawn(command, args, csOptions);\n const outputs = { stdout: null, stderr: null };\n\n if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);\n }\n\n const queue = new Queue();\n if (cp.stdout) {\n if (stdio === 'inherit') {\n outputs.stdout = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stdout, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stdout = concatWritable((output) => {\n outputs.stdout.output = output.toString(encoding || 'utf8');\n });\n }\n queue.defer(oo.bind(null, cp.stdout.pipe(outputs.stdout), ['error', 'end', 'close', 'finish']));\n }\n if (cp.stderr) {\n if (stdio === 'inherit') {\n outputs.stderr = addLines((texts) => {\n const item = store.getState().processes.find((x) => x.id === id);\n const lines = item.lines.concat(texts.map((text) => ({ type: LineType.stderr, text })));\n store.getState().updateProcess({ ...item, lines });\n });\n } else {\n outputs.stderr = concatWritable((output) => {\n outputs.stderr.output = output.toString(encoding || 'utf8');\n });\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 if (cp.stdout && process.stdout.getMaxListeners) {\n process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);\n process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);\n }\n\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}\n"],"names":["spawn","crossSpawn","uuid","oo","Queue","createApp","addLines","concatWritable","LineType","terminal","spawnTerminal","command","args","spawnOptions","options","callback","encoding","stdio","csOptions","retain","store","id","getState","addProcess","title","concat","join","state","lines","cp","outputs","stdout","stderr","process","getMaxListeners","setMaxListeners","queue","texts","item","processes","find","x","map","text","type","updateProcess","output","toString","defer","bind","pipe","worker","await","err","res","setTimeout","release"],"mappings":"AAAA,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,OAAOA,SAASC,UAAU,QAA0B,iBAAiB;AACrE,OAAOC,UAAU,WAAW;AAC5B,OAAOC,QAAQ,SAAS;AACxB,OAAOC,WAAW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AAe,EAAE;gBAC/CD,QAAQF,MAAM,CAACI,eAAe,CAACF,QAAQF,MAAM,CAACG,eAAe,KAAK;gBAClED,QAAQD,MAAM,CAACG,eAAe,CAACF,QAAQD,MAAM,CAACE,eAAe,KAAK;YACpE;YAEA,MAAMoB,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAIvB,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACe,MAAM,GAAG;YACtDQ,IAAItB,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACc,MAAM,GAAG;YACtDQ,IAAIR,MAAM,GAAG;gBAACQ,IAAIvB,MAAM;gBAAEuB,IAAItB,MAAM;gBAAE;aAAK;YAC3C,MAAMM,OAAOlB,MAAME,QAAQ,GAAGiB,SAAS,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEpB,EAAE,KAAKA;YAC7DD,MAAME,QAAQ,GAAGuB,aAAa,CAAC,wCAAKP;gBAAMX,OAAO0B,MAAM,UAAU;;YAEjE,yBAAyB;YACzBE,WAAW;gBACT9C,SAAS+C,OAAO;gBAChBH,MAAMtC,SAASsC,OAAOtC,SAAS,MAAMuC;YACvC;QACF;IACF;AACF"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { SpawnOptions, SpawnCallback, SpawnResult } from 'cross-spawn-cb';
|
|
2
2
|
export type TerminalOptions = {
|
|
3
3
|
group?: string;
|
|
4
|
+
expanded?: string;
|
|
4
5
|
};
|
|
5
6
|
export declare enum LineType {
|
|
6
7
|
stdout = 1,
|
|
@@ -16,7 +17,8 @@ export type ChildProcess = {
|
|
|
16
17
|
title: string;
|
|
17
18
|
state: State;
|
|
18
19
|
lines: Line[];
|
|
19
|
-
|
|
20
|
+
group?: string;
|
|
21
|
+
expanded?: string;
|
|
20
22
|
};
|
|
21
23
|
export interface AppState {
|
|
22
24
|
processes: ChildProcess[];
|
package/dist/types/worker.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { SpawnOptions, TerminalOptions } from './types';
|
|
2
|
-
export default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions,
|
|
2
|
+
export default function spawnTerminal(command: string, args: string[], spawnOptions: SpawnOptions, options: TerminalOptions, callback: any): void;
|