1 | const inquirer = require("inquirer");
|
2 | const chalk = require("chalk");
|
3 | const boxen = require("boxen");
|
4 | const { boxInform } = require("../helpers.js");
|
5 | const git = require("git-state");
|
6 | const simple = require("simple-git");
|
7 | const pathToCwd = process.cwd();
|
8 |
|
9 | const newBranch = async name => {
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | try {
|
23 |
|
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 |
|
37 |
|
38 | boxInform(chalk.green(`New branch ${name} created`, "", 5));
|
39 | };
|
40 |
|
41 | async 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 |
|
58 | const 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 | };
|
82 | module.exports = validateNotInDev;
|