Skip to content

Commit

Permalink
Step ctx.task in each task
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Sep 4, 2023
1 parent 5af2c59 commit a25f747
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion node-src/lib/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import { Context, Task } from '../types';

type ValueFn = string | ((ctx: Context, task: Task) => string);

export const createTask = ({ title, steps, ...config }): Listr.ListrTask<Context> => ({
type TaskInput = Omit<Listr.ListrTask<Context>, 'task'> & {
name: string;
steps: ((ctx: Context, task: Listr.ListrTaskWrapper<Context> | Task) => void | Promise<void>)[];
};

export const createTask = ({
name,
title,
steps,
...config
}: TaskInput): Listr.ListrTask<Context> => ({
title,
task: async (ctx: Context, task: Listr.ListrTaskWrapper<Context>) => {
ctx.task = name;
ctx.title = title;
ctx.startedAt = Number.isInteger(ctx.now) ? ctx.now : new Date().getTime();
// eslint-disable-next-line no-restricted-syntax
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const setAuthorizationToken = async (ctx: Context) => {
};

export default createTask({
name: 'auth',
title: initial.title,
steps: [transitionTo(authenticating), setAuthorizationToken, transitionTo(authenticated, true)],
});
1 change: 1 addition & 0 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const buildStorybook = async (ctx: Context) => {
};

export default createTask({
name: 'build',
title: initial.title,
skip: async (ctx) => {
if (ctx.skip) return true;
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/gitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export const setGitInfo = async (ctx: Context, task: Task) => {
};

export default createTask({
name: 'gitInfo',
title: initial.title,
steps: [transitionTo(pending), setGitInfo],
});
1 change: 1 addition & 0 deletions node-src/tasks/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const announceBuild = async (ctx: Context) => {
};

export default createTask({
name: 'initialize',
title: initial.title,
skip: (ctx: Context) => ctx.skip,
steps: [transitionTo(pending), setEnvironment, announceBuild, transitionTo(success, true)],
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/prepareWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const runPrepareWorkspace = async (ctx: Context, task: Task) => {
};

export default createTask({
name: 'prepareWorkspace',
title: initial.title,
steps: [transitionTo(pending), runPrepareWorkspace, transitionTo(success, true)],
});
1 change: 1 addition & 0 deletions node-src/tasks/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const generateReport = async (ctx: Context) => {
};

export default createTask({
name: 'report',
title: initial.title,
skip: (ctx: Context) => ctx.skip,
steps: [transitionTo(pending), generateReport, transitionTo(success, true)],
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/restoreWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const runRestoreWorkspace = async () => {
};

export default createTask({
name: 'restoreWorkspace',
title: initial.title,
steps: [transitionTo(pending), runRestoreWorkspace, transitionTo(success, true)],
});
1 change: 1 addition & 0 deletions node-src/tasks/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const takeSnapshots = async (ctx: Context, task: Task) => {
};

export default createTask({
name: 'snapshot',
title: initial.title,
skip: (ctx: Context) => {
if (ctx.skip) return true;
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/storybookInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const setStorybookInfo = async (ctx: Context) => {
};

export default createTask({
name: 'storybookInfo',
title: initial.title,
skip: (ctx: Context) => ctx.skip,
steps: [transitionTo(pending), setStorybookInfo, transitionTo(success, true)],
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export const uploadStorybook = async (ctx: Context, task: Task) => {
};

export default createTask({
name: 'upload',
title: initial.title,
skip: (ctx: Context) => {
if (ctx.skip) return true;
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export const verifyBuild = async (ctx: Context, task: Task) => {
};

export default createTask({
name: 'verify',
title: initial.title,
skip: (ctx: Context) => {
if (ctx.skip) return true;
Expand Down
1 change: 1 addition & 0 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface Context {
argv: string[];
flags: Flags;
options: Options;
task: string;
title: string;
skip?: boolean;
skipSnapshots?: boolean;
Expand Down

0 comments on commit a25f747

Please sign in to comment.