Skip to content

Commit 79c244f

Browse files
author
Murat
committed
feat(script): add ability to call any task
1 parent 816749e commit 79c244f

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/tasks/scriptTask.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { processScript } from '../processScript';
2-
import { ScriptTaskType } from '../types/mod.types';
2+
import { ModStep, ScriptTaskType } from '../types/mod.types';
33
import { checkCondition } from '../utils/checkCondition';
44
import { getErrMessage } from '../utils/getErrMessage';
55
import { setState } from '../utils/setState';
6+
import type { taskManager } from '../utils/taskManager';
67
import { variables } from '../variables';
78

89
export async function scriptTask(args: {
910
configPath: string;
1011
packageName: string;
1112
task: ScriptTaskType;
13+
taskManager: typeof taskManager;
1214
}): Promise<void> {
1315
const { task } = args;
1416

@@ -27,11 +29,33 @@ export async function scriptTask(args: {
2729
error: false,
2830
});
2931
try {
32+
const ctx = Object.entries(args.taskManager.task).reduce(
33+
(ctx, [taskName, task]) => {
34+
ctx[taskName] = async (actionOneOrList, opts) => {
35+
const dynamicTask: ModStep = {
36+
task: taskName,
37+
...opts,
38+
actions: Array.isArray(actionOneOrList)
39+
? actionOneOrList
40+
: [actionOneOrList],
41+
};
42+
await task.runTask({
43+
configPath: args.configPath,
44+
packageName: args.packageName,
45+
task: dynamicTask,
46+
taskManager: args.taskManager,
47+
});
48+
};
49+
return ctx;
50+
},
51+
{} as Record<string, (...args: any[]) => any>
52+
);
3053
const resultValue = await processScript(
3154
action.script,
3255
variables,
3356
false,
34-
true
57+
true,
58+
ctx
3559
);
3660
if (action.name) variables.set(action.name, resultValue);
3761
} catch (e) {

src/utils/runTask.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export async function runTask(args: {
1111
configPath,
1212
packageName,
1313
task,
14+
taskManager,
1415
});
1516
}

src/utils/taskManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface RunTaskArgs {
6767
configPath: string;
6868
packageName: string;
6969
task: any;
70+
taskManager: any;
7071
}
7172

7273
export interface TaskExports {

website/docs/guides/task-types/other-tasks/script.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ In this example:
4747
4848
- We evaluate a script to check if `some-task` was run with success and define `run_app_delegate` variable.
4949
- `app_delegate` task will run if `run_app_delegate` is true.
50+
51+
You can also call any task in a script:
52+
53+
```yaml
54+
steps:
55+
- task: script
56+
actions:
57+
- script: |-
58+
await app_delegate({
59+
prepend: 'some import'
60+
});
61+
```

0 commit comments

Comments
 (0)