UNPKG

@seedneey/gint

Version:

creating a repo (in Github) for your project in one command

86 lines (71 loc) 2 kB
#!/usr/bin/env node const chalk = require("chalk"); const clear = require("clear"); const figlet = require("figlet"); const files = require("./lib/files"); const github = require("./lib/github"); const repo = require("./lib/repo"); const setupconfig = require("./lib/setupconfig"); const display = require("./screen/cli"); const getGithubToken = async () => { // Fetch token from config store let token = github.getStoredGithubToken(); if (token) { return token; } // No token found, use credentials to access GitHub account token = await github.getPersonalAccesToken(); return token; }; const run = async () => { try { await files.createDirectory(); if (files.directoryExists(".git")) { console.log(chalk.red("Repo already exists!")); process.exit(); } clear(); console.log( chalk.yellow(figlet.textSync("SID:gint", { horizontalLayout: "full" })) ); // Retrieve & Set Authentication Token const token = await getGithubToken(); github.githubAuth(token); // Create remote repository const data = await repo.createRemoteRepo(); // Create .gitignore file await repo.createGitignore(); // Set up local repository and push to remote await repo.setupRepo(data); if (data.config !== "none") { await setupconfig.setupConfig(data); setTimeout(() => { display.displayChalk(data); }, 2000); } else { display.displayChalk(data); } } catch (err) { if (err) { switch (err.status) { case 401: console.log( chalk.red( "Couldn't log you in. Please provide correct credentials/token." ) ); break; case 422: console.log( chalk.red( "There is already a remote repository or token with the same name" ) ); break; default: console.log(chalk.red(err)); } } } }; run();