npm run format -ws
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import { TemplateContext } from "../templates/template-context"
|
||||
import {
|
||||
TemplateToken,
|
||||
TemplateTokenError,
|
||||
} from "../templates/tokens/template-token"
|
||||
import { convertConcurrency } from "./converter/concurrency"
|
||||
import { convertOn } from "./converter/events"
|
||||
import { handleTemplateTokenErrors } from "./converter/handle-errors"
|
||||
import { convertJobs } from "./converter/jobs"
|
||||
import { WorkflowTemplate } from "./workflow-template"
|
||||
import {TemplateContext} from "../templates/template-context";
|
||||
import {TemplateToken, TemplateTokenError} from "../templates/tokens/template-token";
|
||||
import {convertConcurrency} from "./converter/concurrency";
|
||||
import {convertOn} from "./converter/events";
|
||||
import {handleTemplateTokenErrors} from "./converter/handle-errors";
|
||||
import {convertJobs} from "./converter/jobs";
|
||||
import {WorkflowTemplate} from "./workflow-template";
|
||||
|
||||
export enum ErrorPolicy {
|
||||
ReturnErrorsOnly,
|
||||
TryConversion,
|
||||
TryConversion
|
||||
}
|
||||
|
||||
export function convertWorkflowTemplate(
|
||||
@@ -19,62 +16,53 @@ export function convertWorkflowTemplate(
|
||||
root: TemplateToken,
|
||||
errorPolicy: ErrorPolicy = ErrorPolicy.ReturnErrorsOnly
|
||||
): WorkflowTemplate {
|
||||
const result = {} as WorkflowTemplate
|
||||
const result = {} as WorkflowTemplate;
|
||||
|
||||
if (
|
||||
context.errors.getErrors().length > 0 &&
|
||||
errorPolicy === ErrorPolicy.ReturnErrorsOnly
|
||||
) {
|
||||
result.errors = context.errors.getErrors().map((x) => ({
|
||||
Message: x.message,
|
||||
}))
|
||||
return result
|
||||
if (context.errors.getErrors().length > 0 && errorPolicy === ErrorPolicy.ReturnErrorsOnly) {
|
||||
result.errors = context.errors.getErrors().map(x => ({
|
||||
Message: x.message
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
const rootMapping = root.assertMapping("root")
|
||||
const rootMapping = root.assertMapping("root");
|
||||
|
||||
for (const item of rootMapping) {
|
||||
const key = item.key.assertString("root key")
|
||||
const key = item.key.assertString("root key");
|
||||
|
||||
switch (key.value) {
|
||||
case "on":
|
||||
result.events = handleTemplateTokenErrors(root, context, {}, () =>
|
||||
convertOn(context, item.value)
|
||||
)
|
||||
break
|
||||
result.events = handleTemplateTokenErrors(root, context, {}, () => convertOn(context, item.value));
|
||||
break;
|
||||
|
||||
case "jobs":
|
||||
result.jobs = handleTemplateTokenErrors(root, context, [], () =>
|
||||
convertJobs(context, item.value)
|
||||
)
|
||||
break
|
||||
result.jobs = handleTemplateTokenErrors(root, context, [], () => convertJobs(context, item.value));
|
||||
break;
|
||||
|
||||
case "concurrency":
|
||||
handleTemplateTokenErrors(root, context, {}, () =>
|
||||
convertConcurrency(context, item.value)
|
||||
)
|
||||
result.concurrency = item.value
|
||||
break
|
||||
handleTemplateTokenErrors(root, context, {}, () => convertConcurrency(context, item.value));
|
||||
result.concurrency = item.value;
|
||||
break;
|
||||
case "env":
|
||||
result.env = item.value
|
||||
break
|
||||
result.env = item.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof TemplateTokenError) {
|
||||
context.error(err.token, err)
|
||||
context.error(err.token, err);
|
||||
} else {
|
||||
// Report error for the root node
|
||||
context.error(root, err)
|
||||
context.error(root, err);
|
||||
}
|
||||
} finally {
|
||||
if (context.errors.getErrors().length > 0) {
|
||||
result.errors = context.errors.getErrors().map((x) => ({
|
||||
Message: x.message,
|
||||
}))
|
||||
result.errors = context.errors.getErrors().map(x => ({
|
||||
Message: x.message
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user