XuqmGroup-H5SDK/node_modules/@rushstack/terminal/lib-esm/TerminalStreamWritable.js
徐勤民 e34fa2052a feat(private): add private deployment SDK module
Adds @xuqm/h5-sdk/private entry point with JSON-based initialization,
feature gating, and error codes for private deployment scenarios.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 21:08:08 +08:00

49 行
1.8 KiB
JavaScript

// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { Writable } from 'node:stream';
import { TerminalProviderSeverity } from './ITerminalProvider';
/**
* A adapter to allow writing to a provided terminal using Writable streams.
*
* @beta
*/
export class TerminalStreamWritable extends Writable {
constructor(options) {
const { terminal, severity, writableOptions } = options;
super(writableOptions);
this._writev = undefined;
switch (severity) {
case TerminalProviderSeverity.log:
this._writeMethod = terminal.write.bind(terminal);
break;
case TerminalProviderSeverity.verbose:
this._writeMethod = terminal.writeVerbose.bind(terminal);
break;
case TerminalProviderSeverity.debug:
this._writeMethod = terminal.writeDebug.bind(terminal);
break;
case TerminalProviderSeverity.warning:
this._writeMethod = terminal.writeWarning.bind(terminal);
break;
case TerminalProviderSeverity.error:
this._writeMethod = terminal.writeError.bind(terminal);
break;
default:
throw new Error(`Unknown severity: ${severity}`);
}
}
_write(chunk, encoding,
// eslint-disable-next-line @rushstack/no-new-null
callback) {
try {
const chunkData = typeof chunk === 'string' ? chunk : Buffer.from(chunk);
this._writeMethod(chunkData.toString());
}
catch (e) {
callback(e);
return;
}
callback();
}
}
//# sourceMappingURL=TerminalStreamWritable.js.map