add emojis to the status command
This commit is contained in:
parent
f497fde8ad
commit
f3bfe0f905
@ -1,46 +1,67 @@
|
|||||||
const Git = require('simple-git');
|
const Git = require("simple-git");
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require("inquirer");
|
||||||
const report = require('yurnalist');
|
const report = require("yurnalist");
|
||||||
const _ = require('lodash');
|
const _ = require("lodash");
|
||||||
const { defaults } = require('lodash/fp');
|
const { defaults } = require("lodash/fp");
|
||||||
const u = require('updeep');
|
const u = require("updeep");
|
||||||
const columnify = require('columnify');
|
const columnify = require("columnify");
|
||||||
const chalk = require('chalk');
|
const chalk = require("chalk");
|
||||||
|
|
||||||
|
const iconFor = ( branch, branches ) => {
|
||||||
|
if(branch.done ) return "✅";
|
||||||
|
|
||||||
|
for( const dep of branch.dependencies ) {
|
||||||
|
if( !branches[dep].done ) return "⛔";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "🙋";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = async (yargs) => {
|
module.exports = async (yargs) => {
|
||||||
const config = (await Git().listConfig('local')).all;
|
const config = (await Git().listConfig("local")).all;
|
||||||
|
|
||||||
let tree = Object.entries(config).reduce(
|
let tree = Object.entries(config).reduce(
|
||||||
(accum, [key,value]) => u.updateIn(key,value,accum), {}
|
(accum, [key, value]) => u.updateIn(key, value, accum),
|
||||||
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
const branches = {};
|
const branches = {};
|
||||||
|
|
||||||
const normalizeArray = value => Array.isArray(value)?value: [value].filter(x=>x);
|
const normalizeArray = (value) =>
|
||||||
|
Array.isArray(value) ? value : [value].filter((x) => x);
|
||||||
|
|
||||||
const initBranch = config => defaults({
|
const initBranch = (config) =>
|
||||||
|
defaults(
|
||||||
|
{
|
||||||
upstream: [],
|
upstream: [],
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
},config);
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
const current = (await Git().raw('branch','--show-current')).replace("\n",'');
|
const current = (await Git().raw("branch", "--show-current")).replace(
|
||||||
|
"\n",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
for (const branch in tree.branch) {
|
for (const branch in tree.branch) {
|
||||||
const entry = tree.branch[branch];
|
const entry = tree.branch[branch];
|
||||||
|
|
||||||
if( !('mikado-upstream' in entry) ) continue;
|
if (!("mikado-upstream" in entry)) continue;
|
||||||
|
|
||||||
branches[branch] = initBranch({
|
branches[branch] = initBranch({
|
||||||
name: branch,
|
name: branch,
|
||||||
upstream: normalizeArray(entry['mikado-upstream']),
|
upstream: normalizeArray(entry["mikado-upstream"]),
|
||||||
base: entry['mikado-base'],
|
base: entry["mikado-base"],
|
||||||
done: entry['mikado-done'],
|
done: entry["mikado-done"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const branch of Object.values(branches)) {
|
for (const branch of Object.values(branches)) {
|
||||||
for( const ups of branch['upstream'] ) {
|
for (const ups of branch["upstream"]) {
|
||||||
if(!branches[ups]) branches[ups] = initBranch({
|
if (!branches[ups])
|
||||||
|
branches[ups] = initBranch({
|
||||||
name: ups,
|
name: ups,
|
||||||
upstream: [],
|
upstream: [],
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
@ -52,52 +73,57 @@ module.exports = async (yargs) => {
|
|||||||
|
|
||||||
if (branches[current]) branches[current].current = true;
|
if (branches[current]) branches[current].current = true;
|
||||||
|
|
||||||
const depColor = current => async ( dep ) => {
|
const depColor = (current) => async (dep) => {
|
||||||
let color = branches[dep].done ? chalk.green : chalk.red;
|
let color = branches[dep].done ? chalk.green : chalk.red;
|
||||||
|
|
||||||
let contains = await Git().raw('branch', '--contains', dep);
|
let contains = await Git().raw("branch", "--contains", dep);
|
||||||
contains = contains.split("\n").map( x => x.trim().replace('* ','') );
|
contains = contains
|
||||||
|
.split("\n")
|
||||||
|
.map((x) => x.trim().replace("* ", ""));
|
||||||
|
|
||||||
if( contains.includes(current) )
|
if (contains.includes(current)) color = color.underline;
|
||||||
color = color.underline;
|
|
||||||
|
|
||||||
return color(dep);
|
return color(dep);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
const upstreamColor = (current) => async (up) => {
|
||||||
|
|
||||||
const upstreamColor = current => async ( up ) => {
|
|
||||||
let color = branches[up].done ? chalk.green : chalk.red;
|
let color = branches[up].done ? chalk.green : chalk.red;
|
||||||
|
|
||||||
let contains = await Git().raw('branch', '--contains', current);
|
let contains = await Git().raw("branch", "--contains", current);
|
||||||
contains = contains.split("\n").map( x => x.trim().replace('* ','') );
|
contains = contains
|
||||||
|
.split("\n")
|
||||||
|
.map((x) => x.trim().replace("* ", ""));
|
||||||
|
|
||||||
if( contains.includes(up) )
|
if (contains.includes(up)) color = color.underline;
|
||||||
color = color.underline;
|
|
||||||
|
|
||||||
return color(up);
|
return color(up);
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
console.log("\n=== Mikado status ===\n");
|
console.log("\n=== Mikado status ===\n");
|
||||||
|
|
||||||
const sorted = _.sortBy(Object.values(branches), ['current'])
|
const sorted = _.sortBy(Object.values(branches), ["current"]);
|
||||||
|
|
||||||
for (const branch of sorted) {
|
for (const branch of sorted) {
|
||||||
console.log( chalk.blue(branch.name), branch.current ? "(current branch)" : "", branch.done ? chalk.green.bold('done'):"" );
|
console.log(
|
||||||
console.log( `\tbase: ${chalk.magenta(branch.base ?? '<none>')}` );
|
iconFor(branch,branches),
|
||||||
|
chalk.blue(branch.name),
|
||||||
|
branch.current ? "👷" : ' '
|
||||||
|
);
|
||||||
|
console.log(`\tbase: ${chalk.magenta(branch.base ?? "<none>")}`);
|
||||||
|
|
||||||
if (branch.upstream.length) {
|
if (branch.upstream.length) {
|
||||||
const ups = await Promise.all(branch.upstream.map(upstreamColor(branch.name)));
|
const ups = await Promise.all(
|
||||||
|
branch.upstream.map(upstreamColor(branch.name))
|
||||||
|
);
|
||||||
console.log("\tupstream:", ups.join(" "));
|
console.log("\tupstream:", ups.join(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (branch.dependencies.length) {
|
if (branch.dependencies.length) {
|
||||||
const deps = await Promise.all(branch.dependencies.map(depColor(branch.name)));
|
const deps = await Promise.all(
|
||||||
|
branch.dependencies.map(depColor(branch.name))
|
||||||
|
);
|
||||||
console.log("\tdependencies:", deps.join(" "));
|
console.log("\tdependencies:", deps.join(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\n\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user