Skip to content

Commit

Permalink
chopsticks cleans up logs
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 2, 2023
1 parent 78abb1e commit 7492e9c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .changeset/sweet-bats-punch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

Fixes for tanssi
- [#295](https://github.com/Moonsong-Labs/moonwall/issues/295)
- [#297](https://github.com/Moonsong-Labs/moonwall/issues/297)
- [#297](https://github.com/Moonsong-Labs/moonwall/issues/297)
- [#278](https://github.com/Moonsong-Labs/moonwall/issues/278)
5 changes: 4 additions & 1 deletion packages/cli/src/cmds/runNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export async function runNetworkCmd(args) {
},
];

if (env.foundation.type == "dev" && !env.foundation.launchSpec[0].retainAllLogs) {
if (
(env.foundation.type == "dev" && !env.foundation.launchSpec[0].retainAllLogs) ||
(env.foundation.type == "chopsticks" && !env.foundation.launchSpec[0].retainAllLogs)
) {
clearNodeLogs();
}

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export async function testCmd(envName: string, additionalArgs?: object): Promise

await commonChecks(env);

if (env.foundation.type == "dev" && !env.foundation.launchSpec[0].retainAllLogs) {
if (
(env.foundation.type == "dev" && !env.foundation.launchSpec[0].retainAllLogs) ||
(env.foundation.type == "chopsticks" && !env.foundation.launchSpec[0].retainAllLogs)
) {
clearNodeLogs();
}
const vitest = await executeTests(env, additionalArgs);
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/internal/cmdFunctions/tempLogs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import path from "path";
import fs from "fs";

export function clearNodeLogs() {
export function clearNodeLogs(silent: boolean = true) {
const dirPath = path.join(process.cwd(), "tmp", "node_logs");
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}

// Check for existing log files and delete
const files = fs.readdirSync(dirPath);
for (const file of files) {
!silent && console.log(`Deleting log: ${file}`);
if (file.endsWith(".log")) {
fs.unlinkSync(path.join(dirPath, file));
}
Expand All @@ -32,9 +32,7 @@ export function reportLogLocation(silent: boolean = false) {
console.error(e);
}

if (!silent) {
console.log(consoleMessage);
}
!silent && console.log(consoleMessage);

return filePath.trim();
}
4 changes: 4 additions & 0 deletions packages/types/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
},
"type": "array"
},
"retainAllLogs": {
"description": "An optional flag to retain node logs from previous runs.",
"type": "boolean"
},
"running": {
"description": "UNUSED",
"type": "boolean"
Expand Down
15 changes: 10 additions & 5 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ export interface ChopsticksLaunchSpec extends GenericLaunchSpec {
* This is only supported for single mode chopsticks.
*/
buildBlockMode?: "batch" | "manual" | "instant";

/**
* An optional flag to retain node logs from previous runs.
*/
retainAllLogs?: boolean;
}

/**
Expand All @@ -317,11 +322,6 @@ export interface DevLaunchSpec extends GenericLaunchSpec {
*/
newRpcBehaviour?: boolean;

/**
* An optional flag to retain node logs from previous runs.
*/
retainAllLogs?: boolean;

/**
* An optional object with p2pPort, wsPort, and rpcPort.
*/
Expand All @@ -341,6 +341,11 @@ export interface DevLaunchSpec extends GenericLaunchSpec {
*/
wsPort: number;
};

/**
* An optional flag to retain node logs from previous runs.
*/
retainAllLogs?: boolean;
}

/**
Expand Down

0 comments on commit 7492e9c

Please sign in to comment.