Skip to content

Commit

Permalink
Add support for running a custom start command on running the task an…
Browse files Browse the repository at this point in the history
…d also add support for clearing logs before running tasks from start.
  • Loading branch information
sahilrajput03 committed Aug 9, 2022
1 parent 7e180fb commit b233ac4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -27,6 +28,8 @@ extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) =>
files: task.files ?? [config.paths.sources],
ignoredFiles: task.ignoredFiles ?? [],
verbose: task.verbose ?? false,
start: task.start ?? '',
clearOnStart: task.clearOnStart ?? false,
}
})

Expand Down Expand Up @@ -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]

Expand Down
4 changes: 4 additions & 0 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ declare module 'hardhat/types/config' {
files?: string[]
ignoredFiles?: string[]
verbose?: boolean
start?: string
clearOnStart?: boolean
}

// User facing config
Expand All @@ -29,6 +31,8 @@ declare module 'hardhat/types/config' {
files: string[]
ignoredFiles: string[]
verbose: boolean
start?: string
clearOnStart?: boolean
}
}

Expand Down

0 comments on commit b233ac4

Please sign in to comment.