Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add a plugin to clear the terminal screen
Browse files Browse the repository at this point in the history
## Name
TerminalClearPlugin

## Description
Clears the terminal output so that only the latest build information is displayed

## Options
- saveHistory {Boolean} true - indicates whether to keep the terminal history or not
  • Loading branch information
alsolovyev committed Apr 14, 2021
1 parent d76bd18 commit c73fd0d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ import '@/icons/github.svg'
- [stylelint-webpack-plugin](https://github.com/webpack-contrib/stylelint-webpack-plugin)
- [StyleLint](https://github.com/stylelint/stylelint)

- Terminal
- [TerminalClearPlugin](./config/plugins/clearTerminal.plugin.js)

<br/>


Expand Down
3 changes: 3 additions & 0 deletions config/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
## Stylelint
- [stylelint-webpack-plugin](https://github.com/webpack-contrib/stylelint-webpack-plugin)
- [StyleLint](https://github.com/stylelint/stylelint)

## Terminal
- [TerminalClearPlugin](./clearTerminal.plugin.js)
30 changes: 30 additions & 0 deletions config/plugins/clearTerminal.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Class representing a webpack plugin for clearing the terminal screen.
*
* @requires webpack version >=4
* @version 1.0.0
* @author janeRivas <[email protected]>
* @license MIT
*/
class TerminalClearPlugin {
/**
* @param {Boolean} [saveHistory=true] - indicates whether to keep the terminal history or not
*/
constructor({ saveHistory = true } = { }) {
this.saveHistory = saveHistory
}

/**
* Installs the plugin.
* https://webpack.js.org/contribute/writing-a-plugin/#basic-plugin-architecture
*/
apply(compiler) {
compiler.hooks.beforeCompile.tapAsync('TerminalClearPlugin', (params, callback) => {
process.stdout.write(this.saveHistory ? '\x1B[H\x1B[2J' : '\x1B[2J\x1B[3J\x1B[H\x1Bc')
callback()
})
}
}


module.exports = new TerminalClearPlugin()
2 changes: 2 additions & 0 deletions config/webpack/webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { SOURCE_DIR } = require('../helpers')
const htmlPlugin = require('../plugins/html.plugin.js')
const eslintPlugin = require('../plugins/eslint.plugin.js')
const stylelintPlugin = require('../plugins/stylelint.plugin.js')
const clearTerminal = require('../plugins/clearTerminal.plugin.js')
const javascriptLoader = require('../loaders/javascript.loader.js')
const typescriptLoader = require('../loaders/typescript.loader.js')
const nunjucksLoader = require('../loaders/nunjucks.loader.js')
Expand All @@ -22,6 +23,7 @@ module.exports = {
},
stats: { all: false },
plugins: [
clearTerminal,
...htmlPlugin,
eslintPlugin,
stylelintPlugin
Expand Down

0 comments on commit c73fd0d

Please sign in to comment.