Browse Source

Minor improvements to logging and webpack.

pull/297/head
Sebastian 8 years ago
parent
commit
a23519a761
  1. 9
      src/Squidex.Infrastructure/Log/ConsoleLogChannel.cs
  2. 4
      src/Squidex.Infrastructure/Log/Internal/AnsiLogConsole.cs
  3. 4
      src/Squidex.Infrastructure/Log/Internal/ConsoleLogProcessor.cs
  4. 2
      src/Squidex.Infrastructure/Log/Internal/IConsole.cs
  5. 5
      src/Squidex.Infrastructure/Log/Internal/WindowsLogConsole.cs
  6. 7
      src/Squidex/Config/Domain/LoggingServices.cs
  7. 2
      src/Squidex/app-config/karma.coverage.conf.js
  8. 23
      src/Squidex/app-config/webpack.config.js
  9. 18
      src/Squidex/app-config/webpack.run.base.js
  10. 18
      src/Squidex/app-config/webpack.run.dev.js
  11. 30
      src/Squidex/app-config/webpack.run.prod.js
  12. 38
      src/Squidex/app-config/webpack.test.coverage.js
  13. 6
      src/Squidex/appsettings.json
  14. 1
      src/Squidex/package.json

9
src/Squidex.Infrastructure/Log/ConsoleLogChannel.cs

@ -13,6 +13,12 @@ namespace Squidex.Infrastructure.Log
public sealed class ConsoleLogChannel : ILogChannel, IDisposable
{
private readonly ConsoleLogProcessor processor = new ConsoleLogProcessor();
private readonly bool useColors;
public ConsoleLogChannel(bool useColors = false)
{
this.useColors = useColors;
}
public void Dispose()
{
@ -23,6 +29,8 @@ namespace Squidex.Infrastructure.Log
{
var color = 0;
if (useColors)
{
if (logLevel == SemanticLogLevel.Warning)
{
color = 0xffff00;
@ -31,6 +39,7 @@ namespace Squidex.Infrastructure.Log
{
color = 0xff0000;
}
}
processor.EnqueueMessage(new LogMessageEntry { Message = message, Color = color });
}

4
src/Squidex.Infrastructure/Log/Internal/AnsiLogConsole.cs

@ -18,6 +18,10 @@ namespace Squidex.Infrastructure.Log.Internal
this.logToStdError = logToStdError;
}
public void Reset()
{
}
public void WriteLine(int color, string message)
{
if (color != 0 && logToStdError)

4
src/Squidex.Infrastructure/Log/Internal/ConsoleLogProcessor.cs

@ -86,6 +86,10 @@ namespace Squidex.Infrastructure.Log.Internal
{
Debug.WriteLine($"Failed to shutdown log queue grateful: {ex}.");
}
finally
{
console.Reset();
}
}
}
}

2
src/Squidex.Infrastructure/Log/Internal/IConsole.cs

@ -10,5 +10,7 @@ namespace Squidex.Infrastructure.Log.Internal
public interface IConsole
{
void WriteLine(int color, string message);
void Reset();
}
}

5
src/Squidex.Infrastructure/Log/Internal/WindowsLogConsole.cs

@ -18,6 +18,11 @@ namespace Squidex.Infrastructure.Log.Internal
this.logToStdError = logToStdError;
}
public void Reset()
{
Console.ResetColor();
}
public void WriteLine(int color, string message)
{
if (color != 0)

7
src/Squidex/Config/Domain/LoggingServices.cs

@ -42,6 +42,13 @@ namespace Squidex.Config.Domain
.As<IInitializable>();
}
var useColors = config.GetValue<bool>("logging:colors");
if (console == null)
{
console = new ConsoleLogChannel(useColors);
}
services.AddSingletonAs(console)
.As<ILogChannel>();

2
src/Squidex/app-config/karma.coverage.conf.js

