From b233ac46cf0226bcbda35b636be4be5171eccd93 Mon Sep 17 00:00:00 2001 From: Sahil Rajput Date: Tue, 9 Aug 2022 19:50:22 +0530 Subject: [PATCH] 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 } }