<commit_before>const fs = require('fs');
const ejs = require('ejs');
const utils = require('./utils.js');

var inquirer = require('inquirer');

var logDetail = (str) => {
	console.log("    - "+str);
}
var ar = __dirname.split("/");
var rootPath = ar.splice(0, ar.length-1).join("/");

const modelPath = '/app/models';
const contPath = '/app/controllers';
const viewsPath = '/app/views';

var model = {};
var path = "";

// begin method
var getEnv = (cb) =>{
	utils.checkPath(process.cwd(), "/config", (err, pathChk) => {
		if(err){
			cb(true);
			return;
		}
		path = pathChk;
		cb(false)
	});	
}

function randString(totalLength){
	var text = "";
	var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%";

	for( var i=0; i < totalLength; i++ )
		text += possible.charAt(Math.floor(Math.random() * possible.length));

	return text;
}
var autoGenerateKeyPhase = (cb)=>{
	var keyphase = randString(8);
	var authConf = path+"/config/keyphase.json";
	var txt = JSON.stringify({keyphase:keyphase}, 0, 4);
	fs.writeFile(authConf, txt, (err) => {
		if(err){
			logDetail("generate keyphase ["+keyphase+"] fails.")
			logDetail(err);
			cb(true);
			return;
		}
		logDetail("generate keyphase ["+keyphase+"] completed.")
		cb(false)
	});
}

var askMore = (model, cb) => {
	var questions = [{
		type: 'input',
		name: 'fieldName',
		message: 'What\'s your field name?',
	},{
		type: 'list',
		name: 'fieldType',
		message: 'What Schema Type of field name?',
		choices: ['String', 'Date']
	},{
		type: 'confirm',
		name: 'addMore',
		message: 'insert More ?',
		default: false
	}];

	inquirer.prompt(questions).then(function (answers) {
		model.fields.push({
			fieldName:answers.fieldName,
			typeName:answers.fieldType
		});
		if(answers.addMore == true)
			askMore(model, cb);
		else
			cb(false);		
	});
}

var askModelLoginName = (cb) =>{
	var questions = [{
		type: 'input',
		name: 'modelName',
		message: 'What\'s your login model name?',
	},{
		type: 'confirm',
		name: 'addMore',
		message: 'insert More ?',
		default: false
	}];
	inquirer.prompt(questions).then(function (answers) {
		// initial model name
		model.modelName = answers.modelName;
		model.fields.push({
			fieldName:"username",
			typeName:"String"
		});
		model.fields.push({
			fieldName:"password",
			typeName:"String"
		});	
		if(answers.addMore == true)
			askMore(model, cb);<commit_msg>add role_id<commit_after>const fs = require('fs');
const ejs = require('ejs');
const utils = require('./utils.js');

var inquirer = require('inquirer');

var logDetail = (str) => {
	console.log("    - "+str);
}
var ar = __dirname.split("/");
var rootPath = ar.splice(0, ar.length-1).join("/");

const modelPath = '/app/models';
const contPath = '/app/controllers';
const viewsPath = '/app/views';

var model = {};
var path = "";

// begin method
var getEnv = (cb) =>{
	utils.checkPath(process.cwd(), "/config", (err, pathChk) => {
		if(err){
			cb(true);
			return;
		}
		path = pathChk;
		cb(false)
	});	
}

function randString(totalLength){
	var text = "";
	var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%";

	for( var i=0; i < totalLength; i++ )
		text += possible.charAt(Math.floor(Math.random() * possible.length));

	return text;
}
var autoGenerateKeyPhase = (cb)=>{
	var keyphase = randString(8);
	var authConf = path+"/config/keyphase.json";
	var txt = JSON.stringify({keyphase:keyphase}, 0, 4);
	fs.writeFile(authConf, txt, (err) => {
		if(err){
			logDetail("generate keyphase ["+keyphase+"] fails.")
			logDetail(err);
			cb(true);
			return;
		}
		logDetail("generate keyphase ["+keyphase+"] completed.")
		cb(false)
	});
}

var askMore = (model, cb) => {
	var questions = [{
		type: 'input',
		name: 'fieldName',
		message: 'What\'s your field name?',
	},{
		type: 'list',
		name: 'fieldType',
		message: 'What Schema Type of field name?',
		choices: ['String', 'Date']
	},{
		type: 'confirm',
		name: 'addMore',
		message: 'insert More ?',
		default: false
	}];

	inquirer.prompt(questions).then(function (answers) {
		model.fields.push({
			fieldName:answers.fieldName,
			typeName:answers.fieldType
		});
		if(answers.addMore == true)
			askMore(model, cb);
		else
			cb(false);		
	});
}

var askModelLoginName = (cb) =>{
	var questions = [{
		type: 'input',
		name: 'modelName',
		message: 'What\'s your login model name?',
	},{
		type: 'confirm',
		name: 'addMore',
		message: 'insert More ?',
		default: false
	}];
	inquirer.prompt(questions).then(function (answers) {
		// initial model name
		model.modelName = answers.modelName;
		model.fields.push({
			fieldName:"username",
			typeName:"String"
		});
		model.fields.push({
			fieldName:"password",
			typeName:"String"
		});	
		model.fields.push({
			fieldName:"user_role",
			typeName:"Number"
		});	
		if(answers.addMore == true)
			askMore(model, cb);
{'fraction_non_alphanumeric': 0.18788627935723115, 'fraction_numerical': 0.006592501030078286, 'mean_word_length': 4.01031991744066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5800945', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1775, 'n_words': 383}