@ -1,4 +1,4 @@
var webpackConfig = require('./webpack.test');
var webpackConfig = require('./webpack.test.coverage');
module.exports = function (config) {
var _config = {

23
src/Squidex/app-config/webpack.config.js

@ -1,10 +1,14 @@
var webpack = require('webpack'),
const webpack = require('webpack'),
path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'),
helpers = require('./helpers');
const plugins = {
// https://github.com/webpack-contrib/mini-css-extract-plugin
MiniCssExtractPlugin: require('mini-css-extract-plugin'),
// https://github.com/dividab/tsconfig-paths-webpack-plugin
TsconfigPathsPlugin: require('tsconfig-paths-webpack-plugin')
};
module.exports = {
/**
* Options affecting the resolving of modules.
@ -25,7 +29,7 @@ module.exports = {
],
plugins: [
new TsconfigPathsPlugin()
new plugins.TsconfigPathsPlugin()
]
},
@ -83,7 +87,7 @@ module.exports = {
}, {
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
plugins.MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
}]
@ -100,6 +104,13 @@ module.exports = {
},
plugins: [
/*
* Puts each bundle into a file and appends the hash of the file to the path.
*
* See: https://github.com/webpack-contrib/mini-css-extract-plugin
*/
new plugins.MiniCssExtractPlugin('[name].css'),
new webpack.LoaderOptionsPlugin({
options: {
tslint: {

18
src/Squidex/app-config/webpack.run.base.js

@ -1,9 +1,12 @@
 var webpack = require('webpack'),
const webpack = require('webpack'),
webpackMerge = require('webpack-merge'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
commonConfig = require('./webpack.config.js'),
helpers = require('./helpers');
const plugins = {
HtmlWebpackPlugin: require('html-webpack-plugin')
};
module.exports = webpackMerge(commonConfig, {
/**
* The entry point for the bundle
@ -17,21 +20,14 @@ module.exports = webpackMerge(commonConfig, {
},
plugins: [
/**
* Simplifies creation of HTML files to serve your webpack bundles.
* This is especially useful for webpack bundles that include a hash in the filename
* which changes every compilation.
*
* See: https://github.com/ampedandwired/html-webpack-plugin
*/
new HtmlWebpackPlugin({
new plugins.HtmlWebpackPlugin({
hash: true,
chunks: ['shims', 'app'],
chunksSortMode: 'manual',
template: 'wwwroot/index.html'
}),
new HtmlWebpackPlugin({
new plugins.HtmlWebpackPlugin({
template: 'wwwroot/theme.html', hash: true, chunksSortMode: 'none', filename: 'theme.html'
})
]

18
src/Squidex/app-config/webpack.run.dev.js

@ -1,5 +1,4 @@
 var webpackMerge = require('webpack-merge'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
const webpackMerge = require('webpack-merge'),
runConfig = require('./webpack.run.base.js'),
helpers = require('./helpers');
@ -8,6 +7,7 @@ module.exports = webpackMerge(runConfig, {
output: {
filename: '[name].js',
// Set the public path, because we are running the website from another port (5000)
publicPath: 'http://localhost:3000/'
},
@ -37,20 +37,10 @@ module.exports = webpackMerge(runConfig, {
}
]
},
plugins: [
/*
* Puts each bundle into a file and appends the hash of the file to the path.
*
* See: https://github.com/webpack-contrib/mini-css-extract-plugin
*/
new MiniCssExtractPlugin('[name].css'),
],
devServer: {
historyApiFallback: true, stats: 'minimal',
headers: {
'Access-Control-Allow-Origin': '*'
}
},
historyApiFallback: true
}
});

30
src/Squidex/app-config/webpack.run.prod.js

@ -1,10 +1,15 @@
 var webpack = require('webpack'),
const webpack = require('webpack'),
webpackMerge = require('webpack-merge'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
ngToolsWebpack = require('@ngtools/webpack'),
runConfig = require('./webpack.run.base.js'),
helpers = require('./helpers');
const plugins = {
// https://www.npmjs.com/package/@ngtools/webpack
NgToolsWebpack: require('@ngtools/webpack'),
// https://github.com/webpack-contrib/mini-css-extract-plugin
MiniCssExtractPlugin: require('mini-css-extract-plugin'),
};
helpers.removeLoaders(runConfig, ['scss', 'ts']);
module.exports = webpackMerge(runConfig, {
@ -57,9 +62,9 @@ module.exports = webpackMerge(runConfig, {
* See: https://github.com/webpack-contrib/extract-text-webpack-plugin
*/
use: [
MiniCssExtractPlugin.loader,
plugins.MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
loader: 'css-loader', options: { minimize: true },
}, {
loader: 'sass-loader'
}],
@ -85,16 +90,11 @@ module.exports = webpackMerge(runConfig, {
},
plugins: [
/*
* Puts each bundle into a file and appends the hash of the file to the path.
*
* See: https://github.com/webpack-contrib/mini-css-extract-plugin
*/
new MiniCssExtractPlugin('[name].css'),
new ngToolsWebpack.AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: 'app/app.module#AppModule'
new plugins.NgToolsWebpack.AngularCompilerPlugin({
entryModule: 'app/app.module#AppModule',
sourceMap: false,
skipSourceGeneration: false,
tsConfigPath: './tsconfig.json'
})
]
});

38
src/Squidex/app-config/webpack.test.coverage.js

@ -0,0 +1,38 @@
var webpackMerge = require('webpack-merge'),
path = require('path'),
helpers = require('./helpers'),
testConfig = require('./webpack.test.js');
helpers.removeLoaders(testConfig, ['ts']);
module.exports = webpackMerge(testConfig, {
module: {
/**
* An array of Rules which are matched to requests when modules are created.
*
* See: https://webpack.js.org/configuration/module/#module-rules
*/
rules: [
{
test: /\.ts$/,
use: [{
loader: 'awesome-typescript-loader'
}],
include: [/\.(e2e|spec)\.ts$/],
}, {
test: /\.ts$/,
use: [{
loader: 'istanbul-instrumenter-loader'
},{
loader: 'awesome-typescript-loader'
}, {
loader: 'angular2-router-loader'
}, {
loader: 'angular2-template-loader'
}],
exclude: [/\.(e2e|spec)\.ts$/]
}
]
}
});

6
src/Squidex/appsettings.json

@ -53,7 +53,11 @@
/*
* Setting the flag to true, enables well formatteds json logs.
*/
"human": true
"human": true,
/*
* Set to true, to use colors.
*/
"colors": true
},
"assetStore": {

1
src/Squidex/package.json

@ -9,6 +9,7 @@
"test:coverage": "karma start karma.coverage.conf.js",
"test:clean": "rimraf _test-output",
"dev": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000",
"start": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000",
"build": "webpack --config app-config/webpack.run.prod.js",
"build:copy": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/",
"build:clean": "rimraf wwwroot/build",

Loading…
Cancel
Save