Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/lib
/vscode-extension/out
tsconfig.tsbuildinfo
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"lib/**/*"
],
"scripts": {
"prepare": "husky",
"build": "tsc",
"build-and-publish": "npm run build && npx changeset publish",
"lint": "run-p lint:eslint lint:tsc",
"lint:eslint": "eslint src/",
"lint:tsc": "tsc",
"build": "tsc",
"prepare": "husky",
"start": "tsc --watch",
"test": "vitest run",
"test:watch": "vitest",
Expand Down
2 changes: 1 addition & 1 deletion src/daemon-command/handle-log-socket-close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Daemon } from "../commands/start-daemon.command.js";

export function handleLogSocketClose(daemon: Daemon, socket: Socket): void {
for (const script of daemon.scripts) {
const index = script.logSockets.findIndex((i) => i == socket);
const index = script.logSockets.findIndex((i) => i.socket == socket);
if (index !== -1) {
script.logSockets.splice(index, 1);
}
Expand Down
7 changes: 4 additions & 3 deletions src/daemon-command/logs.daemon-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { scriptsMatchingPattern, type ScriptsMatchingPatternOptions } from "./sc

export interface LogsCommandOptions extends ScriptsMatchingPatternOptions {
lines?: number;
hideLogPrefix?: boolean;
}

export function logsDaemonCommand(daemon: Daemon, socket: Socket, options: LogsCommandOptions): void {
Expand All @@ -20,7 +21,7 @@ export function logsDaemonCommand(daemon: Daemon, socket: Socket, options: LogsC
for (const script of scriptsToProcess) {
const lastLines = script.logBuffer.slice(-options.lines);
for (const line of lastLines) {
socket.write(`${script.logPrefix}${line}\n`);
socket.write(`${options.hideLogPrefix ? "" : script.logPrefix}${line}\n`);
}
}
socket.end();
Expand All @@ -29,9 +30,9 @@ export function logsDaemonCommand(daemon: Daemon, socket: Socket, options: LogsC

for (const script of scriptsToProcess) {
for (const line of script.logBuffer) {
socket.write(`${script.logPrefix}${line}\n`);
socket.write(`${options.hideLogPrefix ? "" : script.logPrefix}${line}\n`);
}
script.addLogSocket(socket);
script.addLogSocket(socket, { hideLogPrefix: options.hideLogPrefix ?? false });
}

socket.on("close", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/daemon-command/restart.daemon-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function restartDaemonCommand(daemon: Daemon, socket: Socket, optio
script.startProcess(); //don't await

if (options.follow) {
script.addLogSocket(socket);
script.addLogSocket(socket, { hideLogPrefix: false });
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/daemon-command/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import path from "path";
import waitOn from "wait-on";

import type { ScriptDefinition } from "../script-definition.type.js";
import type { ScriptStatus } from "../shared-types.js";

export type { ScriptStatus };

const KEEP_LOG_LINES = 100;
export type ScriptStatus = "started" | "stopping" | "stopped" | "waiting" | "backoff";

let expandedEnv: Record<string, string>;
function loadExpandedEnv() {
Expand All @@ -28,7 +30,7 @@ export class Script {
status: ScriptStatus = "stopped";
process?: ChildProcess;
logBuffer: string[] = [];
logSockets: Socket[] = [];
logSockets: { socket: Socket; hideLogPrefix: boolean }[] = [];
logPrefix: string;
restartCount = 0;

Expand Down Expand Up @@ -100,8 +102,8 @@ export class Script {
}
}

addLogSocket(socket: Socket): void {
this.logSockets.push(socket);
addLogSocket(socket: Socket, options: { hideLogPrefix: boolean }): void {
this.logSockets.push({ socket, ...options });
}

handleLogs(data: Buffer | string): void {
Expand All @@ -112,7 +114,7 @@ export class Script {
for (const line of incomingLines) {
console.log(`${this.logPrefix}${line}`);
this.logSockets.forEach((socket) => {
socket.write(`${this.logPrefix}${line}\n`);
socket.socket.write(`${socket.hideLogPrefix ? "" : this.logPrefix}${line}\n`);
});
}
const removeLines = incomingLines.length - (KEEP_LOG_LINES - this.logBuffer.length);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon-command/start.daemon-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function startDaemonCommand(daemon: Daemon, socket: Socket, options
script.startProcess(); //don't await
}
if (options.follow) {
script.addLogSocket(socket);
script.addLogSocket(socket, { hideLogPrefix: false });
}
}

Expand Down
14 changes: 3 additions & 11 deletions src/daemon-command/status.daemon-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ import pidusage from "pidusage";
import prettyBytes from "pretty-bytes";

import type { Daemon } from "../commands/start-daemon.command.js";
import type { ScriptStatus } from "./script.js";
import type { ScriptStatusEntry } from "../shared-types.js";
import { scriptsMatchingPattern, type ScriptsMatchingPatternOptions } from "./scripts-matching-pattern.js";

export type { ScriptStatusEntry };

export interface StatusCommandOptions extends ScriptsMatchingPatternOptions {
interval: number | undefined;
}

export interface ScriptStatusEntry {
id: number;
name: string;
status: ScriptStatus;
cpu: string;
memory: string;
pid: number | undefined;
restarts: number;
}

async function pidusageRecursive(pid: number): Promise<{ cpu: number; memory: number }> {
const pids = await pidtree(pid, { root: true });
const usages = await pidusage(pids);
Expand Down
15 changes: 15 additions & 0 deletions src/shared-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Shared type definitions used by both the dev-pm package and the vscode-extension.
// This file is intentionally a .d.ts so it can be imported from packages with a
// restricted rootDir (like the vscode-extension) without emitting JS output.

export type ScriptStatus = "started" | "stopping" | "stopped" | "waiting" | "backoff";

export interface ScriptStatusEntry {
id: number;
name: string;
status: ScriptStatus;
cpu: string;
memory: string;
pid: number | undefined;
restarts: number;
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"target": "ES2020",
"lib": ["ES2020"],
"outDir": "./lib",
"baseUrl": "./",
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Expand Down
8 changes: 8 additions & 0 deletions vscode-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode/**
.vscode-test/**
src/**
node_modules/**
tsconfig.json
**/*.map
**/*.ts
!out/**
25 changes: 25 additions & 0 deletions vscode-extension/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2019, Vivid Planet Software GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 changes: 59 additions & 0 deletions vscode-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Dev Process Manager - VS Code Extension

A VS Code extension for [dev-process-manager](https://github.com/vivid-planet/dev-process-manager) that lets you manage your dev scripts directly from the VS Code sidebar.

## Features

- **Script Status Overview**: See all your dev-pm scripts and their current status (running, stopped, waiting, backoff) in the sidebar
- **Auto-Refresh**: The status list refreshes automatically every 2 seconds
- **Start/Stop/Restart**: Control individual scripts with inline action buttons
- **Start All / Stop All**: Bulk actions available in the view title bar
- **Live Logs**: Open a streaming log output channel for any script

## Requirements

- [VS Code](https://code.visualstudio.com/) 1.85.0 or later
- [dev-process-manager](https://www.npmjs.com/package/dev-process-manager) installed and configured in your project

## Usage

1. Open a workspace that contains a `dev-pm.config.*` file
2. Start the dev-pm daemon (e.g., `dev-pm start`)
3. The **Dev Process Manager** view will appear in the activity bar
4. Use the inline buttons to start, stop, restart, or view logs for each script

### Script Status Icons

| Icon | Status |
|------|--------|
| ▶ (green) | Running |
| ○ (grey) | Stopped |
| ⟳ (yellow) | Waiting (for dependencies) |
| ⟳ (red) | Stopping |
| ⚠ (red) | Backoff (crashed, restarting) |

### Actions

- **Start** (▶): Start a stopped script
- **Restart** (⟳): Restart a running or waiting script
- **Stop** (■): Stop a running or waiting script
- **Logs** (📋): Open a live log stream in a VS Code Output Channel

## Development

```bash
cd vscode-extension
npm install
npm run compile
```

To test the extension, press `F5` in VS Code to launch an Extension Development Host.

## Packaging

```bash
cd vscode-extension
npm run package
```

This creates a `.vsix` file that can be installed in VS Code.
Loading