UNPKG

@seedneey/gint

Version:

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

80 lines (71 loc) 2.19 kB
const CLI = require("clui"); const Spinner = CLI.Spinner; const fs = require("fs-extra"); const touch = require("touch"); const _ = require("lodash"); const inquirer = require("./inquirer"); const gh = require("./github"); const chalk = require("chalk"); const path = require("path"); module.exports = { createRemoteRepo: async () => { const github = gh.getInstance(); const answers = await inquirer.askRepoDetails(); const data = { name: answers.name, description: answers.description, private: answers.visibility === "private", }; console.log(" "); const status = new Spinner("Creating remote repository..."); status.start(); try { const response = await github.repos.createForAuthenticatedUser(data); return { url: response.data.ssh_url, config: answers.config }; } finally { status.stop(); console.log(chalk.green(" - Repository created ✔️ ")); } }, createGitignore: async () => { const filelist = _.without(fs.readdirSync("."), ".git", ".gitignore"); const filePath = path.join( __dirname, "../templates/documentation/template-readme.md" ); touch("README.md"); fs.copyFile(filePath, "README.md", (err) => { if (err) throw err; }); if (filelist.length) { const answers = await inquirer.askIgnoreFiles(filelist); if (answers.ignore.length) { fs.writeFileSync(".gitignore", answers.ignore.join("\n")); } else { touch(".gitignore"); } } else { touch(".gitignore"); } }, setupRepo: async (data) => { const git = require("simple-git/promise")(process.cwd()); const status1 = new Spinner( "Initializing local repository and pushing to remote..." ); status1.start(); try { await git.init(); await git.add(".gitignore"); await git.add("./*"); await git.commit("Initial commit"); await git.addRemote("origin", data.url); await git.push("origin", "master"); } finally { status1.stop(); console.log( chalk.green(" - Git initialized and local repo pushed to origin ✔️ ") ); } }, };