semantic-release-yaml 1.1.1 → 1.1.3
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 +1 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,8 +33,6 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
33
33
|
{
|
|
34
34
|
// The current working directory is the root of the project.
|
|
35
35
|
"cwd": "./",
|
|
36
|
-
// Currently only supports "prepare" phase.
|
|
37
|
-
"phase": "prepare",
|
|
38
36
|
// The file to edit
|
|
39
37
|
"file": "./Chart.yaml",
|
|
40
38
|
// The field in the file to edit.
|
|
@@ -44,7 +42,6 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
44
42
|
},
|
|
45
43
|
{
|
|
46
44
|
"cwd": "./",
|
|
47
|
-
"phase": "prepare",
|
|
48
45
|
// A dynamic file name.
|
|
49
46
|
"file": "./${branch.name}.yaml",
|
|
50
47
|
"selector": "name",
|
|
@@ -75,7 +72,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
75
72
|
|
|
76
73
|
- Lodash `template`: https://lodash.com/docs/4.17.15#template
|
|
77
74
|
|
|
78
|
-
Each variable (`cwd`, `
|
|
75
|
+
Each variable (`cwd`, `file`, `selector`, `value`) in a command is evaluated via lodash's `template` function.
|
|
79
76
|
|
|
80
77
|
```json
|
|
81
78
|
{
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("path"),
|
|
1
|
+
var e=require("path"),t=require("lodash/template"),r=require("fs"),a=require("lodash/set"),l=require("yaml-diff-patch"),i=require("js-yaml"),o=require("lodash"),n=require("aggregate-error"),u=require("@semantic-release/error"),d=require("lodash/isString"),f=require("util");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/s(e),h=/*#__PURE__*/s(t),g=/*#__PURE__*/s(r),p=/*#__PURE__*/s(a),v=/*#__PURE__*/s(i),m=/*#__PURE__*/s(n),y=/*#__PURE__*/s(u),q=/*#__PURE__*/s(d);const w=["cwd","env","logger"],[$]="https://github.com/meesvandongen/semantic-release-yaml#readme".split("#"),b=e=>o.isString(e)&&e.trim().length>0,k=[{key:"cwd",validator:(j=b,e=>o.isNil(e)||j(e))},{key:"file",validator:b},{key:"selector",validator:b},{key:"value",validator:b}];var j;exports.prepare=function({commands:e},t){if(e.length>0)return function(e){const t=e.flatMap(e=>k.reduce((t,{key:r,validator:a})=>a(e[r])?t:t.concat(function(e,t){const r=[`for usage, see ${$}/blob/master/README.md#options`,"",`Your configuration for the \`${e}\` option is \`${a=t[e],q.default(a)?a:f.inspect(a,{breakLength:Infinity,depth:2,maxArrayLength:5})}\`.`].join("\n");var a;return new y.default(`Invalid \`${e}\` option.`,e,r)}(r,e)),[]));if(t.length>0)throw new m.default(t)}(e),e.forEach(e=>{((e,t)=>{let{cwd:r=process.cwd(),logger:a}=t,i=function(e,t){if(null==e)return{};var r,a,l={},i=Object.keys(e);for(a=0;a<i.length;a++)t.indexOf(r=i[a])>=0||(l[r]=e[r]);return l}(t,w);const o=h.default(e.cwd)(i),n=h.default(e.file)(i),u=h.default(e.selector)(i),d=h.default(e.value)(i),f=o?c.default.resolve(r,o):r,s=c.default.resolve(f,n);a.log(`Updating -> path: ${s} | selector: ${u} | value: ${d}`);const m=g.default.readFileSync(s,"utf8"),y=v.default.load(m),q=v.default.load(m);if("object"!=typeof q||null===q)throw new Error(`The file ${s} is not a valid YAML file.`);p.default(q,u,d);const $=l.yamlDiffPatch(m,y,q);g.default.writeFileSync(s,$)})(e,t)}),"Prepared"};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/get-error.ts","../src/verify-commands.ts","../src/index.ts","../src/yaml.ts"],"sourcesContent":["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: \"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/get-error.ts","../src/verify-commands.ts","../src/index.ts","../src/yaml.ts"],"sourcesContent":["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","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"],"names":["homepage","split","isNonEmptyString","value","isString","trim","length","validators","key","validator","isNil","commands","context","errors","flatMap","command","reduce","concat","message","object","inspect","breakLength","Infinity","depth","maxArrayLength","join","SemanticReleaseError","getError","AggregateError","verifyCommands","forEach","cwd","process","logger","interpretedCwd","template","interpretedFile","file","interpretedSelector","selector","interpretedValue","workingDirectory","path","resolve","pathToFile","log","yamlFileRaw","fs","readFileSync","originalYamlFile","jsYaml","load","changedYamlFile","Error","set","yamlResult","yamlDiffPatch","writeFileSync","yaml"],"mappings":"8hBAMOA,mEAAyBC,MAAM,KCAhCC,EAAoBC,GACxBC,WAASD,IAAUA,EAAME,OAAOC,OAAS,EAUrCC,EAA+B,CACnC,CAAEC,IAAK,MAAOC,WARbA,EAQmCP,EARSC,GAC3CO,QAAMP,IAAUM,EAAUN,KAQ5B,CAAEK,IAAK,OAAQC,UAAWP,GAC1B,CAA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iBd,EAAqBE,GAC1C,MAAMe,EAAaC,gBACjBV,EACAG,EACAG,GAGFL,UAAGU,cAAcb,EAAYW,IDhCzBG,CAAK3C,EAASH,KAET"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Configuration } from "./definitions/configuration.interface";
|
|
2
2
|
import { SemanticContext } from "./definitions/semantic-context.interface";
|
|
3
|
-
export declare function prepare(
|
|
3
|
+
export declare function prepare({ commands }: Configuration, context: SemanticContext): "Prepared" | undefined;
|
package/package.json
CHANGED