diff --git a/index.js b/index.js index 03167c8..24a9e29 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ module.exports = class Notifications { } /** - * Remove the laravel mix notifictaion plugin, so that we can use our own + * Remove the laravel mix notification plugin, so that we can use our own * @param config */ webpackConfig(config) { @@ -46,7 +46,8 @@ module.exports = class Notifications { if (Mix.isUsing('notifications')) { let WebpackBuildNotifierPlugin = require('webpack-build-notifier'); - return new WebpackBuildNotifierPlugin(this.config || this.defaultConfig); + const mergedConfig = Object.assign({}, this.defaultConfig, this.config); + return new WebpackBuildNotifierPlugin(mergedConfig); } } } \ No newline at end of file diff --git a/package.json b/package.json index ee06203..19637e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pretty-mix-notifications", - "version": "0.1.2", + "version": "1.0.0", "description": "Make your laravel mix notifications pretty.", "main": "index.js", "scripts": { diff --git a/readme.md b/readme.md index eb78453..220aacb 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,118 @@ Take 2 seconds to make your laravel-mix notifications pretty. +![success](https://user-images.githubusercontent.com/20874606/40683887-7a064b44-6398-11e8-9355-b99528b5ad19.png) +![failure](https://user-images.githubusercontent.com/20874606/40683894-85861fe4-6398-11e8-9d98-3f85014df3c0.png) + ## Installation - `npm install @ntavelis/pretty-mix-notifications` \ No newline at end of file + 1. `npm install pretty-mix-notifications --save-dev` or `yarn add pretty-mix-notifications --dev` + 2. Require the package to your webpack.mix.js file `let Notifications = require('pretty-mix-notifications');` + 3. Extend mix, and pass it the package. `mix.extend('prettyNotifications', new Notifications);` + 4. Call the prettyNotifications. + + Here is a full example of a **webpack.mix.js** file that uses this package: + + ```javascript + let mix = require('laravel-mix'); + let Notifications = require('pretty-mix-notifications'); + + mix.extend('prettyNotifications', new Notifications); + + /* + |-------------------------------------------------------------------------- + | Mix Asset Management + |-------------------------------------------------------------------------- + | + | Mix provides a clean, fluent API for defining some Webpack build steps + | for your Laravel application. By default, we are compiling the Sass + | file for the application as well as bundling up all the JS files. + | + */ + + mix.js('resources/assets/js/app.js', 'public/js') + .sass('resources/assets/sass/app.scss', 'public/css') + .prettyNotifications(); + ``` + +## Override the default config + +If you want to override the default configuration you can pass an object with your config to the prettyNotifications function. + +Below we override the default successImage and the default title. + + ```javascript + mix.js('resources/assets/js/app.js', 'public/js') + .sass('resources/assets/sass/app.scss', 'public/css') + .prettyNotifications( + { + title: "Pretty Mix Notifications", + + successIcon: path.resolve("./success.png"), + } + ); + ``` + +Here is the full list of the supported configuration. +Credit https://github.com/RoccoC/webpack-build-notifier + +## Config Options + + #### title + The notification title. Defaults to **_Webpack Build_**. + + #### logo + The absolute path to the project logo to be displayed as a content image in the notification. Optional. + + #### sound + The sound to play for notifications. Set to false to play no sound. Valid sounds are listedin the node-notifier project, [here](https://github.com/mikaelbr/node-notifier). Defaults to **_Submarine_**. + + #### successSound + The sound to play for success notifications. Defaults to the value of the *sound* configuration option. Set to false to play no sound for success notifications. Takes precedence over the *sound* configuration option. + + #### warningSound + The sound to play for warning notifications. Defaults to the value of the *sound* configuration option. Set to false to play no sound for warning notifications. Takes precedence over the *sound* configuration option. + + #### failureSound + The sound to play for failure notifications. Defaults to the value of the *sound* configuration option. Set to false to play no sound for failure notifications. Takes precedence over the *sound* configuration option. + + #### suppressSuccess + Defines when success notifications are shown. Can be one of the following values: + * false - Show success notification for each successful compilation (default). + * true - Only show success notification for initial successful compilation and after failed compilations. + * "always" - Never show the success notifications. + * "initial" - Same as true, but suppresses the initial success notification. + + #### suppressWarning + True to suppress the warning notifications, otherwise false (default). + + #### suppressCompileStart + True to suppress the compilation started notifications (default), otherwise false. + + #### activateTerminalOnError + True to activate (focus) the terminal window when a compilation error occurs. Note that this only works on Mac OSX (for now). Defaults to **_false_**. Regardless of the value of this config option, the terminal window can always be brought to the front by clicking on the notification. + + #### successIcon + The absolute path to the icon to be displayed for success notifications. Defaults to the included **_./icons/success.png_**. + + #### warningIcon + The absolute path to the icon to be displayed for warning notifications. Defaults to the included **_./icons/warning.png_**. + + #### failureIcon + The absolute path to the icon to be displayed for failure notifications. Defaults to the included **_./icons/failure.png_**. + + #### compileIcon + The absolute path to the icon to be displayed for compilation started notifications. Defaults to the included **_./icons/compile.png_**. + + #### messageFormatter + A function which returns a formatted notification message. The function is passed two parameters: + * {Object} error/warning - The raw error or warning object. + * {String} filepath - The path to the file containing the error/warning (if available). + + This function must return a String. + The default messageFormatter will display the filename which contains the error/warning followed by the + error/warning message. + Note that the message will always be limited to 256 characters. + + #### onClick + A function called when the notification is clicked. By default it activates the Terminal application. \ No newline at end of file