Skip to content

Commit f03a81e

Browse files
authored
Merge pull request #33 from sontx/task-decorator
Task decorators
2 parents 153e1b6 + b3a335e commit f03a81e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+503
-348
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ See more details in the [Plugin](docs/plugin/plugin.md) document.
174174
The CLI tool can be configured using a configuration file or environment variables.
175175
The configuration provider will look up in this order:
176176

177-
1. `letrun.json` in the runner directory.
177+
1. `letrun.mjson` in the runner directory.
178178
2. `letrun.yaml` in the runner directory.
179179
3. `letrun.yml` in the runner directory.
180180
4. Lookup from environment variables.
@@ -261,7 +261,7 @@ npm run build
261261
```sh
262262
cd dist
263263

264-
node letrun.js <workflow-file>
264+
node letrun.mjs <workflow-file>
265265
```
266266

267267
### License

bin/letrun

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
exec node "letrun.js" "$@"
3+
exec node "letrun.mjs" "$@"

bin/letrun.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ IF EXIST "%dp0%\node.exe" (
1414
SET PATHEXT=%PATHEXT:;.JS;=;%
1515
)
1616

17-
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "letrun.js" %*
17+
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "letrun.mjs" %*

bin/letrun.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
99
$ret=0
1010
# Support pipeline input
1111
if ($MyInvocation.ExpectingInput) {
12-
$input | & "node$exe" "letrun.js" $args
12+
$input | & "node$exe" "letrun.mjs" $args
1313
} else {
14-
& "node$exe" "letrun.js" $args
14+
& "node$exe" "letrun.mjs" $args
1515
}
1616
$ret=$LASTEXITCODE
1717
exit $ret

docs/task/task-handler.md

+18-11
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ A task handler should have the following structure:
5454
- `name`: The name of the task, this is optional. We'll use the file name or package name as the task name if not defined.
5555
- `description`: A brief description of the task, this is optional.
5656
- `version`: The version of the task, this is optional. We'll use the package version if not defined.
57-
- `parameters`: An object that describes the input parameters of the task for showing help.
58-
- `handle`: The function that executes the task.
57+
- `parameters`: An object that describes the input parameters of the task for showing help. (calls `Schema.describe()` from Joi)
58+
- `handle`: The function that executes the task. This is required.
59+
60+
There are alternative ways to define those fields by using these corresponding decorators:
61+
62+
- `@Name`: The name of the task.
63+
- `@Description`: A brief description of the task.
64+
- `@Version`: The version of the task.
65+
- `@Parameters`: An object that describes the input parameters of the task for showing help.
66+
67+
> _Vanilla JS_ does not support decorators yet, so you need to use Babel or TypeScript to work with them.
5968
6069
This is an example of a custom task:
6170

6271
```ts
63-
import { validateParameters } from '@letrun/core';
72+
import { validateParameters, Name, Parameters } from '@letrun/core';
6473
import { TaskHandler } from '@letrun/common';
6574
import Joi from 'joi';
6675

@@ -72,10 +81,9 @@ const Schema = Joi.object<TaskParameters>({
7281
message: Joi.string().description('The message to say greeting').required(),
7382
});
7483

75-
export default class GreatingTaskHandler implements TaskHandler {
76-
name = 'greeting';
77-
parameters = Schema.describe();
78-
84+
@Name('greeting')
85+
@Parameters(Schema)
86+
export default class GreetingTaskHandler implements TaskHandler {
7987
async handle({ task }: TaskHandlerInput) {
8088
const { message } = validateParameters(task.parameters, Schema);
8189
const effectiveMessage = `Hello, ${message}!`;
@@ -88,7 +96,7 @@ export default class GreatingTaskHandler implements TaskHandler {
8896
Here is another example that will uppercase the input string:
8997

9098
```ts
91-
import { validateParameters } from '@letrun/core';
99+
import { validateParameters, Name, Parameters } from '@letrun/core';
92100
import { TaskHandler } from '@letrun/common';
93101
import Joi from 'joi';
94102

@@ -100,10 +108,9 @@ const Schema = Joi.object<TaskParameters>({
100108
value: Joi.string().description('The string to uppercase').required(),
101109
});
102110

111+
@Name('uppercase')
112+
@Parameters(Schema)
103113
export default class UppercaseTaskHandler implements TaskHandler {
104-
name = 'uppercase';
105-
parameters = Schema.describe();
106-
107114
async handle({ task }: TaskHandlerInput) {
108115
const { value } = validateParameters(task.parameters, Schema);
109116
return value.toUpperCase();

esbuild.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const options = {
99
bundle: true,
1010
tsconfig: 'tsconfig.json',
1111
platform: 'node',
12-
target: 'esnext',
12+
target: 'es2022',
1313
plugins: [nodeExternalsPlugin()],
1414
};
1515

0 commit comments

Comments
 (0)