#!/usr/bin/env node

const program = require("commander");
const utils = require("./utils");

program
    .usage("<appName> [options]")
    .arguments("<app-name>")
    .action(function (appName) {
        cmdAppName = appName;
    })
    .option("-o, --out <output-folder>", "Specifies the output (build) folder of the project. Defaults to wwwroot")
    .option("-s, --src <src-folder>", "Specifies the name of the folder that will hold all source files. Defaults to src.")
    //.option("--use-bower", "Enables Bower usage in the project, otherwise it will use only NPM.")
    .parse(process.argv);

if (typeof cmdAppName === "undefined") {
    console.log("You must specify an app name.");
    process.exit(1);
}

cmdAppName = utils.camelCase(cmdAppName);
program.out = utils.camelCase(program.out) || "wwwroot";
program.src = utils.camelCase(program.src) || "src";
program.useBower = program.useBower || false;

var vals = {
    hAppName: utils.hyphenate(cmdAppName),
    pAppName: utils.pascalCase(cmdAppName),
    srcFolder: utils.hyphenate(program.src),
    appName: cmdAppName,
    outFolder: program.out,
    noBower: program.useBower
};

var appTpls = utils.readTemplates("app");
var srcTpls = utils.readTemplates("app/src");
var decoratorTpls = utils.readTemplates("app/src/decorators");
var servicesTpls = utils.readTemplates("app/src/services");
var stylesTpls = utils.readTemplates("app/src/styles");

appTpls = utils.compileTemplates(appTpls, vals, cmdAppName);
srcTpls = utils.compileTemplates(srcTpls, vals, cmdAppName);
decoratorTpls = utils.compileTemplates(decoratorTpls, null, cmdAppName);
stylesTpls = utils.compileTemplates(stylesTpls, vals, cmdAppName);

var servicesCompiledTpls = {};
for (var i in servicesTpls) {
    if (i === "_base.service.ts") {
        servicesCompiledTpls[i.replace("_", "")] = servicesTpls[i];
    } else {
        var tpl = {};
        tpl[i.replace("_", "")] = servicesTpls[i];
        servicesTpls = utils.extend(servicesCompiledTpls, utils.compileTemplates(tpl, vals, cmdAppName));
    }
}

/*utils.writeFiles(appTpls);
utils.writeFiles(srcTpls, program.src.concat("/"));*/
utils.writeFiles(decoratorTpls, program.src.concat("/decorators/"));
console.log(decoratorTpls)
@@ -85,16 +85,756 @@
 utils%22);
+%0Aconst path = require(%22path%22);%0Avar rootPath = %22%22;%0A%0Afunction writeFolders(folderPath, folders) %7B%0A    const fs = require(%22fs%22);%0A%0A    var folders = folders %7C%7C folderPath.split(path.sep);%0A    var childFolders = folderPath.replace(rootPath, %22%22);%0A    childFolders = childFolders.split(path.sep);%0A    childFolders = childFolders.slice(0, childFolders.length -1);%0A%0A    try %7B%0A        var contents = fs.readdirSync(folderPath);%0A    %7D catch (e) %7B%0A        if (e.code === %22ENOENT%22) %7B%0A            if (rootPath !== folderPath) %7B%0A                writeFolders(path.join(rootPath, childFolders.join(%22/%22)), childFolders);%0A            %7D%0A            console.log(%22Creating directory: %22.concat(folderPath));%0A            fs.mkdirSync(folderPath);%0A        %7D%0A    %7D%0A%7D
 %0A%0Aprogra
@@ -2782,10 +2782,8 @@
 %0A%7D%0A%0A
-/*
 util
@@ -2809,94 +2809,311 @@
 s);%0A
-utils.writeFiles(srcTpls, program.src.concat(%22/%22));*/%0Autils.writeFiles(decoratorTpls, 
+rootPath = utils.getRootPath();%0AwriteFolders(path.join(rootPath, program.src.concat(%22/decorators%22)));%0AwriteFolders(path.join(rootPath, program.src.concat(%22/services%22)));%0AwriteFolders(path.join(rootPath, program.src.concat(%22/styles%22)));%0Autils.writeFile(program.src.concat(%22/%22), srcTpls);%0Autils.writeFile(
 prog
@@ -3143,36 +3143,147 @@
 tors
-/
 %22)
-);%0Aconsole.log(decorator
+, decoratorTpls);%0Autils.writeFile(program.src.concat(%22/services%22), servicesTpls);%0Autils.writeFile(program.src.concat(%22/styles%22), styles
 Tpls)
+;

Enable ngts app command