Skip to content

Commit

Permalink
Adding a readme file and performing a better merge of the user config…
Browse files Browse the repository at this point in the history
… and the with the default config. If a property exists in both configs the users takes precedence.
  • Loading branch information
ntavelis committed May 29, 2018
1 parent e62117b commit 3b60269
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 4 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
114 changes: 113 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
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.

0 comments on commit 3b60269

Please sign in to comment.