@ethima/semantic-release-configuration 2.0.0 → 2.1.1

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 CHANGED
@@ -36,6 +36,30 @@ configuration supporting a range of languages and platforms supported by the
36
36
  [`extends`][semantic-release-extends-configuration-url] configuration for the
37
37
  project to be semantically released.
38
38
 
39
+ ### Configuration
40
+
41
+ The semantic release configuration has several configuration options itself.
42
+ Some of this configuration, like sensitive tokens such as `GITLAB_TOKEN` and
43
+ `NPM_TOKEN`, should be configured through environment variables.
44
+
45
+ Other configuration options have more complex values and are not suitable for
46
+ configuration through environment variables. These configuration options can be
47
+ configured through a file. The [`cosmiconfig` library][cosmiconfig-url] is used
48
+ for this purpose. This library will search for an `ethima` configuration file
49
+ as explained in the introduction of its `README`, e.g. a JSON or YAML-formatted
50
+ `.ethimarc` or `.config/ethimarc` file, JavaScript in a `.ethimarc.js`, etc.
51
+
52
+ All configuration options are explained in more detail in the sections
53
+ describing the functionality they apply to.
54
+
55
+ ### Changelog Maintenance
56
+
57
+ A changelog is maintained using the release notes generated by the semantic
58
+ release tooling. This changelog is maintained in a `CHANGELOG.md` in the root
59
+ of a project by default. This path can be configured by adding a
60
+ `changelog_filename` property to a file-based configuration as described in
61
+ [the configuration section](#configuration).
62
+
39
63
  ### JavaScript Packages
40
64
 
41
65
  JavaScript packages are detected based on the presence of a `package.json` file
@@ -66,7 +90,7 @@ structure:
66
90
 
67
91
  ` token,
68
92
  - the template itself with one or more
69
- `2.0.0` tokens,
93
+ `2.1.1` tokens,
70
94
  - a comment closing tag `
71
95
 
72
96
  <!-- END_VERSIONED_TEMPLATE -->`.
@@ -80,7 +104,7 @@ The next semantically released version will be v__NEXT_SEMANTIC_RELEASE_VERSION_
80
104
 
81
105
  -->
82
106
 
83
- The next semantically released version will be v2.0.0!
107
+ The next semantically released version will be v2.1.1!
84
108
 
85
109
  <!-- END_VERSIONED_TEMPLATE -->
86
110
  ```
@@ -95,7 +119,7 @@ The next semantically released version will be v__NEXT_SEMANTIC_RELEASE_VERSION_
95
119
 
96
120
  -->
97
121
 
98
- The next semantically released version will be v2.0.0!
122
+ The next semantically released version will be v2.1.1!
99
123
 
100
124
  <!-- END_VERSIONED_TEMPLATE -->
101
125
  ```
@@ -103,6 +127,44 @@ The next semantically released version will be v2.0.0!
103
127
  Note that the `v` is in the template! The version as derived by the semantic
104
128
  release tooling does not contain that prefix.
105
129
 
130
+ #### Configuring which files to update
131
+
132
+ The templated content feature uses [the `replace-in-file`
133
+ library][replace-in-file-url] to perform the actual replacements. In which
134
+ files templates should be replaced, can be configured by adding a
135
+ `files_with_versioned_templates` key specifying an array of filenames and globs
136
+ to a configuration file as described in the [configuration
137
+ section](#configuration). For instance:
138
+
139
+ ```json
140
+ {
141
+ "files_with_versioned_templates": [
142
+ "README.md",
143
+ "some/other/file.md",
144
+ "a/glob/for/multiple/markdown/files/*.md",
145
+ "src/**/*.js"
146
+ ]
147
+ }
148
+ ```
149
+
150
+ #### Preventing individual templates from being updated
151
+
152
+ Configuring which files to ignore when updating templated content is a very
153
+ coarse approach which may not always be suitable. In cases where a more
154
+ fine-grained approach is necessary, replacements in individual templates can be
155
+ prevented by modifying (one of) the tokens in those templates. For instance by
156
+ including a non-visible whitespace character, e.g. [a _Zero Width Non-Joiner
157
+ (ZWNJ)_ character](https://unicode-table.com/en/200C/). A sufficient approach
158
+ is to modify the starting token, so that the template is no longer recognized
159
+ as one. Using the suggested ZWNJ character the starting token becomes
160
+ `<!--‌ START_VERSIONED_TEMPLATE`.
161
+
162
+ Note that when using this approach, although the templates/tokens _visually_
163
+ look like versions that should be replaced, they cannot be copied and pasted as
164
+ examples as the resulting copies will also contain the non-visible whitespace
165
+ character. When using this approach be sure to indicate this as to not confuse
166
+ readers as to why replacements may not be working!
167
+
106
168
  ## Troubleshooting
107
169
 
108
170
  ### Publishing the initial release of a scoped JavaScript package
@@ -123,8 +185,10 @@ When this happens, it is typically also necessary to create the initial GitHub
123
185
  release by hand from the tag and changelog that was created by the
124
186
  [`semantic-release`][semantic-release-url] tooling.
125
187
 
188
+ [cosmiconfig-url]: https://www.npmjs.com/package/cosmiconfig
126
189
  [gitlab-pat-url]: https://gitlab.com/-/profile/personal_access_tokens
127
190
  [npm-token-url]: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website
191
+ [replace-in-file-url]: https://www.npmjs.com/package/replace-in-file
128
192
  [semantic-release-changelog-plugin-url]: https://github.com/semantic-release/changelog
129
193
  [semantic-release-commit-analyzer-plugin-url]: https://github.com/semantic-release/commit-analyzer
130
194
  [semantic-release-extends-configuration-url]: https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethima/semantic-release-configuration",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "A shareable semantic release configuration supporting a range of languages and platforms supported by the Ethima organization.",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -21,6 +21,7 @@
21
21
  "@google/semantic-release-replace-plugin": "1.2.0",
22
22
  "@semantic-release/changelog": "6.0.2",
23
23
  "@semantic-release/git": "10.0.1",
24
- "@semantic-release/gitlab": "9.5.1"
24
+ "@semantic-release/gitlab": "9.5.1",
25
+ "cosmiconfig": "8.0.0"
25
26
  }
26
27
  }
@@ -0,0 +1,16 @@
1
+ const { cosmiconfigSync } = require("cosmiconfig");
2
+
3
+ const CONFIGURATION_DEFAULTS = {
4
+ changelog_filename: "CHANGELOG.md",
5
+ files_with_versioned_templates: ["README.md"],
6
+ };
7
+
8
+ const ethimaConfig = cosmiconfigSync("ethima").search();
9
+
10
+ // The configuration only supports merging elements at the root object. This is
11
+ // sufficient for the current configuration needs, which tend to be simple
12
+ // values and doing a deep merge would add currently unnecessary complexity.
13
+ // This can be revisited once the need arises
14
+ const CONFIGURATION = { ...CONFIGURATION_DEFAULTS, ...ethimaConfig?.config };
15
+
16
+ module.exports = CONFIGURATION;
package/src/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  const { accessSync } = require("node:fs");
2
2
  const { env } = require("node:process");
3
3
 
4
+ const CONFIGURATION = require("./configuration.js");
4
5
  const VersionedTemplatesConfiguration = require("./versioned-templates.js");
5
6
 
6
- const CHANGELOG_FILENAME = "CHANGELOG.md";
7
- const README_FILENAME = "README.md";
8
-
9
- const GIT_ASSETS = [CHANGELOG_FILENAME, README_FILENAME];
7
+ const GIT_ASSETS = [
8
+ CONFIGURATION.changelog_filename,
9
+ ...CONFIGURATION.files_with_versioned_templates,
10
+ ];
10
11
 
11
12
  // Ensure the NPM plugin gets added to the semantic release pipeline if a
12
13
  // `package.json` file is detected
@@ -24,9 +25,14 @@ const SEMANTIC_RELEASE_CONFIGURATION = {
24
25
  "@semantic-release/release-notes-generator",
25
26
  [
26
27
  "@semantic-release/changelog",
27
- { changelogFile: CHANGELOG_FILENAME, changelogTitle: "# Changelog" },
28
+ {
29
+ changelogFile: CONFIGURATION.changelog_filename,
30
+ changelogTitle: "# Changelog",
31
+ },
28
32
  ],
29
- VersionedTemplatesConfiguration(README_FILENAME),
33
+ VersionedTemplatesConfiguration(
34
+ CONFIGURATION.files_with_versioned_templates
35
+ ),
30
36
  ...NPM_PLUGIN,
31
37
  [
32
38
  "@semantic-release/git",