feat(dees-terminal): Enhanced the dees-terminal component to support environment variable settings and improved setup command execution.
This commit is contained in:
parent
f29ca0ba0b
commit
d2646cd62c
@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-01-20 - 1.4.0 - feat(dees-terminal)
|
||||||
|
Enhanced the dees-terminal component to support environment variable settings and improved setup command execution.
|
||||||
|
|
||||||
|
- Added environment property to pass custom environment variables.
|
||||||
|
- Introduced webcontainerDeferred to handle the promise for web container creation.
|
||||||
|
- Enhanced demo to illustrate environment variable usage.
|
||||||
|
- Improved async interaction with the terminal for setting environment variables and executing setup commands.
|
||||||
|
|
||||||
## 2025-01-15 - 1.3.4 - fix(chart)
|
## 2025-01-15 - 1.3.4 - fix(chart)
|
||||||
Fix chart rendering and appearance issues in the DeesChartArea component.
|
Fix chart rendering and appearance issues in the DeesChartArea component.
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@design.estate/dees-catalog',
|
name: '@design.estate/dees-catalog',
|
||||||
version: '1.3.4',
|
version: '1.4.0',
|
||||||
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,25 @@ declare global {
|
|||||||
|
|
||||||
@customElement('dees-terminal')
|
@customElement('dees-terminal')
|
||||||
export class DeesTerminal extends DeesElement {
|
export class DeesTerminal extends DeesElement {
|
||||||
public static demo = () => html` <dees-terminal></dees-terminal> `;
|
public static demo = () => html` <dees-terminal
|
||||||
|
.environment=${{
|
||||||
|
NODE_ENV: 'development',
|
||||||
|
PORT: '3000',
|
||||||
|
}}
|
||||||
|
></dees-terminal> `;
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
private resizeObserver: ResizeObserver;
|
private resizeObserver: ResizeObserver;
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
public setupCommand = `pnpm install @git.zone/tsbuild && clear && echo 'welcome'`;
|
public setupCommand = `pnpm install @serve.zone/cli && servezone cli\n`;
|
||||||
|
|
||||||
|
@property()
|
||||||
|
environment: {[key: string]: string} = {};
|
||||||
|
|
||||||
|
// exposing webcontainer
|
||||||
|
private webcontainerDeferred = new domtools.plugins.smartpromise.Deferred<webcontainer.WebContainer>();
|
||||||
|
public webcontainerPromise = this.webcontainerDeferred.promise;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -282,8 +294,15 @@ export class DeesTerminal extends DeesElement {
|
|||||||
input.write(data);
|
input.write(data);
|
||||||
});
|
});
|
||||||
await this.waitForPrompt(term, '~/');
|
await this.waitForPrompt(term, '~/');
|
||||||
|
// lets set the environment variables
|
||||||
|
await this.setEnvironmentVariables(this.environment, webcontainerInstance);
|
||||||
|
input.write(`source source.env\n`);
|
||||||
|
await this.waitForPrompt(term, '~/');
|
||||||
|
// lets run the setup command
|
||||||
input.write(this.setupCommand);
|
input.write(this.setupCommand);
|
||||||
input.write(`\n`);
|
await this.waitForPrompt(term, '~/');
|
||||||
|
input.write(`clear && echo 'welcome'\n`);
|
||||||
|
this.webcontainerDeferred.resolve(webcontainerInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectedCallback(): Promise<void> {
|
async connectedCallback(): Promise<void> {
|
||||||
@ -300,14 +319,16 @@ export class DeesTerminal extends DeesElement {
|
|||||||
this.fitAddon.fit();
|
this.fitAddon.fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async waitForPrompt(term: Terminal, prompt: string): Promise<void> {
|
public async waitForPrompt(term: Terminal, prompt: string): Promise<void> {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
const checkPrompt = () => {
|
const checkPrompt = () => {
|
||||||
const lines = term.buffer.active;
|
const lines = term.buffer.active;
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines.getLine(i);
|
const line = lines.getLine(i);
|
||||||
if (line && line.translateToString().includes(prompt)) {
|
if (line && line.translateToString().includes(prompt)) {
|
||||||
resolve();
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,4 +338,18 @@ export class DeesTerminal extends DeesElement {
|
|||||||
checkPrompt();
|
checkPrompt();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async setEnvironmentVariables(envArg: {[key: string]: string}, webcontainerInstanceArg?: webcontainer.WebContainer) {
|
||||||
|
const webcontainerInstance = webcontainerInstanceArg ||await this.webcontainerPromise;
|
||||||
|
let envFile = ``
|
||||||
|
for (const key in envArg) {
|
||||||
|
envFile += `export ${key}="${envArg[key]}"\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await webcontainerInstance.mount({'source.env': {
|
||||||
|
file: {
|
||||||
|
contents: envFile,
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user