Skip to content

Commit

Permalink
Extract Logger class to own package (#151)
Browse files Browse the repository at this point in the history
* Extract Logger class to own package

* Add README.md for logger package
  • Loading branch information
valscion authored Feb 4, 2018
1 parent faf24a3 commit 15caf72
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/bundle-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm install --save @webpack-bundle-analyzer/bundle-parser

```js
const parseBundle = require('@webpack-bundle-analyzer/bundle-parser');
const Logger = require('@webpack-bundle-analyzer/plugin/lib/Logger');
const Logger = require('@webpack-bundle-analyzer/logger');

const fs = require('fs');
const webpackStats = JSON.parse(
Expand Down
16 changes: 16 additions & 0 deletions packages/logger/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Babel config for Node
// Compiles sources, gulpfile and tests
{
"presets": [
["env", {
"targets": { "node": 4 },
"exclude": [
// Node 4 supports all the generator features that we use so there is no need in Regenerator
"transform-regenerator"
]
}]
],
"plugins": [
"transform-class-properties"
]
}
59 changes: 59 additions & 0 deletions packages/logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>@webpack-bundle-analyzer/logger</h1>
<p>Logging implementation used in webpack-bundle-analyzer.</p>
</div>

<h2 align="center">Install</h2>

```bash
npm install --save @webpack-bundle-analyzer/logger
```

<h2 align="center">Usage</h2>

```js
const Logger = require('@webpack-bundle-analyzer/logger');

// Possible logging levels are 'info', 'warn', 'error' and 'silent'.
const logger = new Logger('info');

logger.info('Informative message');
logger.warn('Warning, something is not right!');
logger.error('An error happened!');
```

<h2 align="center">Options</h2>

```js
new Logger(level: LogLevel);
```

|Name|Type|Description|
|:--:|:--:|:----------|
|**`level`**|One of: `info`, `warn`, `error`, `silent`|The logging level to use. `info` displays all log messages, `warn` displays only `.warn` and `.error` logs, `error` displays only `.error` logs and `silent` displays none.|


<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/302213?v=4&s=150">
</br>
<a href="https://github.com/th0r">Yuriy Grunin</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/482561?v=4&s=150">
</br>
<a href="https://github.com/valscion">Vesa Laakso</a>
</td>
</tr>
<tbody>
</table>
32 changes: 32 additions & 0 deletions packages/logger/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const gulp = require('gulp');

const NODE_SRC = './src/**/*.js';
const NODE_DEST = './lib';

gulp.task('clean', gulp.parallel(cleanNodeScripts));
gulp.task('build', gulp.series('clean', compileNodeScripts));
gulp.task('watch', gulp.series('build', watch));
gulp.task('default', gulp.task('watch'));

function watch() {
gulp
.watch(NODE_SRC, gulp.series(cleanNodeScripts, compileNodeScripts))
// TODO: replace with `emitErrors: false` option after https://github.com/gulpjs/glob-watcher/pull/34 will be merged
.on('error', () => {});
}

function cleanNodeScripts() {
const del = require('del');
return del(NODE_DEST);
}

function compileNodeScripts() {
const babel = require('gulp-babel');

return gulp
.src(NODE_SRC)
.pipe(babel())
.pipe(gulp.dest(NODE_DEST));
}
50 changes: 50 additions & 0 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@webpack-bundle-analyzer/logger",
"version": "3.0.0-alpha.1",
"description": "Logger class used by webpack-bundle-analyzer",
"author": "Yury Grunin <[email protected]>",
"contributors": [
"Yury Grunin <[email protected]>",
"Vesa Laakso <[email protected]> (http://vesalaakso.com)"
],
"license": "MIT",
"homepage": "https://github.com/webpack-contrib/webpack-bundle-analyzer",
"changelog": "https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/CHANGELOG.md",
"bugs": {
"url": "https://github.com/webpack-contrib/webpack-bundle-analyzer/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/webpack-bundle-analyzer.git"
},
"main": "lib/index.js",
"engines": {
"node": ">= 4"
},
"scripts": {
"start": "gulp watch",
"build": "gulp build",
"test": "mocha --exit --require babel-core/register",
"test-dev": "mocha --watch --require babel-core/register"
},
"files": [
"src",
"lib"
],
"dependencies": {
},
"devDependencies": {
"babel-core": "6.26.0",
"babel-preset-env": "1.6.1",
"babel-plugin-transform-class-properties": "6.24.1",
"gulp": "4.0.0",
"gulp-babel": "7.0.1",
"mocha": "5.0.0"
},
"keywords": [
"webpack",
"bundle",
"analyzer",
"logger"
]
}
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/logger/test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../.eslintrc.json",
"env": {
"mocha": true
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Logger = require('../lib/Logger');
const { expect } = require('chai');
const Logger = require('../');

class TestLogger extends Logger {
constructor(level) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
],
"dependencies": {
"@webpack-bundle-analyzer/bundle-parser": "^3.0.0-alpha.1",
"@webpack-bundle-analyzer/logger": "^3.0.0-alpha.1",
"@webpack-bundle-analyzer/reporter-treemap": "^3.0.0-alpha.1",
"bfj-node4": "^5.2.0",
"chalk": "^2.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/BundleAnalyzerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const mkdir = require('mkdirp');
const { bold } = require('chalk');

const Logger = require('./Logger');
const Logger = require('@webpack-bundle-analyzer/logger');
const parseBundle = require('@webpack-bundle-analyzer/bundle-parser');

class BundleAnalyzerPlugin {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/bin/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _ = require('lodash');
const commander = require('commander');
const { magenta } = require('chalk');

const Logger = require('../Logger');
const Logger = require('@webpack-bundle-analyzer/logger');
const parseBundle = require('@webpack-bundle-analyzer/bundle-parser');

const program = commander
Expand Down
1 change: 1 addition & 0 deletions packages/reporter-treemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"ws": "^4.0.0"
},
"devDependencies": {
"@webpack-bundle-analyzer/logger": "^3.0.0-alpha.1",
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-transform-class-properties": "6.24.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter-treemap/test/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const crypto = require('crypto');
const net = require('net');

const Logger = require('@webpack-bundle-analyzer/plugin/lib/Logger');
const Logger = require('@webpack-bundle-analyzer/logger');
const { startServer } = require('../lib/viewer.js');

describe('WebSocket server', function () {
Expand Down

0 comments on commit 15caf72

Please sign in to comment.