spawn-term 0.1.2 → 0.1.4
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 +54 -36
- package/dist/cjs/components/App.cjs.map +1 -1
- package/dist/cjs/components/ChildProcess.cjs +51 -2
- package/dist/cjs/components/ChildProcess.cjs.map +1 -1
- package/dist/cjs/contexts/Store.cjs +13 -0
- package/dist/cjs/contexts/Store.cjs.map +1 -0
- package/dist/cjs/createApp.cjs +68 -54
- package/dist/cjs/createApp.cjs.map +1 -1
- package/dist/cjs/lib/addLines.cjs +5 -5
- package/dist/cjs/lib/addLines.cjs.map +1 -1
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/cjs/worker.cjs +98 -81
- package/dist/cjs/worker.cjs.map +1 -1
- package/dist/esm/components/App.mjs +16 -38
- package/dist/esm/components/App.mjs.map +1 -1
- package/dist/esm/components/ChildProcess.mjs +8 -2
- package/dist/esm/components/ChildProcess.mjs.map +1 -1
- package/dist/esm/contexts/Store.mjs +2 -0
- package/dist/esm/contexts/Store.mjs.map +1 -0
- package/dist/esm/createApp.mjs +30 -56
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/lib/addLines.mjs +5 -3
- package/dist/esm/lib/addLines.mjs.map +1 -1
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/worker.mjs +88 -81
- package/dist/esm/worker.mjs.map +1 -1
- package/dist/types/components/App.d.ts +1 -5
- package/dist/types/components/ChildProcess.d.ts +2 -6
- package/dist/types/contexts/Store.d.ts +2 -0
- package/dist/types/createApp.d.ts +1 -4
- package/dist/types/lib/addLines.d.ts +1 -1
- package/dist/types/types.d.ts +6 -0
- package/package.json +4 -3
package/dist/cjs/worker.cjs
CHANGED
|
@@ -10,13 +10,13 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
var _crossspawncb = /*#__PURE__*/ _interop_require_wildcard(require("cross-spawn-cb"));
|
|
13
|
+
var _liluuid = /*#__PURE__*/ _interop_require_default(require("lil-uuid"));
|
|
13
14
|
var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
14
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
15
16
|
var _createApp = /*#__PURE__*/ _interop_require_default(require("./createApp.cjs"));
|
|
16
17
|
var _addLines = /*#__PURE__*/ _interop_require_default(require("./lib/addLines.cjs"));
|
|
17
18
|
var _concatWritable = /*#__PURE__*/ _interop_require_default(require("./lib/concatWritable.cjs"));
|
|
18
19
|
var _types = require("./types.cjs");
|
|
19
|
-
var _lodashthrottle = /*#__PURE__*/ _interop_require_default(require("lodash.throttle"));
|
|
20
20
|
function _define_property(obj, key, value) {
|
|
21
21
|
if (key in obj) {
|
|
22
22
|
Object.defineProperty(obj, key, {
|
|
@@ -143,95 +143,112 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
143
143
|
return target;
|
|
144
144
|
}
|
|
145
145
|
var terminal = (0, _createApp.default)();
|
|
146
|
-
var THROTTLE = 100;
|
|
147
|
-
var rerender = (0, _lodashthrottle.default)(function() {
|
|
148
|
-
terminal.rerender();
|
|
149
|
-
}, THROTTLE);
|
|
150
146
|
function spawnTerminal(command, args, spawnOptions, _options, callback) {
|
|
151
147
|
var encoding = spawnOptions.encoding, stdio = spawnOptions.stdio, csOptions = _object_without_properties(spawnOptions, [
|
|
152
148
|
"encoding",
|
|
153
149
|
"stdio"
|
|
154
150
|
]);
|
|
155
|
-
terminal.retain()
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (cp.stdout) {
|
|
174
|
-
if (stdio === 'inherit') {
|
|
175
|
-
outputs.stdout = (0, _addLines.default)(function(text) {
|
|
176
|
-
item.lines.push({
|
|
177
|
-
type: _types.LineType.stdout,
|
|
178
|
-
text: text
|
|
179
|
-
});
|
|
180
|
-
rerender();
|
|
181
|
-
});
|
|
182
|
-
} else {
|
|
183
|
-
outputs.stdout = (0, _concatWritable.default)(function(output) {
|
|
184
|
-
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
185
|
-
});
|
|
151
|
+
terminal.retain(function(store) {
|
|
152
|
+
var id = (0, _liluuid.default)();
|
|
153
|
+
store.getState().addProcess({
|
|
154
|
+
id: id,
|
|
155
|
+
title: [
|
|
156
|
+
command
|
|
157
|
+
].concat(args).join(' '),
|
|
158
|
+
state: 'running',
|
|
159
|
+
lines: []
|
|
160
|
+
});
|
|
161
|
+
var cp = (0, _crossspawncb.crossSpawn)(command, args, csOptions);
|
|
162
|
+
var outputs = {
|
|
163
|
+
stdout: null,
|
|
164
|
+
stderr: null
|
|
165
|
+
};
|
|
166
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
167
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() + 1);
|
|
168
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() + 1);
|
|
186
169
|
}
|
|
187
|
-
queue.
|
|
188
|
-
|
|
189
|
-
'
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
170
|
+
var queue = new _queuecb.default();
|
|
171
|
+
if (cp.stdout) {
|
|
172
|
+
if (stdio === 'inherit') {
|
|
173
|
+
outputs.stdout = (0, _addLines.default)(function(texts) {
|
|
174
|
+
var item = store.getState().processes.find(function(x) {
|
|
175
|
+
return x.id === id;
|
|
176
|
+
});
|
|
177
|
+
var lines = item.lines.concat(texts.map(function(text) {
|
|
178
|
+
return {
|
|
179
|
+
type: _types.LineType.stdout,
|
|
180
|
+
text: text
|
|
181
|
+
};
|
|
182
|
+
}));
|
|
183
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
184
|
+
lines: lines
|
|
185
|
+
}));
|
|
200
186
|
});
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
187
|
+
} else {
|
|
188
|
+
outputs.stdout = (0, _concatWritable.default)(function(output) {
|
|
189
|
+
outputs.stdout.output = output.toString(encoding || 'utf8');
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
queue.defer(_onone.default.bind(null, cp.stdout.pipe(outputs.stdout), [
|
|
193
|
+
'error',
|
|
194
|
+
'end',
|
|
195
|
+
'close',
|
|
196
|
+
'finish'
|
|
197
|
+
]));
|
|
207
198
|
}
|
|
208
|
-
|
|
209
|
-
'
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
199
|
+
if (cp.stderr) {
|
|
200
|
+
if (stdio === 'inherit') {
|
|
201
|
+
outputs.stderr = (0, _addLines.default)(function(texts) {
|
|
202
|
+
var item = store.getState().processes.find(function(x) {
|
|
203
|
+
return x.id === id;
|
|
204
|
+
});
|
|
205
|
+
var lines = item.lines.concat(texts.map(function(text) {
|
|
206
|
+
return {
|
|
207
|
+
type: _types.LineType.stderr,
|
|
208
|
+
text: text
|
|
209
|
+
};
|
|
210
|
+
}));
|
|
211
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
212
|
+
lines: lines
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
outputs.stderr = (0, _concatWritable.default)(function(output) {
|
|
217
|
+
outputs.stderr.output = output.toString(encoding || 'utf8');
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
queue.defer(_onone.default.bind(null, cp.stderr.pipe(outputs.stderr), [
|
|
221
|
+
'error',
|
|
222
|
+
'end',
|
|
223
|
+
'close',
|
|
224
|
+
'finish'
|
|
225
|
+
]));
|
|
222
226
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
queue.defer(_crossspawncb.default.worker.bind(null, cp, _object_spread_props(_object_spread({}, csOptions), {
|
|
228
|
+
encoding: 'utf8'
|
|
229
|
+
})));
|
|
230
|
+
queue.await(function(err) {
|
|
231
|
+
if (cp.stdout && process.stdout.getMaxListeners) {
|
|
232
|
+
process.stdout.setMaxListeners(process.stdout.getMaxListeners() - 1);
|
|
233
|
+
process.stderr.setMaxListeners(process.stderr.getMaxListeners() - 1);
|
|
234
|
+
}
|
|
235
|
+
var res = err ? err : {};
|
|
236
|
+
res.stdout = outputs.stdout ? outputs.stdout.output : null;
|
|
237
|
+
res.stderr = outputs.stderr ? outputs.stderr.output : null;
|
|
238
|
+
res.output = [
|
|
239
|
+
res.stdout,
|
|
240
|
+
res.stderr,
|
|
241
|
+
null
|
|
242
|
+
];
|
|
243
|
+
var item = store.getState().processes.find(function(x) {
|
|
244
|
+
return x.id === id;
|
|
245
|
+
});
|
|
246
|
+
store.getState().updateProcess(_object_spread_props(_object_spread({}, item), {
|
|
247
|
+
state: err ? 'error' : 'success'
|
|
248
|
+
}));
|
|
249
|
+
terminal.release();
|
|
250
|
+
err ? callback(err) : callback(null, res);
|
|
251
|
+
});
|
|
235
252
|
});
|
|
236
253
|
}
|
|
237
254
|
/* 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/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 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\
|
|
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: [] });\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 terminal.release();\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","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","release"],"mappings":"AAAA,aAAa;;;;;+BAeb;;;eAAwBA;;;oEAd4B;8DACnC;4DACF;8DACG;gEAEI;+DACD;qEACM;qBAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzB,IAAMC,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Ae,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,IAAM0B,MAAOD,MAAMA,MAAM,CAAC;YAC1BC,IAAI7B,MAAM,GAAGD,QAAQC,MAAM,GAAGD,QAAQC,MAAM,CAACmB,MAAM,GAAG;YACtDU,IAAI5B,MAAM,GAAGF,QAAQE,MAAM,GAAGF,QAAQE,MAAM,CAACkB,MAAM,GAAG;YACtDU,IAAIV,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;;YACjEpD,SAASsD,OAAO;YAChBF,MAAM9C,SAAS8C,OAAO9C,SAAS,MAAM+C;QACvC;IACF;AACF"}
|
|
@@ -1,47 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _object_spread(target) {
|
|
15
|
-
for(var i = 1; i < arguments.length; i++){
|
|
16
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
-
var ownKeys = Object.keys(source);
|
|
18
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_define_property(target, key, source[key]);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { useStore } from 'zustand';
|
|
3
|
+
import StoreContext from '../contexts/Store.mjs';
|
|
30
4
|
import { Box } from '../ink.mjs';
|
|
31
5
|
import ChildProcess from './ChildProcess.mjs';
|
|
32
|
-
export default function App(
|
|
33
|
-
const
|
|
6
|
+
export default function App() {
|
|
7
|
+
const store = useContext(StoreContext);
|
|
8
|
+
const appState = useStore(store);
|
|
9
|
+
const running = appState.processes.filter((x)=>[
|
|
34
10
|
'running'
|
|
35
11
|
].indexOf(x.state) >= 0);
|
|
36
|
-
const done =
|
|
12
|
+
const done = appState.processes.filter((x)=>[
|
|
37
13
|
'error',
|
|
38
14
|
'success'
|
|
39
15
|
].indexOf(x.state) >= 0);
|
|
40
16
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Box, {
|
|
41
17
|
flexDirection: "column"
|
|
42
|
-
}, running.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess,
|
|
43
|
-
key: item.id
|
|
44
|
-
|
|
18
|
+
}, running.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, {
|
|
19
|
+
key: item.id,
|
|
20
|
+
id: item.id
|
|
21
|
+
}))), /*#__PURE__*/ React.createElement(Box, {
|
|
45
22
|
flexDirection: "column",
|
|
46
23
|
borderStyle: "single",
|
|
47
24
|
borderColor: "black",
|
|
@@ -51,7 +28,8 @@ export default function App({ list }) {
|
|
|
51
28
|
borderRight: false
|
|
52
29
|
}), /*#__PURE__*/ React.createElement(Box, {
|
|
53
30
|
flexDirection: "column"
|
|
54
|
-
}, done.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess,
|
|
55
|
-
key: item.id
|
|
56
|
-
|
|
31
|
+
}, done.map((item)=>/*#__PURE__*/ React.createElement(ChildProcess, {
|
|
32
|
+
key: item.id,
|
|
33
|
+
id: item.id
|
|
34
|
+
}))));
|
|
57
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/App.tsx"],"sourcesContent":["import React from 'react';\nimport { Box } from '../ink.mjs';\nimport type { ChildProcess as ChildProcessT } from '../types';\nimport ChildProcess from './ChildProcess';\n\nexport
|
|
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 const running = appState.processes.filter((x) => ['running'].indexOf(x.state) >= 0);\n const done = appState.processes.filter((x) => ['error', 'success'].indexOf(x.state) >= 0);\n\n return (\n <>\n <Box flexDirection=\"column\">\n {running.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} id={item.id} />\n ))}\n </Box>\n <Box flexDirection=\"column\" borderStyle=\"single\" borderColor=\"black\" borderBottom={true} borderTop={false} borderLeft={false} borderRight={false} />\n <Box flexDirection=\"column\">\n {done.map((item: ChildProcessT) => (\n <ChildProcess key={item.id} id={item.id} />\n ))}\n </Box>\n </>\n );\n}\n"],"names":["React","useContext","useStore","StoreContext","Box","ChildProcess","App","store","appState","running","processes","filter","x","indexOf","state","done","flexDirection","map","item","key","id","borderStyle","borderColor","borderBottom","borderTop","borderLeft","borderRight"],"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;IAC1B,MAAME,UAAUD,SAASE,SAAS,CAACC,MAAM,CAAC,CAACC,IAAM;YAAC;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IACjF,MAAMC,OAAOP,SAASE,SAAS,CAACC,MAAM,CAAC,CAACC,IAAM;YAAC;YAAS;SAAU,CAACC,OAAO,CAACD,EAAEE,KAAK,KAAK;IAEvF,qBACE,wDACE,oBAACV;QAAIY,eAAc;OAChBP,QAAQQ,GAAG,CAAC,CAACC,qBACZ,oBAACb;YAAac,KAAKD,KAAKE,EAAE;YAAEA,IAAIF,KAAKE,EAAE;4BAG3C,oBAAChB;QAAIY,eAAc;QAASK,aAAY;QAASC,aAAY;QAAQC,cAAc;QAAMC,WAAW;QAAOC,YAAY;QAAOC,aAAa;sBAC3I,oBAACtB;QAAIY,eAAc;OAChBD,KAAKE,GAAG,CAAC,CAACC,qBACT,oBAACb;YAAac,KAAKD,KAAKE,EAAE;YAAEA,IAAIF,KAAKE,EAAE;;AAKjD"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { useStore } from 'zustand';
|
|
3
|
+
import StoreContext from '../contexts/Store.mjs';
|
|
2
4
|
import { Box, Text } from '../ink.mjs';
|
|
3
5
|
import figures from '../lib/figures.mjs';
|
|
4
6
|
import Spinner from './Spinner.mjs';
|
|
@@ -36,7 +38,11 @@ const POINTERS = {
|
|
|
36
38
|
color: "yellow"
|
|
37
39
|
}, figures.pointer)
|
|
38
40
|
};
|
|
39
|
-
export default function ChildProcess({
|
|
41
|
+
export default function ChildProcess({ id }) {
|
|
42
|
+
const store = useContext(StoreContext);
|
|
43
|
+
const appState = useStore(store);
|
|
44
|
+
const item = appState.processes.find((x)=>x.id === id);
|
|
45
|
+
const { title, state, lines, isExpanded } = item;
|
|
40
46
|
const icon = isExpanded ? POINTERS[state] || POINTERS.default : ICONS[state];
|
|
41
47
|
const output = state === 'running' && lines.length ? lines[lines.length - 1] : undefined;
|
|
42
48
|
const errors = state !== 'running' ? lines.filter((line)=>line.type === LineType.stderr) : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/components/ChildProcess.tsx"],"sourcesContent":["import React from 'react';\nimport { Box, Text } from '../ink.mjs';\nimport figures from '../lib/figures';\nimport Spinner from './Spinner';\n\nimport type {
|
|
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\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 { title, state, lines, isExpanded } = item;\n\n const icon = isExpanded ? POINTERS[state] || POINTERS.default : 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 <Box flexDirection=\"column\">\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 {errors.length > 0 && (\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>{line.text}</Text>\n </Box>\n ))}\n </Box>\n )}\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","ChildProcess","id","store","appState","item","processes","find","x","title","state","lines","isExpanded","icon","output","length","undefined","errors","filter","line","type","stderr","flexDirection","marginRight","marginLeft","arrowRight","text","map","index","key","height"],"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,OA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/spawn-term/src/contexts/Store.tsx"],"sourcesContent":["import { createContext } from 'react';\nexport default createContext(undefined);\n"],"names":["createContext","undefined"],"mappings":"AAAA,SAASA,aAAa,QAAQ,QAAQ;AACtC,6BAAeA,cAAcC,WAAW"}
|
package/dist/esm/createApp.mjs
CHANGED
|
@@ -1,73 +1,47 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _object_spread(target) {
|
|
15
|
-
for(var i = 1; i < arguments.length; i++){
|
|
16
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
-
var ownKeys = Object.keys(source);
|
|
18
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_define_property(target, key, source[key]);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
import uuid from 'lil-uuid';
|
|
30
1
|
import React from 'react';
|
|
2
|
+
import resolveOnce from 'resolve-once-cb';
|
|
3
|
+
import { createStore } from 'zustand';
|
|
31
4
|
import App from './components/App.mjs';
|
|
5
|
+
import StoreContext from './contexts/Store.mjs';
|
|
32
6
|
// @ts-ignore
|
|
33
7
|
import { render } from './ink.mjs';
|
|
8
|
+
const initialize = resolveOnce((cb)=>setTimeout(()=>cb(), 0));
|
|
34
9
|
export default function createApp() {
|
|
35
10
|
let refCount = 0;
|
|
36
|
-
let
|
|
11
|
+
let store = null;
|
|
37
12
|
let inkApp = null;
|
|
13
|
+
const _waiting = [];
|
|
38
14
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}), {
|
|
62
|
-
patchConsole: false
|
|
15
|
+
retain (fn) {
|
|
16
|
+
initialize(()=>{
|
|
17
|
+
if (++refCount > 1) return fn(store);
|
|
18
|
+
if (store) throw new Error('Not expecting store');
|
|
19
|
+
store = createStore()((set)=>({
|
|
20
|
+
processes: [],
|
|
21
|
+
addProcess: (process1)=>set((state)=>({
|
|
22
|
+
processes: [
|
|
23
|
+
...state.processes,
|
|
24
|
+
process1
|
|
25
|
+
]
|
|
26
|
+
})),
|
|
27
|
+
updateProcess: (process1)=>set((state)=>({
|
|
28
|
+
processes: state.processes.map((x)=>x.id === process1.id ? process1 : x)
|
|
29
|
+
}))
|
|
30
|
+
}));
|
|
31
|
+
inkApp = render(/*#__PURE__*/ React.createElement(StoreContext.Provider, {
|
|
32
|
+
value: store
|
|
33
|
+
}, /*#__PURE__*/ React.createElement(App, null)), {
|
|
34
|
+
patchConsole: false
|
|
35
|
+
});
|
|
36
|
+
return fn(store);
|
|
63
37
|
});
|
|
64
38
|
},
|
|
65
39
|
release () {
|
|
66
40
|
if (--refCount > 0) return;
|
|
67
|
-
if (!
|
|
41
|
+
if (!store) throw new Error('Expecting store');
|
|
42
|
+
store = null;
|
|
68
43
|
inkApp.unmount();
|
|
69
44
|
inkApp = null;
|
|
70
|
-
list = null;
|
|
71
45
|
process.stdout.write('\x1b[?25h'); // show cursor
|
|
72
46
|
}
|
|
73
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/spawn-term/src/createApp.tsx"],"sourcesContent":["import React from 'react';\nimport resolveOnce from 'resolve-once-cb';\nimport { createStore } from 'zustand';\nimport App from './components/App';\nimport StoreContext from './contexts/Store';\n\n// @ts-ignore\nimport { type Instance, render } from './ink.mjs';\nimport type { AppState } from './types';\n\nconst initialize = resolveOnce((cb) => setTimeout(() => cb(), 0));\n\nexport default function createApp() {\n let refCount = 0;\n let store = null;\n let inkApp: Instance | null = null;\n const _waiting = [];\n\n return {\n retain(fn) {\n initialize(() => {\n if (++refCount > 1) return fn(store);\n if (store) throw new Error('Not expecting store');\n store = createStore<AppState>()((set) => ({\n processes: [],\n addProcess: (process) => set((state) => ({ processes: [...state.processes, process] })),\n updateProcess: (process) => set((state) => ({ processes: state.processes.map((x) => (x.id === process.id ? process : x)) })),\n }));\n inkApp = render(\n <StoreContext.Provider value={store}>\n <App />\n </StoreContext.Provider>,\n { patchConsole: false }\n );\n return fn(store);\n });\n },\n release() {\n if (--refCount > 0) return;\n if (!store) throw new Error('Expecting store');\n store = null;\n inkApp.unmount();\n inkApp = null;\n process.stdout.write('\\x1b[?25h'); // show cursor\n },\n };\n}\n"],"names":["React","resolveOnce","createStore","App","StoreContext","render","initialize","cb","setTimeout","createApp","refCount","store","inkApp","_waiting","retain","fn","Error","set","processes","addProcess","process","state","updateProcess","map","x","id","Provider","value","patchConsole","release","unmount","stdout","write"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,iBAAiB,kBAAkB;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,OAAOC,SAAS,mBAAmB;AACnC,OAAOC,kBAAkB,mBAAmB;AAE5C,aAAa;AACb,SAAwBC,MAAM,QAAQ,YAAY;AAGlD,MAAMC,aAAaL,YAAY,CAACM,KAAOC,WAAW,IAAMD,MAAM;AAE9D,eAAe,SAASE;IACtB,IAAIC,WAAW;IACf,IAAIC,QAAQ;IACZ,IAAIC,SAA0B;IAC9B,MAAMC,WAAW,EAAE;IAEnB,OAAO;QACLC,QAAOC,EAAE;YACPT,WAAW;gBACT,IAAI,EAAEI,WAAW,GAAG,OAAOK,GAAGJ;gBAC9B,IAAIA,OAAO,MAAM,IAAIK,MAAM;gBAC3BL,QAAQT,cAAwB,CAACe,MAAS,CAAA;wBACxCC,WAAW,EAAE;wBACbC,YAAY,CAACC,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAW;2CAAIG,MAAMH,SAAS;wCAAEE;qCAAQ;gCAAC,CAAA;wBACpFE,eAAe,CAACF,WAAYH,IAAI,CAACI,QAAW,CAAA;oCAAEH,WAAWG,MAAMH,SAAS,CAACK,GAAG,CAAC,CAACC,IAAOA,EAAEC,EAAE,KAAKL,SAAQK,EAAE,GAAGL,WAAUI;gCAAI,CAAA;oBAC3H,CAAA;gBACAZ,SAASP,qBACP,oBAACD,aAAasB,QAAQ;oBAACC,OAAOhB;iCAC5B,oBAACR,aAEH;oBAAEyB,cAAc;gBAAM;gBAExB,OAAOb,GAAGJ;YACZ;QACF;QACAkB;YACE,IAAI,EAAEnB,WAAW,GAAG;YACpB,IAAI,CAACC,OAAO,MAAM,IAAIK,MAAM;YAC5BL,QAAQ;YACRC,OAAOkB,OAAO;YACdlB,SAAS;YACTQ,QAAQW,MAAM,CAACC,KAAK,CAAC,cAAc,cAAc;QACnD;IACF;AACF"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Writable } from 'readable-stream';
|
|
2
2
|
const regEx = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g;
|
|
3
|
-
export default function addLines(
|
|
3
|
+
export default function addLines(fn) {
|
|
4
4
|
let last = '';
|
|
5
5
|
const stream = new Writable({
|
|
6
6
|
write (chunk, _enc, callback) {
|
|
7
7
|
const more = last + chunk.toString('utf8');
|
|
8
8
|
const lines = more.split(regEx);
|
|
9
9
|
last = lines.pop();
|
|
10
|
-
lines.
|
|
10
|
+
if (lines.length) fn(lines);
|
|
11
11
|
callback();
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
stream.on('finish', ()=>{
|
|
15
|
-
if (last.length)
|
|
15
|
+
if (last.length) fn([
|
|
16
|
+
last
|
|
17
|
+
]);
|
|
16
18
|
last = '';
|
|
17
19
|
});
|
|
18
20
|
return stream;
|
|
@@ -1 +1 @@
|
|
|
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(
|
|
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"}
|
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};\n"],"names":["LineType"],"mappings":"AAAA,aAAa;AAOb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}
|
|
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 isExpanded: boolean;\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;AAOb,OAAO,IAAA,AAAKA,kCAAAA;;;WAAAA;MAGX"}
|