@sewing-kit/ui
Advanced tools
Comparing version 0.0.5 to 0.0.6
import { Step } from '@sewing-kit/types'; | ||
import { Ui } from './ui'; | ||
export declare function run(steps: Step[], { ui, pre, post, title, }: { | ||
interface RunOptions { | ||
ui: Ui; | ||
pre?: Step[]; | ||
post?: Step[]; | ||
skip?: string[]; | ||
skipPre?: string[]; | ||
skipPost?: string[]; | ||
title?: string; | ||
}): Promise<void>; | ||
} | ||
export declare function run(steps: Step[], { ui, pre, post, skip, skipPre, skipPost, title, }: RunOptions): Promise<void>; | ||
export {}; | ||
//# sourceMappingURL=runner.d.ts.map |
@@ -14,2 +14,3 @@ "use strict"; | ||
StepState[StepState["Pending"] = 3] = "Pending"; | ||
StepState[StepState["Skipped"] = 4] = "Skipped"; | ||
})(StepState || (StepState = {})); | ||
@@ -23,4 +24,12 @@ const symbols = '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆'; | ||
this.stepRunners = []; | ||
for (const subStep of step.steps || []) { | ||
const stepRunner = new StepRunner(subStep, this.update); | ||
this.stepRunners.push(stepRunner); | ||
} | ||
} | ||
async run(ui) { | ||
async run(ui, skip) { | ||
if (this.step.skip(skip)) { | ||
this.setState(StepState.Skipped); | ||
return; | ||
} | ||
this.setState(StepState.InProgress); | ||
@@ -33,13 +42,9 @@ try { | ||
}, | ||
run: async (steps) => { | ||
for (const step of steps) { | ||
const stepRunner = new StepRunner(step, this.update); | ||
this.stepRunners.push(stepRunner); | ||
} | ||
for (const stepRunner of this.stepRunners) { | ||
await stepRunner.run(ui); | ||
} | ||
}, | ||
}; | ||
await this.step.run(runner); | ||
if (this.step.run) { | ||
await this.step.run(runner); | ||
} | ||
for (const stepRunner of this.stepRunners) { | ||
await stepRunner.run(ui, skip); | ||
} | ||
this.setState(StepState.Success); | ||
@@ -66,3 +71,3 @@ } | ||
case StepState.Failure: | ||
prefix = fmt `{error o}`; | ||
prefix = fmt `{error ✕}`; | ||
break; | ||
@@ -72,2 +77,5 @@ case StepState.Pending: | ||
break; | ||
case StepState.Skipped: | ||
prefix = fmt `{subdued ⇥}`; | ||
break; | ||
} | ||
@@ -90,4 +98,4 @@ const ownLine = fmt `${prefix} ${fmt `${this.step.label || ''}`}`; | ||
class StepGroupRunner { | ||
constructor(steps, update) { | ||
this.steps = steps; | ||
constructor(group, update) { | ||
this.group = group; | ||
this.update = update; | ||
@@ -97,7 +105,7 @@ this.stepRunners = []; | ||
async run(ui) { | ||
for (const step of this.steps) { | ||
for (const step of this.group.steps) { | ||
this.stepRunners.push(new StepRunner(step, this.update)); | ||
} | ||
for (const step of this.stepRunners) { | ||
await step.run(ui); | ||
await step.run(ui, this.group.skip); | ||
} | ||
@@ -155,4 +163,11 @@ } | ||
} | ||
async function run(steps, { ui, pre = [], post = [], title, }) { | ||
const runnerUi = new RunnerUi([pre, steps, post], ui); | ||
async function run(steps, { ui, pre = [], post = [], skip = [], skipPre = [], skipPost = [], title, }) { | ||
if (pre.length + steps.length + post.length === 0) { | ||
return; | ||
} | ||
const runnerUi = new RunnerUi([ | ||
{ steps: pre, skip: skipPre }, | ||
{ steps, skip }, | ||
{ steps: post, skip: skipPost }, | ||
], ui); | ||
try { | ||
@@ -185,7 +200,15 @@ if (title) { | ||
// ui.log(error.message); | ||
if (error.all == null) { | ||
if (error.all != null) { | ||
ui.error(error.all); | ||
ui.error(error.stack); | ||
} | ||
else if (error.stderr != null) { | ||
ui.error(error.stderr); | ||
ui.error(error.stack); | ||
} | ||
else if (error.stdout == null) { | ||
ui.error(error.stack); | ||
} | ||
else { | ||
ui.error(error.all); | ||
ui.error(error.stdout); | ||
ui.error(error.stack); | ||
@@ -192,0 +215,0 @@ } |
import { Step } from '@sewing-kit/types'; | ||
declare type Skipper = ((skipped: string[]) => boolean) | RegExp; | ||
export declare function createStep(run: Step['run']): Step; | ||
export declare function createStep(options: Omit<Step, 'run'>, run: Step['run']): Step; | ||
export declare function createStep(options: Omit<Step, 'run' | 'skip'> & { | ||
skip?: Skipper; | ||
}, run?: Step['run']): Step; | ||
export {}; | ||
//# sourceMappingURL=steps.d.ts.map |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const defaultSkip = () => false; | ||
function createStep(runOrStep, run) { | ||
return typeof runOrStep === 'function' | ||
? { run: runOrStep } | ||
: Object.assign({ run }, runOrStep); | ||
? { run: runOrStep, skip: defaultSkip } | ||
: Object.assign({ run }, normalizeOptions(runOrStep)); | ||
} | ||
exports.createStep = createStep; | ||
function normalizeOptions(_a) { | ||
var { skip } = _a, rest = __rest(_a, ["skip"]); | ||
return Object.assign(Object.assign({}, rest), { skip: skip ? normalizeSkip(skip) : defaultSkip }); | ||
} | ||
function normalizeSkip(skipper) { | ||
return typeof skipper === 'function' | ||
? skipper | ||
: (skipped) => skipped.some((skip) => skipper.test(skip)); | ||
} |
@@ -1,1 +0,1 @@ | ||
module.exports = require("./build/cjs"); | ||
module.exports = require("./src/index"); |
{ | ||
"name": "@sewing-kit/ui", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"sideEffects": false, | ||
@@ -10,9 +10,10 @@ "publishConfig": { | ||
"dependencies": { | ||
"@shopify/useful-types": "^2.0.0", | ||
"ansi-escapes": "^4.2.1", | ||
"chalk": "^2.4.2", | ||
"execa": "^2.0.4", | ||
"@sewing-kit/types": "^0.0.2", | ||
"@shopify/useful-types": "^2.1.2", | ||
"ansi-escapes": "^4.3.0", | ||
"chalk": "^3.0.0", | ||
"execa": "^3.4.0", | ||
"supports-hyperlinks": "^2.0.0" | ||
}, | ||
"gitHead": "b92b7a4350e29b5c1500b895558743767617d725" | ||
"gitHead": "1fc44608f952bd67cfe6f98006e1e510ec2ce82b" | ||
} |
import {FirstArgument} from '@shopify/useful-types'; | ||
import {Ui} from './ui'; | ||
@@ -3,0 +4,0 @@ |
import exec from 'execa'; | ||
import {Step, StepRunner as NestedStepRunner} from '@sewing-kit/types'; | ||
import {Step, StepRunner as NestedStepRunner} from '@sewing-kit/types'; | ||
import {Ui, Loggable} from './ui'; | ||
@@ -12,2 +12,3 @@ import {DiagnosticError} from './errors'; | ||
Pending, | ||
Skipped, | ||
} | ||
@@ -23,5 +24,15 @@ | ||
constructor(private readonly step: Step, private readonly update: Update) {} | ||
constructor(private readonly step: Step, private readonly update: Update) { | ||
for (const subStep of step.steps || []) { | ||
const stepRunner = new StepRunner(subStep, this.update); | ||
this.stepRunners.push(stepRunner); | ||
} | ||
} | ||
async run(ui: Ui) { | ||
async run(ui: Ui, skip: string[]) { | ||
if (this.step.skip(skip)) { | ||
this.setState(StepState.Skipped); | ||
return; | ||
} | ||
this.setState(StepState.InProgress); | ||
@@ -35,15 +46,12 @@ | ||
}, | ||
run: async (steps) => { | ||
for (const step of steps) { | ||
const stepRunner = new StepRunner(step, this.update); | ||
this.stepRunners.push(stepRunner); | ||
} | ||
for (const stepRunner of this.stepRunners) { | ||
await stepRunner.run(ui); | ||
} | ||
}, | ||
}; | ||
await this.step.run(runner); | ||
if (this.step.run) { | ||
await this.step.run(runner); | ||
} | ||
for (const stepRunner of this.stepRunners) { | ||
await stepRunner.run(ui, skip); | ||
} | ||
this.setState(StepState.Success); | ||
@@ -72,3 +80,3 @@ } catch (error) { | ||
case StepState.Failure: | ||
prefix = fmt`{error o}`; | ||
prefix = fmt`{error ✕}`; | ||
break; | ||
@@ -78,2 +86,5 @@ case StepState.Pending: | ||
break; | ||
case StepState.Skipped: | ||
prefix = fmt`{subdued ⇥}`; | ||
break; | ||
} | ||
@@ -102,2 +113,7 @@ | ||
interface StepGroup { | ||
steps: Step[]; | ||
skip: string[]; | ||
} | ||
class StepGroupRunner { | ||
@@ -107,3 +123,3 @@ readonly stepRunners: StepRunner[] = []; | ||
constructor( | ||
private readonly steps: Step[], | ||
private readonly group: StepGroup, | ||
private readonly update: Update, | ||
@@ -113,3 +129,3 @@ ) {} | ||
async run(ui: Ui) { | ||
for (const step of this.steps) { | ||
for (const step of this.group.steps) { | ||
this.stepRunners.push(new StepRunner(step, this.update)); | ||
@@ -119,3 +135,3 @@ } | ||
for (const step of this.stepRunners) { | ||
await step.run(ui); | ||
await step.run(ui, this.group.skip); | ||
} | ||
@@ -138,3 +154,3 @@ } | ||
constructor(private readonly groups: Step[][], private readonly ui: Ui) {} | ||
constructor(private readonly groups: StepGroup[], private readonly ui: Ui) {} | ||
@@ -185,2 +201,12 @@ async run() { | ||
interface RunOptions { | ||
ui: Ui; | ||
pre?: Step[]; | ||
post?: Step[]; | ||
skip?: string[]; | ||
skipPre?: string[]; | ||
skipPost?: string[]; | ||
title?: string; | ||
} | ||
export async function run( | ||
@@ -192,7 +218,21 @@ steps: Step[], | ||
post = [], | ||
skip = [], | ||
skipPre = [], | ||
skipPost = [], | ||
title, | ||
}: {ui: Ui; pre?: Step[]; post?: Step[]; title?: string}, | ||
}: RunOptions, | ||
) { | ||
const runnerUi = new RunnerUi([pre, steps, post], ui); | ||
if (pre.length + steps.length + post.length === 0) { | ||
return; | ||
} | ||
const runnerUi = new RunnerUi( | ||
[ | ||
{steps: pre, skip: skipPre}, | ||
{steps, skip}, | ||
{steps: post, skip: skipPost}, | ||
], | ||
ui, | ||
); | ||
try { | ||
@@ -234,6 +274,12 @@ if (title) { | ||
if (error.all == null) { | ||
if (error.all != null) { | ||
ui.error(error.all); | ||
ui.error(error.stack); | ||
} else if (error.stderr != null) { | ||
ui.error(error.stderr); | ||
ui.error(error.stack); | ||
} else if (error.stdout == null) { | ||
ui.error(error.stack); | ||
} else { | ||
ui.error(error.all); | ||
ui.error(error.stdout); | ||
ui.error(error.stack); | ||
@@ -240,0 +286,0 @@ } |
import {Step} from '@sewing-kit/types'; | ||
type Skipper = ((skipped: string[]) => boolean) | RegExp; | ||
const defaultSkip = () => false; | ||
export function createStep(run: Step['run']): Step; | ||
export function createStep(options: Omit<Step, 'run'>, run: Step['run']): Step; | ||
export function createStep( | ||
runOrStep: Step['run'] | Omit<Step, 'run'>, | ||
options: Omit<Step, 'run' | 'skip'> & {skip?: Skipper}, | ||
run?: Step['run'], | ||
) { | ||
): Step; | ||
export function createStep( | ||
runOrStep: Step['run'] | (Omit<Step, 'run' | 'skip'> & {skip?: Skipper}), | ||
run?: Step['run'], | ||
): Step { | ||
return typeof runOrStep === 'function' | ||
? {run: runOrStep} | ||
: {run, ...runOrStep}; | ||
? {run: runOrStep, skip: defaultSkip} | ||
: {run, ...normalizeOptions(runOrStep!)}; | ||
} | ||
function normalizeOptions({ | ||
skip, | ||
...rest | ||
}: Omit<Step, 'run' | 'skip'> & {skip?: Skipper}): Step { | ||
return {...rest, skip: skip ? normalizeSkip(skip) : defaultSkip}; | ||
} | ||
function normalizeSkip(skipper: Skipper) { | ||
return typeof skipper === 'function' | ||
? skipper | ||
: (skipped: string[]) => skipped.some((skip) => skipper.test(skip)); | ||
} |
import {clearScreenDown, clearLine, moveCursor, cursorTo} from 'readline'; | ||
import {link} from 'ansi-escapes'; | ||
@@ -3,0 +4,0 @@ import chalk from 'chalk'; |
@@ -8,5 +8,5 @@ { | ||
"typeRoots": [ | ||
"./config/typescript/typings", | ||
"./node_modules/@types", | ||
"../../node_modules/@types" | ||
"../../node_modules/@types", | ||
"./config/typescript/typings" | ||
], | ||
@@ -13,0 +13,0 @@ "types": ["supports-hyperlinks"] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
121373
6
27
811
+ Added@sewing-kit/types@^0.0.2
+ Added@sewing-kit/types@0.0.2(transitive)
+ Added@types/tapable@1.0.12(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@3.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedexeca@3.4.0(transitive)
+ Addedhuman-signals@1.1.1(transitive)
+ Addednpm-run-path@4.0.1(transitive)
+ Addedtapable@1.1.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedexeca@2.1.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removednpm-run-path@3.1.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updated@shopify/useful-types@^2.1.2
Updatedansi-escapes@^4.3.0
Updatedchalk@^3.0.0
Updatedexeca@^3.4.0