Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-task

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-task - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

11

package.json
{
"name": "cli-task",
"version": "0.7.0",
"version": "0.7.1",
"repository": "https://github.com/astoilkov/cli-task",

@@ -18,3 +18,3 @@ "description": "Task runner for developers minimalists",

"scripts": {
"prepare": "tsc",
"build": "tsc",
"tsc": "tsc --watch"

@@ -39,14 +39,15 @@ },

"dependencies": {
"@types/minimist": "1.2.0",
"chalk": "2.4.1",
"cli-cursor": "2.1.0",
"exit-hook": "2.0.0",
"figures": "2.0.0",
"log-update": "2.3.0",
"log-update": "3.0.0",
"minimist": "1.2.0"
},
"devDependencies": {
"@types/exit-hook": "1.1.0",
"@types/figures": "2.0.0",
"@types/log-update": "2.0.0",
"@types/minimist": "1.2.0",
"typescript": "2.9.2"
}
}

@@ -23,8 +23,8 @@ # cli-task

exec: () => {
return execa('npm', [
'init',
'--force'
], {
cwd: tmpPath
});
return execa('npm', [
'init',
'--force'
], {
cwd: tmpPath
});
}

@@ -51,7 +51,3 @@ })

})
.run({
print: true,
colors: true,
animate: true,
});
.run();
```

@@ -78,25 +74,4 @@

### task.run(options)
### task.run()
Execute the task
#### options
Type: `Object`
##### print
Type: `boolean`
Default: `false`
Print progress to the terminal
##### colors
Type: `boolean`
Default: `false`
Print colors to the terminal
##### animate
Type: `boolean`
Default: `false`
Animate the output to the terminal
Executes the task
import Task from './Task';
export interface IRendererOptions {
print?: boolean;
colors?: boolean;
animate?: boolean;
}
export declare class Renderer {
private task;
private chalk;
private logs;
private options;
private intervalId;
private lastRenderedText;
private lastSpinnerUpdate;
private spinnerFrameIndex;
constructor(task: Task, options?: IRendererOptions);
private _update;
private _getErrorsText;
private _getTextAtLevel;
private _getStepText;
private static _task;
private static _logs;
private static _lastRenderedText;
private static _spinnerFrameIndex;
private static _chalk;
static play(task: Task): void;
private static _update;
private static _getErrorsText;
private static _getTextAtLevel;
private static _getStepText;
private static _exitHook;
private static _overrideConsoleLog;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const figures = require("figures");
const minimist = require("minimist");
const chalk_1 = require("chalk");
const exitHook = require("exit-hook");
const util_1 = require("util");
const cliCursor = require("cli-cursor");
const logUpdate = require("log-update");
const chalk_1 = require("chalk");
const Step_1 = require("./Step");
const spinnerFrames = [
'⠋',
'⠙',
'⠹',
'⠸',
'⠼',
'⠴',
'⠦',
'⠧',
'⠇',
'⠏'
];
const argv = minimist(process.argv.slice(2));
const print = argv.hasOwnProperty('print') ? argv.print == 'true' : true;
const colors = argv.hasOwnProperty('colors') ? argv.colors == 'true' : process.stdout.isTTY;
const animate = argv.hasOwnProperty('animate') ? argv.animate == 'true' : process.stdout.isTTY;
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
class Renderer {
constructor(task, options) {
this.logs = [];
this.spinnerFrameIndex = 0;
if (!options.print) {
static play(task) {
if (!print) {
return;
}
this.task = task;
this.options = options;
this.lastSpinnerUpdate = Date.now();
this.chalk = new chalk_1.default.constructor({ enabled: options.colors });
process.on('exit', () => {
this._update();
cliCursor.show();
});
console.log = (...args) => {
let toString = (value) => {
if (typeof value == 'string') {
return util_1.format(value);
}
else {
return util_1.inspect(value, { colors: true });
}
};
this.logs.push(args.map(value => toString(value)).join(' '));
};
this._task = task;
this._update();
cliCursor.hide();
this.intervalId = setInterval(() => this._update(), 60);
this.intervalId.unref();
this._overrideConsoleLog();
exitHook(this._exitHook.bind(this));
setInterval(() => this._update(), 120).unref();
}
_update() {
if (Date.now() - this.lastSpinnerUpdate >= 60) {
this.lastSpinnerUpdate = Date.now();
if (this.spinnerFrameIndex == spinnerFrames.length - 1) {
this.spinnerFrameIndex = 0;
}
else {
this.spinnerFrameIndex += 1;
}
}
static _update() {
let text = '';
text += '\n';
text += this._getTextAtLevel(this.task, 0);
text += this._getTextAtLevel(this._task, 0);
text += this._getErrorsText();
if (this.logs.length) {
if (this._logs.length) {
text += '\n';
text += this.logs.join('\n');
text += this._logs.join('\n');
}

@@ -73,10 +38,13 @@ if (!text.endsWith('\n')) {

}
if (this.lastRenderedText != text) {
if (this._lastRenderedText != text) {
logUpdate(text);
}
this.lastRenderedText = text;
this._lastRenderedText = text;
this._spinnerFrameIndex = this._spinnerFrameIndex < spinnerFrames.length - 1
? this._spinnerFrameIndex + 1
: 0;
}
_getErrorsText() {
static _getErrorsText() {
let text = '';
let queue = [...this.task.steps];
let queue = [...this._task.steps];
while (queue.length) {

@@ -93,3 +61,3 @@ let step = queue.pop();

}
_getTextAtLevel(task, level) {
static _getTextAtLevel(task, level) {
let text = '';

@@ -108,15 +76,15 @@ task.steps.forEach(step => {

}
_getStepText(step) {
static _getStepText(step) {
let text = '';
switch (step.status) {
case Step_1.StepStatus.Running:
text += process.platform == 'win32' || !this.options.animate
? this.chalk.yellow(figures.play)
: this.chalk.yellow(spinnerFrames[this.spinnerFrameIndex]);
text += process.platform == 'win32' || !animate
? this._chalk.yellow(figures.play)
: this._chalk.yellow(spinnerFrames[this._spinnerFrameIndex]);
break;
case Step_1.StepStatus.Success:
text += this.chalk.green(figures.tick);
text += this._chalk.green(figures.tick);
break;
case Step_1.StepStatus.Failure:
text += this.chalk.red(figures.cross);
text += this._chalk.red(figures.cross);
break;

@@ -127,11 +95,32 @@ }

if (step.status == Step_1.StepStatus.Failure && step.errorMessage) {
text += ' ' + figures.arrowRight + ' ' + this.chalk.red(step.errorMessage);
text += ' ' + figures.arrowRight + ' ' + this._chalk.red(step.errorMessage);
}
else if (step.info && (step.status == Step_1.StepStatus.Running || step.status == Step_1.StepStatus.Failure)) {
text += ' ' + figures.arrowRight + ' ' + this.chalk.yellow(step.info);
text += ' ' + figures.arrowRight + ' ' + this._chalk.yellow(step.info);
}
return text;
}
static _exitHook() {
this._update();
logUpdate.done();
}
static _overrideConsoleLog() {
console.log = (...args) => {
let toString = (value) => {
if (typeof value == 'string') {
return util_1.format(value);
}
else {
return util_1.inspect(value, { colors: true });
}
};
this._logs.push(args.map(value => toString(value)).join(' '));
};
}
}
Renderer._logs = [];
Renderer._lastRenderedText = '';
Renderer._spinnerFrameIndex = 0;
Renderer._chalk = new chalk_1.default.constructor({ enabled: colors });
exports.Renderer = Renderer;
//# sourceMappingURL=Renderer.js.map

@@ -1,13 +0,12 @@

import { IRendererOptions } from './Renderer';
import { Step, IStepOptions, IStepState } from './Step';
export default class Task {
steps: Step[];
private options;
private stateValues;
private _options;
private _stateValues;
constructor();
add(step: Task | IStepOptions | ((state: IStepState) => void)): this;
run(options?: IRendererOptions): Promise<void>;
add(value: Task | IStepOptions | ((state: IStepState) => void)): this;
withOptions(options: {
[key: string]: any;
}): Task;
run(): Promise<void>;
private _getCurrentStep;

@@ -14,0 +13,0 @@ private _execTasks;

@@ -9,4 +9,4 @@ "use strict";

this.steps = [];
this.options = {};
this.stateValues = {};
this._options = {};
this._stateValues = {};
let handleError = (err) => {

@@ -24,29 +24,29 @@ if (this._getCurrentStep()) {

}
add(step) {
if (step instanceof Task) {
add(value) {
if (value instanceof Task) {
this.steps.push(new Step_1.Step({
child: step
child: value
}));
}
else if (step instanceof Function) {
else if (value instanceof Function) {
this.steps.push(new Step_1.Step({
exec: step
exec: value
}));
}
else {
this.steps.push(new Step_1.Step(step));
this.steps.push(new Step_1.Step(value));
}
return this;
}
run(options) {
new Renderer_1.Renderer(this, options);
return this._execTasks(this);
}
withOptions(options) {
let copy = new Task();
copy.options = options;
copy._options = options;
copy.steps = this.steps;
copy.stateValues = this.stateValues;
copy._stateValues = this._stateValues;
return copy;
}
run() {
Renderer_1.Renderer.play(this);
return this._execTasks(this);
}
_getCurrentStep() {

@@ -68,3 +68,3 @@ let queue = this.steps.slice();

for (let i = 0; i < task.steps.length; i++) {
await this._execTask(task.steps[i], task.options);
await this._execTask(task.steps[i], task._options);
}

@@ -117,4 +117,4 @@ }

options: options,
get: (key) => this.stateValues[key],
set: (key, value) => this.stateValues[key] = value,
get: (key) => this._stateValues[key],
set: (key, value) => this._stateValues[key] = value,
info: (message) => {

@@ -121,0 +121,0 @@ this._getCurrentStep().info = message;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc