/**
 * @overview generator for directories and files of a new component
 * @author Manfred Kaul <manfred.kaul@h-brs.de> 2017
 * @license The MIT License (MIT)
 */

var fs = require('fs');
var path = require('path');

var component_name = 'learning_app';

var index_html = `<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://mkaul.github.io/ccm-components/${component_name}/ccm.${component_name}.js"></script>
<script src="ccm.${component_name}.js"></script>
<ccm-${component_name}></ccm-${component_name}>`;

var ccm_component = `/**
 * @overview ccm component for ${component_name}
 * @author Manfred Kaul <manfred.kaul@h-brs.de> 2017
 * @license The MIT License (MIT)
 */

( function () {

  var ccm_version = '9.0.0';
  var ccm_url     = 'https://akless.github.io/ccm/ccm.js';

  var component_name = '${component_name}';
  var component_obj  = {

    name: component_name,

    config: {
      html: {
        main: {
          inner: [
            { tag: 'button', class: 'left', inner: '%even%' },
          ]
        }
      },
      css: [ 'ccm.load',  'https://mkaul.github.io/ccm-components/${component_name}/resources/default.css' ],
      // user:   [ 'ccm.instance', 'https://akless.github.io/ccm-components/user/versions/ccm.user-1.0.0.min.js' ],
      // logger: [ 'ccm.instance', 'https://akless.github.io/ccm-components/log/versions/ccm.log-1.0.0.min.js', [ 'ccm.get', 'https://akless.github.io/ccm-components/log/resources/log_configs.min.js', 'greedy' ] ],
      // onfinish: function( instance, results ){ console.log( results ); }
    },

    Instance: function () {
    
      var self = this;

      this.start = function ( callback ) {
      
        // has logger instance? => log 'render' event
        if ( self.logger ) self.logger.log( 'render' );
        
        // prepare main HTML structure
        var main_elem = self.ccm.helper.html( self.html.main, { even: 'even' } );
        
        // select inner containers (mostly for buttons)
        var left_button = main_elem.querySelector( 'button.left' );
        
        // set content of own website area
        self.ccm.helper.setContent( self.element, main_elem );

        if ( callback ) callback();
      };

    }

  };

  var namespace = window.ccm && ccm.components[ component_name ]; if ( namespace ) { if ( namespace.ccm_version ) ccm_version = namespace.ccm_version; if ( namespace.ccm_url ) ccm_url = namespace.ccm_url; }
  if ( !window.ccm || !ccm[ ccm_version ] ) { var tag = document.createElement( 'script' ); document.head.appendChild( tag ); tag.onload = register; tag.src = ccm_url; } else register();
  function register() { ccm[ ccm_version ].component( component_obj ); }
}() );`;

var default_css = `/**
 * @overview default layout of ccm component ${component_name}
 * @author Manfred Kaul <manfred.kaul@h-brs.de> 2017
 * @license The MIT License (MIT)
 */`;

fs.mkdir(path.join('..' + path.sep + component_name), function (err1) {
  if (err1) throw err1;
  console.log( 'Dir ' + component_name + '/ created.' );
  
  fs.writeFile('..' + path.sep + component_name + path.sep + 'index.html', index_html, 'utf8', function (err2) {
      if (err2) throw err2;
      console.log('index.html created.');
  });
  
  fs.writeFile('..' + path.sep + component_name + path.sep + 'ccm.' + component_name + '.js', ccm_component, 'utf8', function (err3) {
      if (err3) throw err3;
      console.log('ccm.' + component_name + '.js created.');
    });
  
  fs.mkdir(path.join('..' + path.sep + component_name + path.sep + 'resources'), function (err4) {
    if (err4) throw err4;
    console.log('Dir resources/ created.');
  
    fs.writeFile('..' + path.sep + component_name + path.sep + 'resources' + path.sep + 'default.css', default_css, 'utf8', function (err5) {
        if (err5) throw err5;
        console.log('default.css created.');
      });
    
  });
});
@@ -236,78 +236,253 @@
  = '
-learning_app';%0A%0Avar index_html = %60%3C!DOCTYPE html%3E%0A%3Cmeta charset=%22utf-8
+fine_upload';%0Avar author = 'Manfred Kaul %3Cmanfred.kaul@h-brs.de%3E 2017';%0Avar account = 'mkaul';%0A%0Avar index_html = %60%3C!DOCTYPE html%3E%0A%3Cmeta charset=%22utf-8%22%3E%0A%3Cmeta name=%22author%22 content=%22$%7Bauthor%7D%22%3E%0A%3Cmeta name=%22license%22 content=%22The MIT License (MIT)
 %22%3E%0A%3C
@@ -493,37 +493,42 @@
 pt src=%22https://
-mkaul
+$%7Baccount%7D
 .github.io/ccm-c
@@ -780,49 +780,17 @@
 hor 
-Manfred Kaul %3Cmanfred.kaul@h-brs.de%3E 2017
+$%7Bauthor%7D
 %0A * 
@@ -1216,21 +1216,82 @@
 ,  '
-https://mkaul
+resources/default.css' %5D,%0A      // css: %5B 'ccm.load',  'https://$%7Baccount%7D
 .git
@@ -3004,49 +3004,17 @@
 hor 
-Manfred Kaul %3Cmanfred.kaul@h-brs.de%3E 2017
+$%7Bauthor%7D
 %0A * 

add more parameters in component maker