only write config if file does not already exist

This commit is contained in:
Niels Lyngsø
2020-09-25 11:50:57 +02:00
parent 78724c11eb
commit b46dad39ff
3 changed files with 26 additions and 8 deletions

View File

@@ -1,17 +1,21 @@
const prompt = require('prompt');
fs = require('fs');
const fs = require('fs');
const properties = [
{
name: 'superadmin username/email'
name: 'username'
},
{
name: 'superadmin password',
name: 'password',
hidden: true
}
];
console.log("Configure your test enviroment:")
const configPath = './cypress.env.json'
console.log("Configure your test enviroment")
console.log("Enter CMS superadmin credentials:")
prompt.start();
@@ -23,10 +27,10 @@ var fileContent = `{
"password": "${result.password}"
}`;
fs.writeFile('cypress.env.json', fileContent, function (error) {
fs.writeFile(configPath, fileContent, function (error) {
if (error) return console.error(error);
console.log('Configuration saved');
});
});
});
function onError(error) {

View File

@@ -1,7 +1,7 @@
{
"scripts": {
"postinstall": "node createEnviromentConfiguration.js",
"config": "node createEnviromentConfiguration.js",
"postinstall": "node postinstall.js",
"config": "node config.js",
"test": "npx cypress run",
"ui": "npx cypress open"
},

View File

@@ -0,0 +1,14 @@
const fs = require('fs');
const configPath = './cypress.env.json';
try {
if (fs.existsSync(configPath)) {
//file exists
console.log("Skips configuration as file already exists, run 'npm run config' to change your configuration.");
} else {
require('./createEnviromentConfiguration.js');
}
} catch(err) {
console.error(err)
}