Skip to content

Commit

Permalink
Merge pull request #10 from sahilrajput03/main
Browse files Browse the repository at this point in the history
Add interesting features 🌟
  • Loading branch information
xanderdeseyn committed Aug 19, 2022
2 parents 7e180fb + 587d393 commit aa428fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
};
Expand Down Expand Up @@ -80,6 +82,8 @@ module.exports = {
files: ['./contracts'],
ignoredFiles: ['**/.vscode'],
verbose: true,
clearOnStart: true,
start: 'echo Running my compilation task now..'
},
ci: {
tasks: [
Expand Down Expand Up @@ -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..',
}
}
}
Expand Down
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: 'inherit' })
} catch (error) {
console.log("Failed 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 aa428fa

Please sign in to comment.