From b233ac46cf0226bcbda35b636be4be5171eccd93 Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Tue, 9 Aug 2022 19:50:22 +0530 Subject: [PATCH 1/5] Add support for running a custom start command on running the task and also add support for clearing logs before running tasks from start. --- src/index.ts | 16 ++++++++++++++++ src/type-extensions.ts | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/index.ts b/src/index.ts index b65fea5..7fb323a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { extendConfig, task } from 'hardhat/config' import { HardhatConfig, HardhatUserConfig, WatcherConfig } from 'hardhat/types' import chokidar from 'chokidar' +const { execSync } = require('child_process') import './type-extensions' @@ -27,6 +28,8 @@ extendConfig((config: HardhatConfig, userConfig: Readonly) => files: task.files ?? [config.paths.sources], ignoredFiles: task.ignoredFiles ?? [], verbose: task.verbose ?? false, + start: task.start ?? '', + clearOnStart: task.clearOnStart ?? false, } }) @@ -84,6 +87,19 @@ task('watch', 'Start the file watcher') interval: 250, }) .on('change', async path => { + // Clear on on changed files received + if (taskConfig.clearOnStart) { + console.clear() + } + if (taskConfig.start) { + try { + execSync(taskConfig.start, { stdio: 'pipe' }) + } catch (error) { + console.log("Faile to execute 'start' script:", taskConfig.start) + console.error(error) + } + } + for (let i = 0; i < taskConfig.tasks.length; i++) { const task = taskConfig.tasks[i] diff --git a/src/type-extensions.ts b/src/type-extensions.ts index 74ba459..86ec32c 100644 --- a/src/type-extensions.ts +++ b/src/type-extensions.ts @@ -16,6 +16,8 @@ declare module 'hardhat/types/config' { files?: string[] ignoredFiles?: string[] verbose?: boolean + start?: string + clearOnStart?: boolean } // User facing config @@ -29,6 +31,8 @@ declare module 'hardhat/types/config' { files: string[] ignoredFiles: string[] verbose: boolean + start?: string + clearOnStart?: boolean } } From 5798120bc1b5bd60c717d898b1a8a12a5a97d636 Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Fri, 19 Aug 2022 18:48:38 +0530 Subject: [PATCH 2/5] Fix show output of the start command before task runs --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7fb323a..6658e3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -93,7 +93,7 @@ task('watch', 'Start the file watcher') } if (taskConfig.start) { try { - execSync(taskConfig.start, { stdio: 'pipe' }) + execSync(taskConfig.start, { stdio: 'inherit' }) } catch (error) { console.log("Faile to execute 'start' script:", taskConfig.start) console.error(error) From 29110d707e37aa49fded8caa9d08e35f91d86d8c Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Fri, 19 Aug 2022 18:53:38 +0530 Subject: [PATCH 3/5] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 272467e..2fc5cb5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ module.exports = { files?: string[]; // Files, directories or glob patterns to watch for changes. (defaults to `[config.paths.sources]`, which itself defaults to the `contracts` dir) ignoredFiles?: string[]; // Files, directories or glob patterns that should *not* be watched. verbose?: boolean; // Turn on for extra logging + clearOnStart?: boolean; // Turn on to clear the logs (of older task runs) each time before running the task + start?: string; // Run any desirable command each time before the task runs } } }; @@ -80,6 +82,8 @@ module.exports = { files: ['./contracts'], ignoredFiles: ['**/.vscode'], verbose: true, + clearOnStart: true, + start: 'echo Running my compilation task now..' }, ci: { tasks: [ @@ -130,7 +134,9 @@ module.exports = { test: { tasks: [{ command: 'test', params: { testFiles: ['{path}'] } }], files: ['./test/**/*'], - verbose: true + verbose: true, + clearOnStart: true, + start: 'echo Running my test task now..', } } } From 52090a490db54a6a67ae27e771ee21ff6bfe0d89 Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Fri, 19 Aug 2022 18:54:43 +0530 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fc5cb5..e9be9fc 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ module.exports = { tasks: [{ command: 'test', params: { testFiles: ['{path}'] } }], files: ['./test/**/*'], verbose: true, - clearOnStart: true, + clearOnStart: true, start: 'echo Running my test task now..', } } From 587d393ce132050be19dce3b96ba1e1f8f9ffa49 Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Fri, 19 Aug 2022 18:57:33 +0530 Subject: [PATCH 5/5] Fix spelling --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6658e3f..dd077b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ task('watch', 'Start the file watcher') try { execSync(taskConfig.start, { stdio: 'inherit' }) } catch (error) { - console.log("Faile to execute 'start' script:", taskConfig.start) + console.log("Failed to execute 'start' script:", taskConfig.start) console.error(error) } }