Skip to content

Commit

Permalink
Read logs produced by dev plugin and print them to console
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jul 18, 2024
1 parent 8cef917 commit e394a7e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
"commander": "^11.1.0",
"rollup": "^4.3.0",
"simple-git": "^3.22.0",
"tail": "^2.2.6",
"toml": "^3.0.0",
"tslib": "^2.6.2",
"zod": "^3.22.4"
},
"devDependencies": {
"@rollup/plugin-json": "^6.1.0",
"@types/node": "^18.17.1",
"@types/tail": "^2.2.3",
"typescript": "^5.2.2"
},
"publishConfig": {
Expand Down
2 changes: 2 additions & 0 deletions schema/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ message RpcSaveLocalPluginRequest {
string path = 1;
}
message RpcSaveLocalPluginResponse {
string stdout_file_path = 1;
string stderr_file_path = 2;
}
28 changes: 27 additions & 1 deletion src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Plugin, RollupError, watch } from "rollup";
import chalk from "chalk";
import { setupGrpc } from "./grpc";
import { Tail } from "tail";

export async function dev() {
const { SaveLocalPlugin } = await setupGrpc();
Expand All @@ -34,6 +35,9 @@ export async function dev() {
output: rollupOutputOptions()
});

let stdoutTail: Tail | undefined = undefined;
let stderrTail: Tail | undefined = undefined;

watcher.on('event', async (event) => {
switch (event.code) {
case "START": {
Expand All @@ -54,7 +58,29 @@ export async function dev() {
await event.result.close()

try {
await SaveLocalPlugin(process.cwd() + "/dist") // TODO: get dir which contains package.json
let { stdoutFilePath, stderrFilePath } = await SaveLocalPlugin(process.cwd()); // TODO: get dir which contains package.json

if (stdoutTail != undefined) {
stdoutTail.unwatch()
}
stdoutTail = new Tail(stdoutFilePath)
stdoutTail.on("line", function(data) {
console.error(data);
});
stdoutTail.on("error", function(error) {
console.error("ERROR: ", error);
});

if (stderrTail != undefined) {
stderrTail.unwatch()
}
stderrTail = new Tail(stderrFilePath)
stderrTail.on("line", function(data) {
console.error(data);
});
stderrTail.on("error", function(error) {
console.error("ERROR: ", error);
});
} catch (e) {
console.error("Error returned by server");
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions src/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export async function setupGrpc() {
return {
async SaveLocalPlugin(path) {
return new Promise((resolve, reject) => {
client.SaveLocalPlugin({ path }, (err, _) => {
client.SaveLocalPlugin({ path }, (err, response) => {
if (err) reject(err);
else (resolve({}));
else (resolve(response));
});
});
}
Expand Down

0 comments on commit e394a7e

Please sign in to comment.