UNPKG

cloudux-starter-kit

Version:

Starter kit for UX developers in MediaCentral - NPM package

57 lines 2.74 kB
const QUESTIONS = require('./questions'); const inquirer = require('inquirer'); const CURR_DIR = process.cwd(); const functions = require('./functions'); const validation = require('../parseCliArguments'); const cliArgs = process.argv.slice(2); const version = require('../../package').version; const help = 'You need to provide --name --description --hostIp --projectChoice ' + '\nOPTIONAL: --hostPort=Default:None --path:Default:Current Dir.\n' + '--path needs to be absolute.'; const logger = require.main.require('log4js').getLogger(`cloudux-starter-kit ${__filename}`); const promptCLI = () => { logger.debug('------ Creating new project ------'); const prompt = args => { if (args.length === 0) { inquirer.prompt(QUESTIONS.QUESTIONS).then(answers => { logger.trace('Passed answers', answers); const projectName = answers['project-name']; const projectDescription = answers['project-description']; const projectHostIp = answers['project-hostIp']; const projectHostPort = answers['project-hostPort']; const projectChoice = answers['project-choice']; const configPath = `${CURR_DIR}/${projectName}/src/project.config.json`; const srcPackagePath = `${CURR_DIR}/${projectName}/src/package.json`; functions.copyProjectTemplate(projectName, projectChoice, CURR_DIR); functions.writeUserConfig(projectName, projectDescription, projectHostIp, projectHostPort, configPath, srcPackagePath); }); } else if (args[0] === '--help') { console.log(help); } else if (args[0] === '--version' || args[0] === '-v') { console.log(version); } else { const validatedArgs = validation(['name', 'description', 'hostIp', 'projectChoice'], args); const projectName = validatedArgs.name; const projectDescription = validatedArgs.description; const projectHostIp = validatedArgs.hostIp; const projectChoice = validatedArgs.projectChoice; const projectHostPort = validatedArgs.hostPort; let projectPath = CURR_DIR; if (validatedArgs.path) { projectPath = validatedArgs.path; } const configPath = `${projectPath}/${projectName}/src/project.config.json`; const srcPackagePath = `${projectPath}/${projectName}/src/package.json`; logger.debug(`Creating project ${projectName} in path`, projectPath); functions.copyProjectTemplate(projectName, projectChoice, projectPath); functions.writeUserConfig(projectName, projectDescription, projectHostIp, projectHostPort, configPath, srcPackagePath); logger.debug('Done'); } }; try { prompt(cliArgs); } catch (err) { logger.error(err.message); } }; module.exports = { promptCLI };