Initial commit 🍀

This commit is contained in:
syuilo
2016-12-29 07:49:51 +09:00
commit b3f42e62af
405 changed files with 31017 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import {logInfo, logDone, logWarn} from 'log-cool';
import {exec} from 'shelljs';
export default function(): void {
checkDependency('Node.js', 'node -v', x => x.match(/^v(.*)\r?\n$/)[1]);
checkDependency('npm', 'npm -v', x => x.match(/^(.*)\r?\n$/)[1]);
checkDependency('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version: (.*)\r?\n$/)[1]);
checkDependency('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/)[1]);
logDone('Successfully checked external dependencies');
}
function checkDependency(serviceName: string, command: string, transform: (x: string) => string): void {
const code = {
success: 0,
notFound: 127
};
const x = exec(command, { silent: true }) as any;
if (x.code === code.success) {
logInfo(`DEPS: ${serviceName} ${transform(x.stdout)}`);
} else if (x.code === code.notFound) {
logWarn(`Unable to find ${serviceName}`);
}
}

View File

@ -0,0 +1,35 @@
import * as readline from 'readline';
/**
* Indicator
*/
export default class {
private clock: NodeJS.Timer;
constructor(text: string) {
let i = 0; // Dots counter
draw();
this.clock = setInterval(draw, 300);
function draw(): void {
cll();
i = (i + 1) % 4;
const dots = new Array(i + 1).join('.');
process.stdout.write(text + dots); // Write text
}
}
public end(): void {
clearInterval(this.clock);
cll();
}
}
/**
* Clear current line
*/
function cll(): void {
readline.clearLine(process.stdout, 0); // Clear current text
readline.cursorTo(process.stdout, 0, null); // Move cursor to the head of line
}

View File

@ -0,0 +1,87 @@
import * as ev from 'events';
import * as readline from 'readline';
import * as chalk from 'chalk';
/**
* Progress bar
*/
class ProgressBar extends ev.EventEmitter {
public max: number;
public value: number;
public text: string;
private indicator: number;
constructor(max: number, text: string = null) {
super();
this.max = max;
this.value = 0;
this.text = text;
this.indicator = 0;
this.draw();
const iclock = setInterval(() => {
this.indicator = (this.indicator + 1) % 4;
this.draw();
}, 200);
this.on('complete', () => {
clearInterval(iclock);
});
}
public increment(): void {
this.value++;
this.draw();
// Check if it is fulfilled
if (this.value === this.max) {
this.indicator = null;
cll();
process.stdout.write(`${this.render()} -> ${chalk.bold('Complete')}\n`);
this.emit('complete');
}
}
public draw(): void {
const str = this.render();
cll();
process.stdout.write(str);
}
private render(): string {
const width = 30;
const t = this.text ? this.text + ' ' : '';
const v = Math.floor((this.value / this.max) * width);
const vs = new Array(v + 1).join('*');
const p = width - v;
const ps = new Array(p + 1).join(' ');
const percentage = Math.floor((this.value / this.max) * 100);
const percentages = chalk.gray(`(${percentage}%)`);
let i: string;
switch (this.indicator) {
case 0: i = '-'; break;
case 1: i = '\\'; break;
case 2: i = '|'; break;
case 3: i = '/'; break;
case null: i = '+'; break;
}
return `${i} ${t}[${vs}${ps}] ${this.value}/${this.max} ${percentages}`;
}
}
export default ProgressBar;
/**
* Clear current line
*/
function cll(): void {
readline.clearLine(process.stdout, 0); // Clear current text
readline.cursorTo(process.stdout, 0, null); // Move cursor to the head of line
}