UNPKG

ruku-js

Version:

A cli that is the new NPM.

255 lines (238 loc) 9.11 kB
#!/usr/bin/env node import { Command } from 'commander'; import figlet from 'figlet'; import inquirer from 'inquirer'; import { createSpinner } from 'nanospinner'; const program = new Command(); const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms)) import {exec} from 'child_process' import cliProgress from 'cli-progress'; program .description('An application for genarating starter files') .option('-js, --jsProject', 'Create a Js Project') .option('-html, --htmlProject', 'Create a HTML, CSS and Vanilla Js Project') .option('-current, --currentDir', 'Creates the app in the current dir') .option('-ts, --typescript', 'Uses TypeScript') program.parse(); const options = program.opts(); console.log('You are creating a project with:'); if (options.jsProject) console.log(' - Js'); if (options.htmlProject) console.log(' - HTML, CSS, and Vanilla Js'); async function askJsFramework() { const answers = await inquirer.prompt({ name: "js_framework", type: "list", message: "What framework do you what to use for this project?\n", choices: [ "React Js", "Vannila (will create .html and .css files)", "Next Js", "Nextron" ] }) return answers.js_framework } async function load(project) { console.clear(); const spinner = createSpinner('Loading...').start() await sleep() spinner.success({text: `Creating Project! Type: ${project}`}) } function createApp(type) { // React if (type === "React Js") { if (options.jsProject && options.currentDir) { console.log("Creating a React App in the current derectory") const bar = new cliProgress.SingleBar({format: 'progress [{bar}] {percentage}% | {value}/{total}'}, cliProgress.Presets.shades_classic); // start the progress bar with a total value of 200 and start value of 0 bar.start(200, 0); // update the current value in your application.. bar.update(100); // stop the progress bar bar.stop(); exec("npx create-react-app .", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } if (options.jsProject && !options.currentDir) { console.log("Creating a React App called app") exec("yarn create react-app app", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } } // Nextron if (type === "Nextron") { if (options.jsProject && options.currentDir) { console.log("Creating a Nextron App in the current derectory") exec("npx create-nextron-app .", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } if (options.jsProject && options.currentDir && options.typescript) { console.log("Creating a Nextron App in the current derectory with Typescript") exec("npx create-nextron-app . --with-typescript", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } if (options.jsProject && !options.currentDir) { console.log("Creating a Nextron App called app") exec("yarn create nextron-app app", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } if (options.jsProject && !options.currentDir && options.typescript) { console.log("Creating a Nextron App called app with Typescript") exec("yarn create nextron-app app --with-typescript", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } } // Next Js if (type === "Next Js") { if (options.jsProject && options.currentDir) { console.log("Creating a React App in the current derectory") const bar = new cliProgress.SingleBar({format: 'progress [{bar}] {percentage}% | {value}/{total}'}, cliProgress.Presets.shades_classic); // start the progress bar with a total value of 200 and start value of 0 bar.start(200, 0); // update the current value in your application.. bar.update(100); // stop the progress bar bar.stop(); exec("npx create-next-app .", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } if (options.jsProject && !options.currentDir) { console.log("Creating a React App called app") exec("yarn create react-app app", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } } // Vannila if (type === "Vannila (will create .html and .css files)") { if (options.jsProject && !options.currentDir) { console.info('Please specify a directory.') } if (options.jsProject && options.currentDir) { console.log("Creating a React App called app") exec("hugo new site app", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); exec("cd app", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); } exec("git init && git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke && echo theme = \"ananke\" >> config.toml", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); exec("hugo new posts/my-first-post.md && hugo server -D", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`Server running on: http://localhost:1313/`); }); } } if (options.jsProject) { const framework = await askJsFramework() await load(framework) createApp(framework) } figlet("Ruku", (err, data) => { console.log(data) })