"use strict";

require ('./useless')

$singleton (Component, {

    $defaults: {
        runCodeBaseTests: false
    },

    api () {
        return {
            '/': this.template.$ ('./hmr-test/index.html') } },

    $depends: [
        
        require ('./server/supervisor'),
        require ('./server/templating'),
        require ('./server/devtools'),
        require ('./server/uptime')

    ],

    erroneousMethod () {
        unknownFunction () },
                                        
    init () {

        log.green ('Example app is running at http://localhost:1333')

        const webpack       = require ('webpack')
        const WebpackServer = require ('webpack-dev-server')
      
        const compiler = webpack ({

            entry: [
                'webpack-dev-server/client?http://localhost:3000',
                'webpack/hot/only-dev-server',
                '/Users/mac/useless/hmr-test/index.js'
            ],

            output: {   filename: 'index.js',
                        path: '/Users/mac/useless/build/',
                        publicPath: 'http://localhost:3000/',
                        hotUpdateChunkFilename: 'hot/[id].[hash].hot-update.js',
                        hotUpdateMainFilename: 'hot/[hash].hot-update.json' },

            plugins: [new webpack.HotModuleReplacementPlugin ()],

            module: {
                loaders: [

                    { test: /\.css$/,
                      loader: 'style!css?-url'
                    }
                ]
            },
        })

        const webpackServer = new WebpackServer (compiler, {

            publicPath: 'http://localhost:3000/',
            hot: true,
            quiet: false,
            noInfo: false,
            progress: true,
            stats: {
                assets: true,
                colors: true,
                version: false,
                hash: false,
                timings: true,
                chunks: false,
                chunkModules: false
            }

        }).listen (3000, 'localhost', (err, result) => {

            if (err) {
                log ('Webpack error:', err) }

            else {
                log.ok ('Webpack HotReload server is running') }
        })

    }
})
