UNPKG

testastra

Version:

** testastra **

95 lines (82 loc) 2.63 kB
#!/usr/bin/env node const inquirer = require("inquirer"); const chalk = require("chalk"); const figlet = require("figlet"); const shell = require("shelljs"); const fs = require("fs"); let projectData = require('./aresDashboardApi/apiData'); const init = () => { console.log(chalk.blue('Welcome to ARES. To get started please make sure project keys are available for following questions !!!')); }; const askQuestions = () => { const questions = [ { name: "PROJECT_NAME", type: "input", message: "Please enter the Project Name:" }, { name: "PROJECT_KEY", type: "input", message: "Please enter ProjectKey:" }, { name: "USER_KEY", type: "input", message: "Please enter the UserKey:" }, { name: "WORKSPACE_NAME", type: "input", message: "Please enter the workspace name (leave blank if default ws is 'zenq_default':" }, ]; return inquirer.prompt(questions); }; const createFile = (filename, extension) => { const filePath = `${process.cwd()}/${filename}.${extension}`; if (fs.existsSync(filePath)) { console.log( chalk.red.bgBlack.bold(' Key File already exists...overwriting the changes... ') ); } shell.touch(filePath); return filePath; }; const writeJsonData = (filepath, data) => { // Creates a new testBody.json with updated moduleName and runId fs.writeFile(filepath, data, 'utf8', function (err) { if (err) { return console.log(err); } }); }; const success = filepath => { console.log( chalk.green.bgBlack.bold(' JSON File has been successfully created ') ); }; const run = async () => { // show script introduction init(); // ask questions const answers = await askQuestions(); const { PROJECT_NAME, PROJECT_KEY, USER_KEY, WORKSPACE_NAME} = answers; // create the file const filePath = createFile(PROJECT_NAME.toLowerCase(), 'json'); // Appended the data to testBody projectData.json.runData.projectName = PROJECT_NAME; projectData.json.runData.projectId = PROJECT_KEY; projectData.json.runData.userToken = USER_KEY; if(WORKSPACE_NAME.length <=0 ) { projectData.json.runData.ws_name = "zenq_default" } else { projectData.json.runData.ws_name = WORKSPACE_NAME; } let data = JSON.stringify(projectData.json); writeJsonData(filePath, data); // show success message success(filePath); }; run();