stroring config settings in a file

This commit is contained in:
Kononnable 2019-01-26 13:48:12 +01:00
parent aa37ba086e
commit 21ec046139
2 changed files with 33 additions and 8 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ coverage/
dist
*.tgz
!gulpfile.js
.tomg-config

View File

@ -17,15 +17,25 @@ async function CliLogic() {
let connectionOptions: IConnectionOptions;
let generationOptions: IGenerationOptions;
if (process.argv.length > 2) {
const retval = GetUtilParametersByArgs();
driver = retval.driver;
connectionOptions = retval.connectionOptions;
generationOptions = retval.generationOptions;
const retVal = GetUtilParametersByArgs();
connectionOptions = retVal.connectionOptions;
generationOptions = retVal.generationOptions;
driver = retVal.driver;
} else {
const retval = await GetUtilParametersByInquirer();
driver = retval.driver;
connectionOptions = retval.connectionOptions;
generationOptions = retval.generationOptions;
if (fs.existsSync(path.resolve(process.cwd(), ".tomg-config"))) {
const retVal = await fs.readJson(
path.resolve(process.cwd(), ".tomg-config")
);
connectionOptions = retVal[0];
generationOptions = retVal[1];
generationOptions.namingStrategy = new NamingStrategy(); // TODO: For now there is no way to store custom naming strategy
driver = createDriver(connectionOptions.databaseType);
} else {
const retVal = await GetUtilParametersByInquirer();
driver = retVal.driver;
connectionOptions = retVal.connectionOptions;
generationOptions = retVal.generationOptions;
}
}
console.log(TomgUtils.packageVersion());
console.log(
@ -404,5 +414,19 @@ async function GetUtilParametersByInquirer() {
generationOptions.convertCaseEntity = namingConventions.entityCase;
}
}
const saveConfig = ((await inquirer.prompt([
{
default: true,
message: "Save configuration to config file?",
name: "saveConfig",
type: "confirm"
}
])) as any).saveConfig;
if (saveConfig) {
await fs.writeJson(path.resolve(process.cwd(), ".tomg-config"), [
connectionOptions,
generationOptions
]);
}
return { driver, connectionOptions, generationOptions };
}