semantic-release-yaml 1.0.4 → 1.1.2
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 +78 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/yaml.d.ts +1 -1
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -18,22 +18,99 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
18
18
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
|
+
// We specify the branches, on which semantic-release should run.
|
|
22
|
+
// This will be used in a later step, when we use the current
|
|
23
|
+
// branch name as variables in the configuration.
|
|
24
|
+
"branches": ["main", "next"],
|
|
21
25
|
"plugins": [
|
|
26
|
+
"@semantic-release/commit-analyzer",
|
|
27
|
+
"@semantic-release/npm",
|
|
22
28
|
[
|
|
23
29
|
"semantic-release-yaml",
|
|
24
30
|
{
|
|
31
|
+
// A list of files to edit.
|
|
25
32
|
"commands": [
|
|
26
33
|
{
|
|
34
|
+
// The current working directory is the root of the project.
|
|
27
35
|
"cwd": "./",
|
|
36
|
+
// Currently only supports "prepare" phase.
|
|
28
37
|
"phase": "prepare",
|
|
38
|
+
// The file to edit
|
|
29
39
|
"file": "./Chart.yaml",
|
|
40
|
+
// The field in the file to edit.
|
|
30
41
|
"selector": "version",
|
|
42
|
+
// The value to set the field to.
|
|
43
|
+
"value": "${nextRelease.version}"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"cwd": "./",
|
|
47
|
+
"phase": "prepare",
|
|
48
|
+
// A dynamic file name.
|
|
49
|
+
"file": "./${branch.name}.yaml",
|
|
50
|
+
"selector": "name",
|
|
31
51
|
"value": "${nextRelease.version}"
|
|
32
52
|
}
|
|
33
53
|
]
|
|
34
54
|
}
|
|
35
55
|
],
|
|
36
|
-
|
|
56
|
+
[
|
|
57
|
+
"@semantic-release/git",
|
|
58
|
+
{
|
|
59
|
+
// Make sure Chart.yaml is pushed to the remote repository
|
|
60
|
+
"assets": [
|
|
61
|
+
"package.json",
|
|
62
|
+
"Chart.yaml",
|
|
63
|
+
// Also include main.yaml and next.yaml. These are the possible
|
|
64
|
+
// outcomes of the second command: the dynamic file name.
|
|
65
|
+
"./main.yaml",
|
|
66
|
+
"./next.yaml"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
]
|
|
37
70
|
]
|
|
38
71
|
}
|
|
39
72
|
```
|
|
73
|
+
|
|
74
|
+
## Lodash `template`
|
|
75
|
+
|
|
76
|
+
- Lodash `template`: https://lodash.com/docs/4.17.15#template
|
|
77
|
+
|
|
78
|
+
Each variable (`cwd`, `phase`, `file`, `selector`, `value`) in a command is evaluated via lodash's `template` function.
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
...
|
|
83
|
+
"value": "${nextRelease.version}"
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Available variables
|
|
88
|
+
|
|
89
|
+
You can use all variables available in the [semantic-release context](https://semantic-release.gitbook.io/semantic-release/developer-guide/plugin)
|
|
90
|
+
|
|
91
|
+
## Lodash `set`
|
|
92
|
+
|
|
93
|
+
- Lodash `set`: https://lodash.com/docs/4.17.15#set
|
|
94
|
+
|
|
95
|
+
Next to this; selector is used by lodash's `set` function to set the value of the field.
|
|
96
|
+
|
|
97
|
+
This means you can write the following command:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
...
|
|
102
|
+
"selector": "meta.version",
|
|
103
|
+
"value": "${nextRelease.version}"
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
which could result in the following:
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
version:
|
|
111
|
+
value: "1.0.0"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Yaml comments
|
|
115
|
+
|
|
116
|
+
Yaml comments will be preserved.
|
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),p=/*#__PURE__*/s(r),g=/*#__PURE__*/s(a),v=/*#__PURE__*/s(i),y=/*#__PURE__*/s(n),m=/*#__PURE__*/s(u),q=/*#__PURE__*/s(d);const w=["cwd","env","logger"],[k]="https://github.com/meesvandongen/semantic-release-yaml#readme".split("#"),$=e=>o.isString(e)&&e.trim().length>0,b=[{key:"cwd",validator:(j=$,e=>o.isNil(e)||j(e))},{key:"file",validator:$},{key:"phase",validator:$},{key:"selector",validator:$},{key:"value",validator:$}];var j;exports.prepare=function(e,t){const r=e.commands.filter(e=>"prepare"===h.default(e.phase)(t));if(r.length>0)return function(e){const t=e.flatMap(e=>b.reduce((t,{key:r,validator:a})=>a(e[r])?t:t.concat(function(e,t){const r=[`for usage, see ${k}/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 m.default(`Invalid \`${e}\` option.`,e,r)}(r,e)),[]));if(t.length>0)throw new y.default(t)}(r),r.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 y=p.default.readFileSync(s,"utf8"),m=v.default.load(y),q=v.default.load(y);if("object"!=typeof q||null===q)throw new Error(`The file ${s} is not a valid YAML file.`);g.default(q,u,d);const k=l.yamlDiffPatch(y,m,q);p.default.writeFileSync(s,k)})(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: \"phase\", validator: isNonEmptyString },\n { key: \"selector\", 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: \"phase\", 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\";\nimport template from \"lodash/template\";\n\nexport function prepare(pluginConfig: Configuration, context: SemanticContext) {\n const commands = pluginConfig.commands.filter((command) => {\n const phase = template(command.phase)(context);\n return phase === \"prepare\";\n });\n\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","pluginConfig","context","commands","filter","command","template","phase","errors","flatMap","reduce","concat","message","object","inspect","breakLength","Infinity","depth","maxArrayLength","join","SemanticReleaseError","getError","AggregateError","verifyCommands","forEach","cwd","process","logger","interpretedCwd","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,CAAEM,IAAK,QAASC,UAAWP,GAC3B,CAAEM,IAAK,WAAYC,UAAWP,GAC9B,CAAEM,IAAK,QAASC,UAAWP,IAZ1BO,IAAAA,2BCJqBE,EAA6BC,GACnD,MAAMC,EAAWF,EAAaE,SAASC,OAAQC,GAE5B,YADHC,UAASD,EAAQE,MAAjBD,CAAwBJ,IAIxC,GAAIC,EAASP,OAAS,EAMpB,gBDO2BO,GAC7B,MAAMK,EAASL,EAASM,QAASJ,GAC/BR,EAAWa,OAAO,CAACF,GAAUV,IAAAA,EAAKC,UAAAA,KAG3BA,EAFSM,EAAQP,IAKfU,EAFEA,EAAOG,gBDRGb,EAAoBO,GAC3C,MAAMO,EAAU,mBAJNtB,kCAMR,mCACgCQ,mBAnBjBe,EAoBbR,EAAQP,GAnBRJ,UAASmB,GACJA,EAEFC,UAAQD,EAAQ,CACrBE,YAAaC,SACbC,MAAO,EACPC,eAAgB,UAehBC,KAAK,MAtBT,IAAmBN,EAuBjB,WAAWO,uBAAkCtB,cAAiBA,EAAKc,GCAxCS,CAASvB,EAAKO,IAGpC,KAGL,GAAIG,EAAOZ,OAAS,EAClB,UAAU0B,UAAed,GCzBzBe,CAAepB,GAEfA,EAASqB,QAASnB,ICNF,EAClBA,WACAoB,IAAEA,EAAMC,QAAQD,MAAhBE,OAA4BA,KAAWzB,0IAEvC,MAAM0B,EAAiBtB,UAASD,EAAQoB,IAAjBnB,CAAsBJ,GACvC2B,EAAkBvB,UAASD,EAAQyB,KAAjBxB,CAAuBJ,GACzC6B,EAAsBzB,UAASD,EAAQ2B,SAAjB1B,CAA2BJ,GACjD+B,EAAmB3B,UAASD,EAAQZ,MAAjBa,CAAwBJ,GAE3CgC,EAAmBN,EACrBO,UAAKC,QAAQX,EAAKG,GAClBH,EACEY,EAAaF,UAAKC,QAAQF,EAAkBL,GAElDF,EAAOW,yBACgBD,iBAA0BN,cAAgCE,KAGjF,MAAMM,EAAcC,UAAGC,aAAaJ,EAAY,QAC1CK,EAAmBC,UAAOC,KAAKL,GAC/BM,EAAkBF,UAAOC,KAAKL,GAEpC,GAA+B,iBAApBM,GAAoD,OAApBA,EACzC,UAAUC,kBAAkBT,+BAG9BU,UAAIF,EAAiBd,EAAqBE,GAC1C,MAAMe,EAAaC,gBACjBV,EACAG,EACAG,GAGFL,UAAGU,cAAcb,EAAYW,ID1BzBG,CAAK9C,EAASH,KAET"}
|
package/dist/src/yaml.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Command } from "./definitions/configuration.interface";
|
|
2
2
|
import { SemanticContext } from "./definitions/semantic-context.interface";
|
|
3
|
-
export declare const yaml: (command: Command, { cwd, env,
|
|
3
|
+
export declare const yaml: (command: Command, { cwd, env, logger, ...context }: SemanticContext) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-release-yaml",
|
|
3
3
|
"description": "semantic-release plugin to edit yaml files",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"author": "Mees van Dongen",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/meesvandongen/semantic-release-yaml/issues"
|
|
@@ -11,15 +11,21 @@
|
|
|
11
11
|
"aggregate-error": "^3.0.0",
|
|
12
12
|
"debug": "^4.0.0",
|
|
13
13
|
"js-yaml": "^4.1.0",
|
|
14
|
-
"lodash": "^4.17.4"
|
|
14
|
+
"lodash": "^4.17.4",
|
|
15
|
+
"yaml-diff-patch": "^1.1.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@semantic-release/git": "^10.0.1",
|
|
19
|
+
"@swc/core": "^1.2.125",
|
|
20
|
+
"@swc/jest": "^0.2.15",
|
|
21
|
+
"@types/jest": "^27.4.0",
|
|
18
22
|
"@types/js-yaml": "^4.0.5",
|
|
19
23
|
"@types/lodash": "^4.14.178",
|
|
20
24
|
"@types/semantic-release": "^17.2.3",
|
|
25
|
+
"jest": "^27.4.5",
|
|
21
26
|
"microbundle": "^0.14.2",
|
|
22
|
-
"semantic-release": "18.0.1"
|
|
27
|
+
"semantic-release": "18.0.1",
|
|
28
|
+
"type-fest": "^2.8.0"
|
|
23
29
|
},
|
|
24
30
|
"files": [
|
|
25
31
|
"dist/**/*"
|
|
@@ -50,6 +56,8 @@
|
|
|
50
56
|
"scripts": {
|
|
51
57
|
"semantic-release": "semantic-release",
|
|
52
58
|
"build": "microbundle --target=node --format cjs --compress",
|
|
53
|
-
"build:watch": "microbundle watch --target=node --format cjs --compress"
|
|
59
|
+
"build:watch": "microbundle watch --target=node --format cjs --compress",
|
|
60
|
+
"test": "jest",
|
|
61
|
+
"test:watch": "jest --watch"
|
|
54
62
|
}
|
|
55
63
|
}
|