UNPKG

pon-shared-pon.universe.frontend.shared.componentlibrary

Version:

shared components for Pon Universe

104 lines (90 loc) 2.83 kB
const chalk = require("chalk"); const clear = require("clear"); const figlet = require("figlet"); const execa = require("execa"); const check = require("./helpers/emojis").check; const cross = require("./helpers/emojis").cross; const branch = require("git-branch"); const inquirer = require("inquirer"); const createCheckbox = async (name, message, options = []) => { return await inquirer.prompt([ { type: "checkbox", message: message, name: name, choices: options.map(option => ({ name: option })), validate: function(answer) { if (answer.length < 1 || answer.length > 1) { return "Choose 1 answer."; } return true; } } ]); }; const renderTitle = () => console.log( chalk.yellow( figlet.textSync("Publish packages", { horizontalLayout: "full" }) ) ); const renderText = (text, color = "yellow") => console.log(chalk[color](text)); const checkDevelop = () => branch.sync() === "develop"; const switchToDevelop = async () => { const answer = await createCheckbox( "develop", "Do you want to switch to develop", ["yes", "no"] ); if (answer.develop[0] === "yes") { const { stdout } = await execa.shell("git checkout develop"); console.log(stdout); return true; } return false; }; const lernaPublish = async () => { renderText("Publishing to Lerna"); await execa.shell("lerna publish"); renderText(`${check} Publish to lerna succesfull`); }; const checkGit = async () => { const { stdout } = await execa.shell("git status -uno"); return ( stdout.includes("Your branch is up-to-date with") && !stdout.includes("Changes to be committed") && !stdout.includes("Changes not staged for commit") ); }; const initCli = async () => { clear(); renderTitle(); renderText("-checking if branch is up to date"); if (await checkGit()) { renderText( `${check} Your branch is up to date and working tree is clean`, "green" ); renderText("-checking if you are currently working on develop"); if (checkDevelop()) { renderText(`${check} You are currently on the develop branch`, "green"); lernaPublish(); } else { if (await switchToDevelop()) { renderText(`${check} Switched to develop`, "green"); lernaPublish(); } else { renderText( `${cross} you can only publish packages from the develop branch. Please checkout develop and run the CLI again`, "red" ); } } } else { renderText( `${cross} your working tree is not clean or your branch is not up to date.Please fix this and run "npm run publish" again`, "red" ); } }; initCli();