{"size": 2024, "ext": "js", "max_stars_repo_path": "templates/digit.js", "max_stars_repo_name": "tejaede/minit", "max_stars_repo_stars_event_min_datetime": "2015-01-28T01:53:52.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-14T11:57:57.000Z", "max_issues_repo_path": "templates/digit.js", "max_issues_repo_name": "tejaede/minit", "max_issues_repo_issues_event_min_datetime": "2015-02-03T19:06:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-28T18:27:11.000Z", "max_forks_repo_path": "templates/digit.js", "max_forks_repo_name": "tejaede/minit", "max_forks_repo_forks_event_min_datetime": "2015-01-28T01:53:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-22T12:19:43.000Z"}
{"max_stars_count": 5, "max_issues_count": 25, "max_forks_count": 13, "avg_line_length": 30.6666666667, "max_line_length": 106, "alphanum_fraction": 0.5597826087}
var PackageTemplate = require("./package").Template;
var ArgumentError = require("../lib/error.js").ArgumentError;
var fs = require('fs');
var removeDiacritics = require("diacritics").remove;

var _fromCamelToDashes = function(name) {
    var s1 = name.replace(/([A-Z])/g, function (g) { return "-"+g.toLowerCase(); });
    s1 = s1.replace(/--/g, "-").replace(/^-/, "");
    return s1;
};
var _fromDashesToCamel = function(name) {
    var s1 = name.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
    s1 = s1[0].toUpperCase() + s1.slice(1);
    return s1;
};
exports.Template = Object.create(PackageTemplate, {

    commandDescription: {
        value: "application"
    },

    addOptions: {
        value:function (command) {
            command = PackageTemplate.addOptions.call(this, command);
            command.option('-n, --name <name>', 'application name (required)');
            command.option('-c, --copyright [path]', 'copyright file');
            return command;
        }
    },

    didSetOptions: {
        value:function (options) {
            if (options.name) {
                options.name = this.validateName(options.name);
            } else {
                throw new ArgumentError("Required name option missing");
            }
            if (options.copyright) {
                options.copyright = this.validateCopyright(options.copyright);
            }
        }
    },

    validateName: {
        value: function(name) {
            name = name.replace(/ /g, "-");
            // convert to camelcase
            name =  _fromDashesToCamel(name);
            // convert back from camelcase to dashes and ensure names are safe to use as npm package names
            return removeDiacritics(_fromCamelToDashes(name));
        }
    },

    validateCopyright: {
        value: function(path) {
            return fs.readFileSync(path, "utf-8");
        }
    },

    defaultPackageHome: {
        value: function () {
            return process.cwd();
        }
    }
});
