UNPKG

2.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const yaml = tslib_1.__importStar(require("yaml"));
5const CustomErrors_1 = require("../errors/CustomErrors");
6const checkCommandNecessryFields = (commandContents) => {
7 if (!commandContents.run || typeof commandContents.run !== 'string') {
8 throw new CustomErrors_1.IncompleteOpsYml('The run command must be included as a string');
9 }
10};
11const checkWorkflowNecessryFields = (workflowContents) => {
12 if (!workflowContents.steps || !workflowContents.steps.length) {
13 throw new CustomErrors_1.IncompleteOpsYml('The run command must be included as a string');
14 }
15 workflowContents.steps.forEach(step => {
16 if (!step || typeof step !== 'string') {
17 throw new CustomErrors_1.IncompleteOpsYml('Each step should be a non-empty string');
18 }
19 });
20};
21const checkOpNecessaryFields = (opContents) => {
22 if (!opContents.name || typeof opContents.name !== 'string') {
23 throw new CustomErrors_1.IncompleteOpsYml('Op name must be a non-empty string');
24 }
25 if (!opContents.description || typeof opContents.description !== 'string') {
26 throw new CustomErrors_1.IncompleteOpsYml('Op description must be a non-empty string');
27 }
28 if (!opContents.isPublic === undefined ||
29 typeof opContents.isPublic !== 'boolean') {
30 throw new CustomErrors_1.IncompleteOpsYml('Your ops.yml file is missing the public field, please add `public:false` to publish your op as private');
31 }
32 return true;
33};
34exports.parseYaml = (manifest) => {
35 const yamlContents = manifest && yaml.parse(manifest);
36 if (!yamlContents)
37 throw new CustomErrors_1.IncompleteOpsYml('Ops.yml is empty');
38 if (yamlContents.ops) {
39 yamlContents.ops = yamlContents.ops.map(op => {
40 const newOp = Object.assign({}, op);
41 newOp.isPublic = newOp.public;
42 delete newOp.public;
43 checkOpNecessaryFields(newOp);
44 checkCommandNecessryFields(newOp);
45 return newOp;
46 });
47 }
48 if (yamlContents.workflows) {
49 yamlContents.workflows = yamlContents.workflows.map(wf => {
50 const newWf = Object.assign({}, wf);
51 newWf.isPublic = newWf.public;
52 delete newWf.public;
53 checkOpNecessaryFields(newWf);
54 checkWorkflowNecessryFields(newWf);
55 return newWf;
56 });
57 }
58 return yamlContents;
59};