UNPKG

2.47 kBJavaScriptView Raw
1const inquirer = require("inquirer");
2const chalk = require("chalk");
3const boxen = require("boxen");
4const { boxInform } = require("../helpers.js");
5const git = require("git-state");
6const simple = require("simple-git");
7const pathToCwd = process.cwd();
8
9const newBranch = async name => {
10 // const last = await new Promise(rzz => {
11 // git.isGit(pathToCwd, function(exists) {
12 // if (!exists) return;
13
14 //
15 // git.commit(pathToCwd, function(err, result) {
16 // if (err) throw err;
17 // rzz(result);
18 // });
19 // });
20 // });
21
22 try {
23 // logInfo(command);
24 childProcess.execSync(
25 `git -c core.quotepath=false -c log.showSignature=false checkout -b ${name}`,
26 {
27 stdio: "inherit",
28 env: Object.assign({}, process.env, {
29 FORCE_COLOR: true,
30 PATH: `${path.resolve("node_modules")}:${process.env.PATH}`
31 })
32 }
33 );
34 } catch (e) {}
35
36 // await simple().checkoutLocalBranch(name);
37 // await simple().checkoutBranch(name, "origin");
38 boxInform(chalk.green(`New branch ${name} created`, "", 5));
39};
40
41async function pub() {
42 return new Promise(resolve => {
43 inquirer
44 .prompt([
45 {
46 type: "input",
47 message: chalk.bold.hex("#38be18")(`Name new feature branch (or type cancel):`),
48 name: "branchname"
49 }
50 ])
51 .then(async ({ branchname }) => {
52 if (branchname !== "Development") await newBranch(branchname);
53 resolve();
54 });
55 });
56}
57
58const validateNotInDev = async () => {
59 await new Promise(async resolve => {
60 const git = require("simple-git/promise");
61
62 let statusSummary = await git(__dirname).status();
63 if (statusSummary.current === "Development") {
64 console.clear();
65 console.log(
66 boxen(chalk.bold.underline.red("DO NO MAKE CHANGES IN DEV!"), {
67 padding: 2
68 })
69 );
70 await new Promise(resolve1 =>
71 setTimeout(() => {
72 resolve1();
73 }, 1000)
74 );
75 await pub();
76 resolve();
77 } else {
78 resolve();
79 }
80 });
81};
82module.exports = validateNotInDev;