Hello Word

Generate hello Bundle :

Command console to Generate new bundle : generate:bundle nameBundle path

$ ./nodefony generate:bundle helloBundle src/bundles
   _   _    ___    ____    _____   _____    ___    _   _  __   __
  | \ | |  / _ \  |  _ \  | ____| |  ___|  / _ \  | \ | | \ \ / /
  |  \| | | | | | | | | | |  _|   | |_    | | | | |  \| |  \ V /
  | |\  | | |_| | | |_| | | |___  |  _|   | |_| | | |\  |   | |
  |_| \_|  \___/  |____/  |_____| |_|      \___/  |_| \_|   |_|

  Version : 3.0.0-beta Platform : darwin Process : nodefony PID : 21397

  NODEFONY CONSOLE Cluster : master Environment : prod Debug :false
  __ _    ___   _ __     ___   _ __    __ _  | |_    ___
   / _` |  / _ \ | '_ \   / _ \ | '__|  / _` | | __|  / _ \
  | (_| | |  __/ | | | | |  __/ | |    | (_| | | |_  |  __/
   \__, |  \___| |_| |_|  \___| |_|     \__,_|  \__|  \___|
   |___/

Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : GENERATE bundle : helloBundle LOCATION : /Users/cci/repository/nodefony-core/src/bundles
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :helloBundle
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :Command
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :controller
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :defaultController.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :services
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :tests
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :helloBundleTest.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :Resources
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :config
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :config.yml
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :routing.yml
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :webpack
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :webpack.common.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :webpack.dev.config.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :webpack.prod.config.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :security.yml
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :public
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :hello.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :css
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :hello.css
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :images
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :assets
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :css
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :fonts
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :images
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :translations
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :views
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :index.html.twig
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :doc
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :1.0
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :readme.md
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create symbolic link :Default
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :core
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create Directory :Entity
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :helloBundle.js
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create symbolic link :readme.md
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : Create File      :package.json
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : INSTALL ASSETS LINK IN WEB PUBLIC DIRECTORY  : /Users/cci/repository/nodefony-core/web/
Thu Aug 03 2017 12:03:44 INFO SERVICE CLI KERNEL  : INSTALL LINK IN /web TOTAL SIZE : 2.6 MB
┌─────────┬───────────────────┬────────────────────────────────────────────┬───────────┬────────────────┐
│ BUNDLES │ DESTINATION PATH  │ SOURCE PATH                                │ SIZE      │ ASSETS COMPILE │
├─────────┼───────────────────┼────────────────────────────────────────────┼───────────┼────────────────┤
│ hello   │ ./web/helloBundle │ ./src/bundles/helloBundle/Resources/public │ 483 bytes │ 0 bytes        │
└─────────┴───────────────────┴────────────────────────────────────────────┴───────────┴────────────────┘
Thu Aug 03 2017 12:03:44 INFO CONSOLE   : NODEFONY Kernel Life Cycle Terminate CODE : 0

AUTO REGISTRATION :

The bundle generation engine auto registre generated bundle in framework :
During the generation of a bundle nodefony uses a temporary yml file ./config/generatedConfig.yml

./config/generatedConfig.yml
system:
  bundles:
  hello: src/bundles/helloBundle

If the bundle is to be used in a durable way It is preferable to register the bundles in framework config file : ./config/config.yml

./config/config.yml
system:
  bundles:
  demo: src/bundles/helloBundle

Generated VIEW :

src/bundles/helloBundle/Resources/views/index.html.twig
{% extends '/app/Resources/views/base.html.twig' %}

{% block title %}Welcome {{kernel.name}}! {% endblock %}

{% block stylesheets %}

  {{ parent() }}

  <!-- WEBPACK BUNDLE -->
  <link rel='stylesheet' href='{{CDN("stylesheet")}}/helloBundle/assets/css/hello.css' />

{% endblock %}

{% block body %}
  <div class='container'>
  <div class='row'>
  {{readme}}
  </div>
  </div>
{% endblock %}

{% block javascripts %}

  {{ parent() }}

  <!-- WEBPACK BUNDLE -->
  <script src='{{CDN("javascript")}}/helloBundle/assets/js/hello.js'></script>

{% endblock %}

Generated Controller :

src/bundles/helloBundle/controller/defaultController.js
module.exports = class defaultController extends nodefony.controller {

  constructor (container, context){
    super(container, context);
  }

  /**
  *
  *	@method indexAction
  *
  */
  indexAction (){
    try {
      return this.render("helloBundle::index.html.twig",{name:"default"});
    }catch(e){
      throw e;
    }
  }
};

WATCHER FILES DURING DEVELOPMENT :

The bundle generation engine build bundle config with node.js watcher configuration
In developement mode is very usefull to auto-reload files as controllers , views , routing , translations
without having to reboot the server.

./src/bundles/helloBundle/Resources/config/config.yml
  #
  #  WATCHERS
  #
  #    watchers Listen to changes, deletion, renaming of files and directories
  #    of different components
  #
  #    For watch all components
  #
  #      watch:			true       # services false by default
  #    or
  #      watch:
  #        controller     : true
  #        config         : true		# only  routing
  #        views          : true
  #        translations   : true
  #        webpack        : true
  #        services       : true

  watch       : true

WEBPACK MODULE BUNDLER :

The bundle generation engine build bundle config with a predefined webpack configurations
In this way webpack is very usefull to manage all assets of bundle
In developement mode watch is very usefull to auto-compile webpack module bundle
without having to reboot the server.

./src/bundles/helloBundle/Resources/config/webpack.config.js
  const path = require("path");
  const public = path.resolve(__dirname, "..", "public");
  const bundleName = path.basename(path.resolve(__dirname, "..", ".."));
  const ExtractTextPluginCss = require('extract-text-webpack-plugin');
  const webpackMerge = require('webpack-merge');
  let config = null;
  if (kernel.environment === "dev") {
    config = require("./webpack/webpack.dev.config.js");
  } else {
    config = require("./webpack/webpack.prod.config.js");
  }

  module.exports = webpackMerge({
    context: public,
    target: "web",
    entry       : {
      hello  : [ "./js/hello.js" ]
    },
    output: {
      path: public,
      filename: "./assets/js/[name].js",
      library: "[name]",
      libraryTarget: "umd"
    },
    externals: {},
    resolve: {},
    module: {
      rules: [{
        // BABEL TRANSCODE
        test: new RegExp("\.es6$"),
        exclude: new RegExp("node_modules"),
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }]
      }, {
        // CSS EXTRACT
        test: new RegExp("\.css$"),
        use: ExtractTextPluginCss.extract({
          use: 'css-loader'
        })
      }, {
        // SASS
        test: new RegExp(".scss$"),
        use: [{
          loader: 'style-loader'
        }, {
          loader: 'css-loader'
        }, {
          loader: 'sass-loader'
        }]
      }, {
        test: new RegExp("\.less$"),
        use: ExtractTextPluginCss.extract({
          use: [
            "raw-loader",
            {
              loader: 'less-loader',
              options: {
                //strictMath: true,
                //noIeCompat: true
              }
            }
          ]
        })
      }, {
        // FONTS
        test: new RegExp("\.(eot|woff2?|svg|ttf)([\?]?.*)$"),
        use: 'file-loader?name=[name].[ext]&publicPath=/' + bundleName + '&outputPath=/assets/fonts/',
      }, {
        // IMAGES
        test: new RegExp("\.(jpg|png|gif)$"),
        use: 'file-loader?name=[name].[ext]&publicPath=/' + bundleName + '&outputPath=/assets/images/'
      }]
    },
    plugins: [
      new ExtractTextPluginCss({
        filename: "./assets/css/[name].css",
      })
    ]
  }, config);
./src/bundles/helloBundle/Resources/config/webpack/webpack.dev.config.js
  module.exports = {
    devtool: "source-map",
    resolve: {},
    plugins: []
  };

Start Nodefony to check new Bundle hello:

-d for debug mode
$ ./nodefony -d dev
 or
$ ./nodefony dev
Access to bundle route with URL : http://nodefony.com:5151/hello