-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.ts
75 lines (65 loc) · 2.17 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {Command, flags} from '@oclif/command'
import * as fs from 'fs-extra'
import * as path from 'path'
import {syncProcessArray} from '../utils'
import WorkflowService from '../workflows'
const yaml = require('js-yaml')
const readYAMLFromRelativePath = async (relativeFilepath: string) => {
const fileContents = await fs.readFile(path.join(process.cwd(), relativeFilepath), 'utf8')
return yaml.load(fileContents)
}
export default class Run extends Command {
static description = 'run leif state workflows'
static flags = {
'dry-run': flags.boolean({
char: 'd',
description: 'view output without committing changes',
}),
dir: flags.string({
char: 'f',
description: 'absolute path to directory with supporting files',
required: true,
default: '.',
}),
workflow: flags.string({
char: 'w',
description: 'run a specific workflow instead of all workflows',
multiple: true,
}),
sequence: flags.string({
char: 's',
description: 'run a specific sequence in a workflow',
dependsOn: ['workflow'],
multiple: true,
}),
}
static args = [
{
name: 'yaml',
description: 'path to a leif yaml file',
required: true,
},
]
async run() {
const {args, flags} = this.parse(Run)
const dir = flags.dir === '.' ? process.cwd() : flags.dir
const dryRun = Boolean(flags['dry-run'])
const runWorkflowService = async (workflowFilepath: string) => {
const yamlContents = await readYAMLFromRelativePath(workflowFilepath)
let preparedWorkflows = WorkflowService.workflowsFromYaml(yamlContents, dir, dryRun)
if (flags.workflow) {
const workflows = flags.workflow
const sequences = flags.sequence
preparedWorkflows = preparedWorkflows.filter(workflow => {
const shouldInclude = workflows.includes(workflow.id)
if (shouldInclude) {
workflow.sequences = workflow.sequences.filter(sequence => sequences.includes(sequence.id))
}
return shouldInclude
})
}
return WorkflowService.runMany(preparedWorkflows)
}
syncProcessArray([args.yaml], runWorkflowService)
}
}