semantic-release-yaml 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,17 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
## Options
|
|
72
|
+
|
|
73
|
+
Each command in `commands` takes the following options:
|
|
74
|
+
|
|
75
|
+
| Option | Required | Description |
|
|
76
|
+
| ---------- | -------- | ----------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `cwd` | no | The directory `file` is resolved against. Defaults to the directory semantic-release runs in. |
|
|
78
|
+
| `file` | yes | The YAML file to edit. |
|
|
79
|
+
| `selector` | yes | The field to set, or an array of fields. See [Lodash `set`](#lodash-set) and [Wildcards](#wildcards). |
|
|
80
|
+
| `value` | yes | The value to set the field to. |
|
|
81
|
+
|
|
71
82
|
## Lodash `template`
|
|
72
83
|
|
|
73
84
|
- Lodash `template`: https://lodash.com/docs/4.17.15#template
|
|
@@ -104,8 +115,48 @@ This means you can write the following command:
|
|
|
104
115
|
which could result in the following:
|
|
105
116
|
|
|
106
117
|
```yaml
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
meta:
|
|
119
|
+
version: 1.0.0
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Wildcards
|
|
123
|
+
|
|
124
|
+
A `*` in the selector matches every item of a list, or every key of a map. Both `modules[*].version` and `modules.*.version` are supported.
|
|
125
|
+
|
|
126
|
+
Given the following file:
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
modules:
|
|
130
|
+
- name: moduleABC
|
|
131
|
+
properties:
|
|
132
|
+
VERSION:
|
|
133
|
+
- name: moduleXYZ
|
|
134
|
+
properties:
|
|
135
|
+
VERSION:
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
the selector `modules[*].properties.VERSION` sets `VERSION` in every module:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
...
|
|
143
|
+
"selector": "modules[*].properties.VERSION",
|
|
144
|
+
"value": "${nextRelease.version}"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Unlike a selector without a wildcard, a selector with a wildcard never adds items to a list or creates missing parents: a module without `properties` is skipped. Only the last key may be added, when its parent map already exists. If a selector matches nothing, a warning is logged and the file is left as is.
|
|
149
|
+
|
|
150
|
+
## Multiple selectors
|
|
151
|
+
|
|
152
|
+
To set several fields to the same value, pass an array of selectors:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
...
|
|
157
|
+
"selector": ["version", "appVersion"],
|
|
158
|
+
"value": "${nextRelease.version}"
|
|
159
|
+
}
|
|
109
160
|
```
|
|
110
161
|
|
|
111
162
|
## Yaml comments
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ interface Command {
|
|
|
10
10
|
file: string;
|
|
11
11
|
/**
|
|
12
12
|
* The subpath leading to the field which should get a new value (evaluated with https://lodash.com/docs/4.17.15#set).
|
|
13
|
+
* A `*` segment matches every existing item of a sequence or key of a mapping.
|
|
14
|
+
* Multiple selectors can be given as an array; each one is set to `value`.
|
|
13
15
|
*/
|
|
14
|
-
selector: string
|
|
16
|
+
selector: string | Array<string>;
|
|
15
17
|
/**
|
|
16
18
|
* The next value to be inserted in the YAML file.
|
|
17
19
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("path");c=s(c);let l=require("lodash/template");l=s(l);let u=require("fs");u=s(u);let d=require("lodash/
|
|
2
|
-
`);return new
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("path");c=s(c);let l=require("lodash/template");l=s(l);let u=require("fs");u=s(u);let d=require("lodash/castArray");d=s(d);let f=require("lodash/set");f=s(f);let p=require("yaml-diff-patch"),m=require("js-yaml");m=s(m);let h=require("lodash/isPlainObject");h=s(h);let g=require("lodash/toPath");g=s(g);let _=require("lodash"),v=require("aggregate-error");v=s(v);let y=require("@semantic-release/error");y=s(y);let b=require("lodash/isString");b=s(b);let x=require("util");const S=e=>Array.isArray(e)||(0,h.default)(e),C=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function w(e,t,n){return t===`*`?Object.keys(e):C(e,t)||n&&!Array.isArray(e)?[t]:[]}function T(e,t){let n=(0,g.default)(t);if(!n.includes(`*`))return[n];let r=[],i=(e,t,a)=>{if(!S(e))return;let o=t===n.length-1;w(e,n[t],o).forEach(n=>{let s=[...a,n];o?r.push(s):i(e[n],t+1,s)})};return i(e,0,[]),r}const E=(e,{cwd:t=process.cwd(),env:n,logger:r,...i})=>{let a=(0,l.default)(e.cwd)(i),o=(0,l.default)(e.file)(i),s=(0,d.default)(e.selector).map(e=>(0,l.default)(e)(i)),h=(0,l.default)(e.value)(i),g=a?c.default.resolve(t,a):t,_=c.default.resolve(g,o);r.log(`Updating -> path: ${_} | selector: ${s.join(`, `)} | value: ${h}`);let v=u.default.readFileSync(_,`utf8`),y=m.default.load(v),b=m.default.load(v);if(typeof b!=`object`||!b)throw Error(`The file ${_} is not a valid YAML file.`);s.forEach(e=>{let t=T(b,e);t.length===0&&r.warn(`The selector ${e} did not match anything in ${_}.`),t.forEach(e=>(0,f.default)(b,e,h))});let x=(0,p.yamlDiffPatch)(v,y,b);u.default.writeFileSync(_,x)},[D]=`https://github.com/meesvandongen/semantic-release-yaml#readme`.split(`#`);function O(e){return(0,b.default)(e)?e:(0,x.inspect)(e,{breakLength:1/0,depth:2,maxArrayLength:5})}function k(e){return`${D}/blob/master/${e}`}function A(e,t){let n=[`for usage, see ${k(`README.md#options`)}`,``,`Your configuration for the \`${e}\` option is \`${O(t[e])}\`.`].join(`
|
|
2
|
+
`);return new y.default(`Invalid \`${e}\` option.`,e,n)}const j=e=>(0,_.isString)(e)&&e.trim().length>0,M=[{key:`cwd`,validator:(e=>t=>(0,_.isNil)(t)||e(t))(j)},{key:`file`,validator:j},{key:`selector`,validator:e=>j(e)||(0,_.isArray)(e)&&e.length>0&&e.every(j)},{key:`value`,validator:j}];function N(e){let t=e.flatMap(e=>M.reduce((t,{key:n,validator:r})=>{let i=e[n];return r(i)?t:t.concat(A(n,e))},[]));if(t.length>0)throw new v.default(t)}function P({commands:e},t){if(e.length>0)return N(e),e.forEach(e=>{E(e,t)}),`Prepared`}exports.prepare=P;
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["template","jsYaml","yamlDiffPatch","isString","inspect","SemanticReleaseError","isString","isNil","AggregateError","__create","__defProp","__getOwnPropDesc","__getOwnPropNames","__getProtoOf","__hasOwnProp","__copyProps","from","keys","i","n","key","to","except","k","desc","__toESM","mod","isNodeMode","target","path","lodash_template","fs","lodash_set","yaml_diff_patch","js_yaml","lodash","aggregate_error","_semantic_release_error","lodash_isString","util","yaml","context","interpretedCwd","command","interpretedFile","interpretedSelector","interpretedValue","workingDirectory","cwd","pathToFile","logger","yamlFileRaw","originalYamlFile","changedYamlFile","yamlResult","homepage","stringify","object","linkify","file","getError","message","isNonEmptyString","value","validators","validator","verifyCommands","errors","commands","prepare"],"sources":["../src/yaml.ts","../package.json","../src/get-error.ts","../src/verify-commands.ts","../src/index.ts"],"sourcesContent":["import path from \"path\";\nimport template from \"lodash/template\";\nimport fs from \"fs\";\nimport { Command } from \"./definitions/configuration.interface\";\nimport { SemanticContext } from \"./definitions/semantic-context.interface\";\nimport set from \"lodash/set\";\nimport { yamlDiffPatch } from \"yaml-diff-patch\";\nimport jsYaml from \"js-yaml\";\n\nexport const yaml = (\n command: Command,\n { cwd = process.cwd(), env, logger, ...context }: SemanticContext\n) => {\n const interpretedCwd = template(command.cwd)(context);\n const interpretedFile = template(command.file)(context);\n const interpretedSelector = template(command.selector)(context);\n const interpretedValue = template(command.value)(context);\n\n const workingDirectory = interpretedCwd\n ? path.resolve(cwd, interpretedCwd)\n : cwd;\n const pathToFile = path.resolve(workingDirectory, interpretedFile);\n\n logger.log(\n `Updating -> path: ${pathToFile} | selector: ${interpretedSelector} | value: ${interpretedValue}`\n );\n\n const yamlFileRaw = fs.readFileSync(pathToFile, \"utf8\");\n const originalYamlFile = jsYaml.load(yamlFileRaw);\n const changedYamlFile = jsYaml.load(yamlFileRaw);\n\n if (typeof changedYamlFile !== \"object\" || changedYamlFile === null) {\n throw new Error(`The file ${pathToFile} is not a valid YAML file.`);\n }\n\n set(changedYamlFile, interpretedSelector, interpretedValue);\n const yamlResult = yamlDiffPatch(\n yamlFileRaw,\n originalYamlFile,\n changedYamlFile\n );\n\n fs.writeFileSync(pathToFile, yamlResult);\n};\n","","import SemanticReleaseError from \"@semantic-release/error\";\nimport isString from \"lodash/isString\";\nimport { inspect } from \"util\";\nimport { Command } from \"./definitions/configuration.interface\";\nimport pkg from \"../package.json\";\n\nconst [homepage] = pkg.homepage.split(\"#\");\n\nfunction stringify(object: unknown) {\n if (isString(object)) {\n return object;\n }\n return inspect(object, {\n breakLength: Infinity,\n depth: 2,\n maxArrayLength: 5,\n });\n}\n\nfunction linkify(file: string) {\n return `${homepage}/blob/master/${file}`;\n}\n\nexport function getError(key: keyof Command, command: Command): Error {\n const message = [\n `for usage, see ${linkify(\"README.md#options\")}`,\n \"\",\n `Your configuration for the \\`${key}\\` option is \\`${stringify(\n command[key]\n )}\\`.`,\n ].join(\"\\n\");\n return new SemanticReleaseError(`Invalid \\`${key}\\` option.`, key, message);\n}\n","import { Command } from \"./definitions/configuration.interface\";\nimport { isNil } from \"lodash\";\nimport { isString } from \"lodash\";\nimport AggregateError from \"aggregate-error\";\nimport { getError } from \"./get-error\";\n\nconst isNonEmptyString = (value: unknown) =>\n isString(value) && value.trim().length > 0;\n\nconst isOptional =\n (validator: (value: unknown) => boolean) => (value: unknown) =>\n isNil(value) || validator(value);\n\ninterface Validator {\n key: keyof Command;\n validator: (value: unknown) => boolean;\n}\nconst validators: Array<Validator> = [\n { key: \"cwd\", validator: isOptional(isNonEmptyString) },\n { key: \"file\", validator: isNonEmptyString },\n { key: \"selector\", validator: isNonEmptyString },\n { key: \"value\", validator: isNonEmptyString },\n];\n\nexport function verifyCommands(commands: Array<Command>) {\n const errors = commands.flatMap((command) =>\n validators.reduce((errors, { key, validator }) => {\n const value = command[key];\n\n if (!validator(value)) {\n return errors.concat(getError(key, command));\n }\n return errors;\n }, [] as Array<Error>)\n );\n\n if (errors.length > 0) {\n throw new AggregateError(errors);\n }\n}\n","import { yaml } from \"./yaml\";\nimport { verifyCommands } from \"./verify-commands\";\nimport { Configuration } from \"./definitions/configuration.interface\";\nimport { SemanticContext } from \"./definitions/semantic-context.interface\";\n\nexport function prepare({ commands }: Configuration, context: SemanticContext) {\n if (commands.length > 0) {\n verifyCommands(commands);\n\n commands.forEach((command) => {\n yaml(command, context);\n });\n return \"Prepared\";\n }\n}\n"],"mappings":"A,i6BASA,MAAawC,GACX,EACA,CAAE,MAAM,QAAQ,IAAI,EAAG,MAAK,SAAQ,GAAGC,KACpC,CACH,IAAMC,GAAA,EAAiB1C,EAAAA,QAAAA,CAAS2C,EAAQ,GAAG,CAAC,CAACF,CAAO,EAC9CG,GAAA,EAAkB5C,EAAAA,QAAAA,CAAS2C,EAAQ,IAAI,CAAC,CAACF,CAAO,EAChDI,GAAA,EAAsB7C,EAAAA,QAAAA,CAAS2C,EAAQ,QAAQ,CAAC,CAACF,CAAO,EACxDK,GAAA,EAAmB9C,EAAAA,QAAAA,CAAS2C,EAAQ,KAAK,CAAC,CAACF,CAAO,EAElDM,EAAmBL,EACrBb,EAAA,QAAK,QAAQmB,EAAKN,CAAc,EAChCM,EACEC,EAAapB,EAAA,QAAK,QAAQkB,EAAkBH,CAAe,EAEjEM,EAAO,IACL,qBAAqBD,EAAW,eAAeJ,EAAoB,YAAYC,GACjF,EAEA,IAAMK,EAAcpB,EAAA,QAAG,aAAakB,EAAY,MAAM,EAChDG,EAAmBnD,EAAAA,QAAO,KAAKkD,CAAW,EAC1CE,EAAkBpD,EAAAA,QAAO,KAAKkD,CAAW,EAE/C,GAAI,OAAOE,GAAoB,WAAYA,EACzC,MAAU,MAAM,YAAYJ,EAAW,2BAA2B,GAGpE,EAAAjB,EAAA,QAAA,CAAIqB,EAAiBR,EAAqBC,CAAgB,EAC1D,IAAMQ,GAAA,EAAapD,EAAAA,cAAAA,CACjBiD,EACAC,EACAC,CACF,EAEAtB,EAAA,QAAG,cAAckB,EAAYK,CAAU,CACzC,EErCM,CAACC,GAAA,gEAAyB,MAA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,YAA2B,EAA0B,CAC7E,GAAID,EAAS,OAAS,EAMpB,OALAF,EAAeE,CAAQ,EAEvBA,EAAS,QAAS,GAAY,CAC5B5B,EAAKG,EAASF,CAAO,CACvB,CAAC,EACM,UAEX,C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["isPlainObject","toPath","template","castArray","jsYaml","set","yamlDiffPatch","isString","inspect","SemanticReleaseError","isString","isArray","isNil","AggregateError","__create","__defProp","__getOwnPropDesc","__getOwnPropNames","__getProtoOf","__hasOwnProp","__copyProps","from","keys","i","n","key","to","except","k","desc","__toESM","mod","isNodeMode","target","path","lodash_template","fs","lodash_castArray","lodash_set","yaml_diff_patch","js_yaml","lodash_isPlainObject","lodash_toPath","lodash","aggregate_error","_semantic_release_error","lodash_isString","util","isContainer","value","hasOwn","node","matchKeys","segment","isLast","resolvePaths","segments","selector","paths","walk","index","prefix","document","yaml","context","interpretedCwd","command","interpretedFile","interpretedSelectors","interpretedValue","workingDirectory","cwd","pathToFile","logger","yamlFileRaw","originalYamlFile","changedYamlFile","yamlResult","homepage","stringify","object","linkify","file","getError","message","isNonEmptyString","validators","validator","verifyCommands","errors","commands","prepare"],"sources":["../src/resolve-paths.ts","../src/yaml.ts","../package.json","../src/get-error.ts","../src/verify-commands.ts","../src/index.ts"],"sourcesContent":["import isPlainObject from \"lodash/isPlainObject\";\nimport toPath from \"lodash/toPath\";\n\nexport const WILDCARD = \"*\";\n\ntype Container = Record<string, unknown> | Array<unknown>;\n\nconst isContainer = (value: unknown): value is Container =>\n Array.isArray(value) || isPlainObject(value);\n\nconst hasOwn = (node: Container, key: string) =>\n Object.prototype.hasOwnProperty.call(node, key);\n\n/**\n * The keys of `node` that `segment` matches. Only the final segment of a\n * selector may introduce a new key, and only on a mapping: a sequence never\n * grows, so a match can not leave holes in it.\n */\nfunction matchKeys(node: Container, segment: string, isLast: boolean) {\n if (segment === WILDCARD) {\n return Object.keys(node);\n }\n if (hasOwn(node, segment) || (isLast && !Array.isArray(node))) {\n return [segment];\n }\n return [];\n}\n\n/**\n * Resolves a selector to the concrete paths that should be set in `document`.\n *\n * A selector without wildcards resolves to its own path, so it behaves exactly\n * like lodash's `set` (missing parents are created).\n *\n * A `*` segment matches every existing item of a sequence or key of a mapping.\n * For selectors with a wildcard nothing is created except the final key of a\n * mapping: every parent along the way must already exist, otherwise that match\n * is skipped.\n */\nexport function resolvePaths(\n document: unknown,\n selector: string\n): Array<Array<string>> {\n const segments = toPath(selector);\n\n if (!segments.includes(WILDCARD)) {\n return [segments];\n }\n\n const paths: Array<Array<string>> = [];\n\n const walk = (node: unknown, index: number, prefix: Array<string>) => {\n if (!isContainer(node)) {\n return;\n }\n\n const isLast = index === segments.length - 1;\n\n matchKeys(node, segments[index], isLast).forEach((key) => {\n const path = [...prefix, key];\n if (isLast) {\n paths.push(path);\n } else {\n walk((node as Record<string, unknown>)[key], index + 1, path);\n }\n });\n };\n\n walk(document, 0, []);\n\n return paths;\n}\n","import path from \"path\";\nimport template from \"lodash/template\";\nimport fs from \"fs\";\nimport { Command } from \"./definitions/configuration.interface\";\nimport { SemanticContext } from \"./definitions/semantic-context.interface\";\nimport castArray from \"lodash/castArray\";\nimport set from \"lodash/set\";\nimport { yamlDiffPatch } from \"yaml-diff-patch\";\nimport jsYaml from \"js-yaml\";\nimport { resolvePaths } from \"./resolve-paths\";\n\nexport const yaml = (\n command: Command,\n { cwd = process.cwd(), env, logger, ...context }: SemanticContext\n) => {\n const interpretedCwd = template(command.cwd)(context);\n const interpretedFile = template(command.file)(context);\n const interpretedSelectors = castArray(command.selector).map((selector) =>\n template(selector)(context)\n );\n const interpretedValue = template(command.value)(context);\n\n const workingDirectory = interpretedCwd\n ? path.resolve(cwd, interpretedCwd)\n : cwd;\n const pathToFile = path.resolve(workingDirectory, interpretedFile);\n\n logger.log(\n `Updating -> path: ${pathToFile} | selector: ${interpretedSelectors.join(\", \")} | value: ${interpretedValue}`\n );\n\n const yamlFileRaw = fs.readFileSync(pathToFile, \"utf8\");\n const originalYamlFile = jsYaml.load(yamlFileRaw);\n const changedYamlFile = jsYaml.load(yamlFileRaw);\n\n if (typeof changedYamlFile !== \"object\" || changedYamlFile === null) {\n throw new Error(`The file ${pathToFile} is not a valid YAML file.`);\n }\n\n interpretedSelectors.forEach((selector) => {\n const paths = resolvePaths(changedYamlFile, selector);\n\n if (paths.length === 0) {\n logger.warn(\n `The selector ${selector} did not match anything in ${pathToFile}.`\n );\n }\n\n paths.forEach((keys) => set(changedYamlFile, keys, interpretedValue));\n });\n\n const yamlResult = yamlDiffPatch(\n yamlFileRaw,\n originalYamlFile,\n changedYamlFile\n );\n\n fs.writeFileSync(pathToFile, yamlResult);\n};\n","","import SemanticReleaseError from \"@semantic-release/error\";\nimport isString from \"lodash/isString\";\nimport { inspect } from \"util\";\nimport { Command } from \"./definitions/configuration.interface\";\nimport pkg from \"../package.json\";\n\nconst [homepage] = pkg.homepage.split(\"#\");\n\nfunction stringify(object: unknown) {\n if (isString(object)) {\n return object;\n }\n return inspect(object, {\n breakLength: Infinity,\n depth: 2,\n maxArrayLength: 5,\n });\n}\n\nfunction linkify(file: string) {\n return `${homepage}/blob/master/${file}`;\n}\n\nexport function getError(key: keyof Command, command: Command): Error {\n const message = [\n `for usage, see ${linkify(\"README.md#options\")}`,\n \"\",\n `Your configuration for the \\`${key}\\` option is \\`${stringify(\n command[key]\n )}\\`.`,\n ].join(\"\\n\");\n return new SemanticReleaseError(`Invalid \\`${key}\\` option.`, key, message);\n}\n","import { Command } from \"./definitions/configuration.interface\";\nimport { isNil } from \"lodash\";\nimport { isString } from \"lodash\";\nimport { isArray } from \"lodash\";\nimport AggregateError from \"aggregate-error\";\nimport { getError } from \"./get-error\";\n\nconst isNonEmptyString = (value: unknown) =>\n isString(value) && value.trim().length > 0;\n\nconst isNonEmptyStringOrArrayOfThem = (value: unknown) =>\n isNonEmptyString(value) ||\n (isArray(value) && value.length > 0 && value.every(isNonEmptyString));\n\nconst isOptional =\n (validator: (value: unknown) => boolean) => (value: unknown) =>\n isNil(value) || validator(value);\n\ninterface Validator {\n key: keyof Command;\n validator: (value: unknown) => boolean;\n}\nconst validators: Array<Validator> = [\n { key: \"cwd\", validator: isOptional(isNonEmptyString) },\n { key: \"file\", validator: isNonEmptyString },\n { key: \"selector\", validator: isNonEmptyStringOrArrayOfThem },\n { key: \"value\", validator: isNonEmptyString },\n];\n\nexport function verifyCommands(commands: Array<Command>) {\n const errors = commands.flatMap((command) =>\n validators.reduce((errors, { key, validator }) => {\n const value = command[key];\n\n if (!validator(value)) {\n return errors.concat(getError(key, command));\n }\n return errors;\n }, [] as Array<Error>)\n );\n\n if (errors.length > 0) {\n throw new AggregateError(errors);\n }\n}\n","import { yaml } from \"./yaml\";\nimport { verifyCommands } from \"./verify-commands\";\nimport { Configuration } from \"./definitions/configuration.interface\";\nimport { SemanticContext } from \"./definitions/semantic-context.interface\";\n\nexport function prepare({ commands }: Configuration, context: SemanticContext) {\n if (commands.length > 0) {\n verifyCommands(commands);\n\n commands.forEach((command) => {\n yaml(command, context);\n });\n return \"Prepared\";\n }\n}\n"],"mappings":"A,6hCAOA,MAAMgD,EAAe,GACnB,MAAM,QAAQC,CAAK,IAAA,EAAKjD,EAAAA,QAAAA,CAAciD,CAAK,EAEvCC,GAAU,EAAiB,IAC/B,OAAO,UAAU,eAAe,KAAKC,EAAM1B,CAAG,EAOhD,SAAS2B,EAAU,EAAiB,EAAiB,EAAiB,CAOpE,OANIC,IAAA,IACK,OAAO,KAAKF,CAAI,EAErBD,EAAOC,EAAME,CAAO,GAAMC,GAAU,CAAC,MAAM,QAAQH,CAAI,EAClD,CAACE,CAAO,EAEV,CAAC,CACV,CAaA,SAAgBE,EACd,EACA,EACsB,CACtB,IAAMC,GAAA,EAAWvD,EAAAA,QAAAA,CAAOwD,CAAQ,EAEhC,GAAI,CAACD,EAAS,SAAA,GAAiB,EAC7B,MAAO,CAACA,CAAQ,EAGlB,IAAME,EAA8B,CAAC,EAE/BC,GAAQ,EAAe,EAAe,IAA0B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