Skip to content
Permalink
Browse files

feat: initial implementation

  • Loading branch information...
satazor committed Dec 15, 2017
1 parent 45c226e commit b60a53ee6e67dd42f5aa19d4e3dc167a473a38cd
Showing with 7,272 additions and 0 deletions.
  1. +16 −0 .editorconfig
  2. +3 −0 .eslintignore
  3. +8 −0 .eslintrc.json
  4. +3 −0 .gitignore
  5. +8 −0 .travis.yml
  6. +21 −0 LICENSE
  7. +55 −0 README.md
  8. +75 −0 index.js
  9. +6,904 −0 package-lock.json
  10. +67 −0 package.json
  11. +112 −0 test/index.spec.js
  12. BIN webpack-logo.png
@@ -0,0 +1,16 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
indent_size = 2

[{*.md,*.snap}]
trim_trailing_whitespace = false
@@ -0,0 +1,3 @@
coverage/
test/tmp/
test/configs/files/
@@ -0,0 +1,8 @@
{
"root": true,
"extends": [
"eslint-config-moxy/es6",
"eslint-config-moxy/addons/node",
"eslint-config-moxy/addons/jest"
]
}
@@ -0,0 +1,3 @@
node_modules
npm-debug.*
coverage/
@@ -0,0 +1,8 @@
language: node_js
node_js:
- "node"
- "lts/*"
# Report coverage
after_success:
- "npm i codecov"
- "node_modules/.bin/codecov"
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Made With MOXY Lda <hello@moxy.studio>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,55 @@
# webpack-sane-compiler-notifier

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]

[npm-url]:https://npmjs.org/package/webpack-sane-compiler-notifier
[npm-image]:http://img.shields.io/npm/v/webpack-sane-compiler-notifier.svg
[downloads-image]:http://img.shields.io/npm/dm/webpack-sane-compiler-notifier.svg
[travis-url]:https://travis-ci.org/moxystudio/webpack-sane-compiler-notifier
[travis-image]:http://img.shields.io/travis/moxystudio/webpack-sane-compiler-notifier/master.svg
[codecov-url]:https://codecov.io/gh/moxystudio/webpack-sane-compiler-notifier
[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/webpack-sane-compiler-notifier/master.svg
[david-dm-url]:https://david-dm.org/moxystudio/webpack-sane-compiler-notifier
[david-dm-image]:https://img.shields.io/david/moxystudio/webpack-sane-compiler-notifier.svg
[david-dm-dev-url]:https://david-dm.org/moxystudio/webpack-sane-compiler-notifier?type=dev
[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/webpack-sane-compiler-notifier.svg
[greenkeeper-image]:https://badges.greenkeeper.io/moxystudio/webpack-sane-compiler-notifier.svg
[greenkeeper-url]:https://greenkeeper.io

Notify webpack compilation status to your operating system when using [webpack-sane-compiler](https://github.com/moxystudio/webpack-sane-compiler).


## Installation

`$ npm install webpack-sane-compiler-notifier --save-dev`


## Usage

```js
const startNotifying = require('webpack-sane-compiler-notifier');
const stopNotifying = startNotifying(compiler, {/* options */});
// Call compiler.run() or compiler.watch() to start a compilation and you will see OS notifications showing up
// Additionally, calling stopNotifying() will stop listening to the compiler events
```

### Available options:

| Name | Description | Type | Default |
| ------ | ------------- | -------- | ------- |
| title | The title for the notification | string | package.json `name` |
| icon | The icon for the notification | string | [webpack-logo.png](webpack-logo.png) |
| sound | Play a sound when notifying on OS that support it | string | false |


## Tests

`$ npm test`
`$ npm test -- --watch` during development


## License

[MIT License](http://opensource.org/licenses/MIT)
@@ -0,0 +1,75 @@
'use strict';

const path = require('path');
const os = require('os');
const notifier = require('node-notifier');
const readPkgUp = require('read-pkg-up');
const stripAnsi = require('strip-ansi');
const { renderers } = require('webpack-sane-compiler-reporter');

let defaultTitle;

function getDefaultTitle() {
if (!defaultTitle) {
/* istanbul ignore next */
defaultTitle = readPkgUp.sync().pkg.name || 'Unknown project';
}

return defaultTitle;
}

function createNotifier({ title, icon, sound }) {
// On osx, omit the icon because it will be cut off in the notification center
const omitIcon = os.platform() === 'darwin';

return (message) => notifier.notify({
title,
message,
contentImage: icon,
icon: omitIcon ? undefined : icon,
sound,
});
}

function startNotifying(compiler, options) {
options = Object.assign({
title: undefined,
icon: path.join(__dirname, 'webpack-logo.png'),
sound: false,
}, options);

// Read the default title only if not set to avoid doing unnecessary I/O
options.title = options.title || getDefaultTitle();

let lastBuildSucceeded = false;
const notify = createNotifier(options);

const onError = (err) => {
lastBuildSucceeded = false;

const message = stripAnsi(renderers.error(err).trim());

notify(message);
};

const onEnd = () => {
if (!lastBuildSucceeded) {
lastBuildSucceeded = true;
notify('Build successful');
}
};

const stopNotifying = () => {
compiler
.removeListener('end', onEnd)
.removeListener('error', onError);
};

compiler
.on('error', onError)
.on('end', onEnd);

return stopNotifying;
}

module.exports = startNotifying;
Oops, something went wrong.

0 comments on commit b60a53e

Please sign in to comment.
You can’t perform that action at this time.