Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interesting features 🌟 #10

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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