UNPKG

node-app-create

Version:

node-ex its basic framework for node express server with mongo db support

123 lines (111 loc) 3.37 kB
const commander = require('commander'); const colors = require('colors'); const processHandler = require('./libs/processHandler'); const Program = commander.program; const cfonts = require('cfonts'); const envInfo = require('envinfo'); const localJson = require('./package.json'); const app = require('./app/app'); let createApp = async (AppName) => { console.log('Creating', AppName); let nodeVersion = await envInfo.helpers.getNodeInfo(); let checknpm = await processHandler.stdHandler('npm --version'); let vsCode = await envInfo.helpers.getVSCodeInfo(); let webStrom = await envInfo.helpers.getWebStormInfo(); let vsCodeInstalled = vsCode[1] === 'Not Found' ? false : true; let webStromInstalled = webStrom[1] === 'Not Found' ? false : true; if ( checknpm?.error || parseFloat(nodeVersion[1]) < 14.0 || parseFloat(checknpm.stdout.replace('/n', '').replace('v', '')) < 6.0 ) { console.log( colors.red('please update your node(above 14) or npm(above 6) ') ); processHandler.killService(); } // printing system informations console.log(colors.blue(`Your System informations\n`)); console.log(colors.red('Node: ') + nodeVersion[1]); console.log(colors.red('VS_Code: ') + vsCode[1]); console.log(colors.red('WebStrom: ') + webStrom[1] + '\n'); if (webStromInstalled && vsCodeInstalled) { console.log(colors.red('please install visual studio code or webstrom')); processHandler.killService(); } if (webStromInstalled) { console.log( colors.bold.green( 'Please install eslint, prettier and editor config plugins in webStorm' ) ); } else { let requirePlugins = [ 'dbaeumer.vscode-eslint', 'esbenp.prettier-vscode', 'EditorConfig.EditorConfig' ]; let pluginList = await processHandler.stdHandler( 'code --list-extensions' ); pluginList = pluginList.stdout.split('\n').map((data) => { return data; }); let needsPlugins = requirePlugins.filter( (plugin) => !pluginList.includes(plugin) ); console.log(colors.green('installing plugins for vscode...')); needsPlugins.map(async (plugin) => { let data = await processHandler.stdHandler( `code --install-extension ${plugin}` ); if (data?.error) { console.log(colors.error(data.error)); } else { console.log(colors.green(`${plugin} installation completed.`)); } }); // main project is initializing is starting from here app(AppName); } }; module.exports = async () => { console.clear(); Program.description( `${colors.green.italic( `Welcome to ${colors.bgGreen.black.bold( ` Sri's ` )} framework this is awesome for basic template with node express with some basic project structure.` )} \n\n\n it contains the following:\n - eslint - \n - prettier\n - husky\n - committizen\n - commitlint\n - and much more things...` ) .version(localJson.version) .name( cfonts.say('node-app-create', { font: 'block', align: 'center', background: 'transparent', space: true, maxLength: '0', gradient: [ 'green', 'yellow', 'red', 'magenta', 'blue', 'cyan', 'white', 'gray' ], independentGradient: false, transitionGradient: true, env: 'node' }) ); Program.command('init') .argument('[string]') .description('project name') .action(async (AppName) => { createApp(AppName); }); Program.parse(); };