relion 0.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1 -0
  4. package/bin/cli.js +9 -0
  5. package/package.json +74 -0
  6. package/src/commands.js +190 -0
  7. package/src/defaults.js +68 -0
  8. package/src/index.js +152 -0
  9. package/src/lib/checkpoint.js +23 -0
  10. package/src/lib/configuration.js +35 -0
  11. package/src/lib/detect-package-manager.js +49 -0
  12. package/src/lib/format-commit-message.js +4 -0
  13. package/src/lib/latest-semver-tag.js +34 -0
  14. package/src/lib/lifecycles/bump.js +234 -0
  15. package/src/lib/lifecycles/changelog.js +105 -0
  16. package/src/lib/lifecycles/commit.js +67 -0
  17. package/src/lib/lifecycles/tag.js +59 -0
  18. package/src/lib/print-error.js +15 -0
  19. package/src/lib/run-exec.js +19 -0
  20. package/src/lib/run-execFile.js +19 -0
  21. package/src/lib/run-lifecycle-script.js +18 -0
  22. package/src/lib/stringify-package.js +34 -0
  23. package/src/lib/updaters/index.js +127 -0
  24. package/src/lib/updaters/types/csproj.js +13 -0
  25. package/src/lib/updaters/types/gradle.js +16 -0
  26. package/src/lib/updaters/types/json.js +25 -0
  27. package/src/lib/updaters/types/maven.js +43 -0
  28. package/src/lib/updaters/types/openapi.js +15 -0
  29. package/src/lib/updaters/types/plain-text.js +7 -0
  30. package/src/lib/updaters/types/python.js +30 -0
  31. package/src/lib/updaters/types/yaml.js +15 -0
  32. package/src/lib/write-file.js +6 -0
  33. package/src/preset/constants.js +16 -0
  34. package/src/preset/index.js +19 -0
  35. package/src/preset/parser.js +11 -0
  36. package/src/preset/templates/commit.hbs +19 -0
  37. package/src/preset/templates/footer.hbs +10 -0
  38. package/src/preset/templates/header.hbs +10 -0
  39. package/src/preset/templates/index.js +13 -0
  40. package/src/preset/templates/main.hbs +21 -0
  41. package/src/preset/whatBump.js +32 -0
  42. package/src/preset/writer.js +201 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,47 @@
1
+ # Changelog
2
+
3
+
4
+ ## [v0.1.1](https://github.com/Kh4f/relion/commits/v0.1.1) (2025-06-20)
5
+
6
+ > [!NOTE]
7
+ > This release is version `0.1.1` instead of `0.1.0` due to an npm restriction: [previously unpublished versions can never be republished](https://docs.npmjs.com/cli/v11/commands/npm-unpublish).
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+ * The project and related references have been renamed to 'relion'.
11
+ * `config` Changed alias for 'prerelease' option to 'P' to reserve 'p' for the new '--profile' option.
12
+ * `config` The 'skip' object has been removed from the config. Now, 'bump', 'changelog', 'commit', and 'tag' are explicit boolean flags. By default, they are false and must be set to true in the user config to enable the corresponding steps.
13
+ * `config` The 'firstRelease' property has been removed.
14
+ * `config` The config structure has changed. All preset options must now be placed under a 'preset' key in the config file (or cli args). This will be smart-merged with the default preset.
15
+
16
+ ### ✨ Features
17
+ * `changelog` repeat last release changelog when no new commits ([bdcb9bc](https://github.com/Kh4f/relion/commit/bdcb9bca3ba38ef8a9a1332d82685b1c7a71508b))
18
+ * `config` add support for `_<profileName>` profiles with CLI `--profile` flag ([a940100](https://github.com/Kh4f/relion/commit/a940100796af3fdcc224f1987775d6a4c04d62dd))
19
+ * `config` add `.mjs` and `.ts` config support ([0efe117](https://github.com/Kh4f/relion/commit/0efe11740433e9a000878a4f0e0822a94a0ac6a2))
20
+ * `cli` add context.fullChangelogLink flag ([949f09e](https://github.com/Kh4f/relion/commit/949f09ee9ddb3ce38a6568b4509a1c08c264f6da))
21
+ * `templates` add full changelog link to footer ([e1ed82b](https://github.com/Kh4f/relion/commit/e1ed82b74c988b1785cd93336918b5f005cd1c38))
22
+ * `templates` add link to current tag commits in header if it is the only tag ([f8a8d73](https://github.com/Kh4f/relion/commit/f8a8d73ef57b5b55ec184c172384ae0f36ac18a8))
23
+ * `cli` add 'context.linkReferences' option ([bc048b4](https://github.com/Kh4f/relion/commit/bc048b4dd1446ee78f3ef670589a9ca5fb41ad3b))
24
+ * `preset` re-export handlebars templates as strings ([1dc5952](https://github.com/Kh4f/relion/commit/1dc5952f42b08e0a86d71b162d427df51d4855c5))
25
+ * `config` add 'all' option to run all lifecycle events ([d2a6fd3](https://github.com/Kh4f/relion/commit/d2a6fd3befd0dd13ab128e220a4a65236b2afe1d))
26
+ * `config` allow defining custom context ([93d6f91](https://github.com/Kh4f/relion/commit/93d6f91caa490d418b20498da9ccc32ccda8ae46))
27
+ * `config` add `writerOpts.commitsSort` to defaults ([dec6006](https://github.com/Kh4f/relion/commit/dec60066dc8690d97dac51707c03c0c0fbc75e4b))
28
+ * `config` replace skip object with explicit bump, changelog, commit, and tag flags ([6f9f4e0](https://github.com/Kh4f/relion/commit/6f9f4e0af3fed9f1687ac1234af2a466c4db579d))
29
+ * `config` require config preset options to be nested under 'preset' key ([01fc1f1](https://github.com/Kh4f/relion/commit/01fc1f16b71b40557877ad67442279892a9a4a60))
30
+ * `changelog` support version prefixes in release headers ([00e5410](https://github.com/Kh4f/relion/commit/00e54105d686d90629c1a95a000c78896065b9e9))
31
+
32
+ ### 🩹 Bug Fixes
33
+ * `changelog` prevent empty changelog generation when last commit has a version tag ([080c007](https://github.com/Kh4f/relion/commit/080c007b88882bfbc7d0e9deb215252714de6475))
34
+ * `writer` correct `previousTag` detection for `releaseCount` > 1 ([464cdfa](https://github.com/Kh4f/relion/commit/464cdfa90bef7af3154e6e3cb1a6d80268c2d375))
35
+ * `cli` use `defaults.preset` for default preset options ([c824820](https://github.com/Kh4f/relion/commit/c824820fa355fc5ad4ff3666a8fa354d35ca35f4))
36
+ * `config` avoid setting `preMajor` to false by default ([a22bd20](https://github.com/Kh4f/relion/commit/a22bd202731c8f4a8c9eb2cea622ed5ac1b9b720))
37
+ * `config` resolve script import path with pathToFileURL ([3f6f930](https://github.com/Kh4f/relion/commit/3f6f93041403573d736eebd3ae55a4b1a922843a))
38
+ * `package` update release script to use node for execution ([bd194d4](https://github.com/Kh4f/relion/commit/bd194d4e66884ca414659e6430cdda30427d6c1d))
39
+ * `core` move `args.all` handling after `args` initialization ([e97b046](https://github.com/Kh4f/relion/commit/e97b04612019a49f9a3aca4653ae88999b3df2e6))
40
+ * `cli` change aliases for commit-all and tag-prefix to avoid conflicts ([8adfdf7](https://github.com/Kh4f/relion/commit/8adfdf7cfe8e6545da1e6fe23298b0669102f142))
41
+ * `commit` add tag prefix to version in release commit message ([0b955a4](https://github.com/Kh4f/relion/commit/0b955a4f3f6377b3092d086bd44a77c3e27816f5))
42
+ * `bump` always resolve new version even if skip.bump is set ([6b560c9](https://github.com/Kh4f/relion/commit/6b560c967e8f8522ecfda1529dde26d0f80ebfe7))
43
+ * `bump` add `await` before calling `resolveUpdaterObjectFromArgument` ([a7026fa](https://github.com/Kh4f/relion/commit/a7026fa6513bf2505415e2c69215173cec194bd1))
44
+
45
+ ### 🧹 Adjustments
46
+ * rename project to 'relion' ([faaa473](https://github.com/Kh4f/relion/commit/faaa473670c52e05821bdcc372f1a434eba1fb38))
47
+ * `config` remove unnecessary? `firstRelease` property ([67266a8](https://github.com/Kh4f/relion/commit/67266a84668e34a1b22ddd361c702010b6619aac))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kh4f
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # relion
package/bin/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ import relion from '../src/index.js';
4
+ import cmdParser from '../src/commands.js';
5
+
6
+ relion(cmdParser.argv).catch((err) => {
7
+ console.error(err);
8
+ process.exit(1);
9
+ });
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "relion",
3
+ "version": "0.1.1",
4
+ "description": "Release workflow helper for Node.js projects.",
5
+ "author": "Kh4f",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Kh4f/relion.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/Kh4f/relion/issues"
13
+ },
14
+ "homepage": "https://github.com/Kh4f/relion#readme",
15
+ "keywords": [
16
+ "relion",
17
+ "release",
18
+ "release-workflow",
19
+ "release-helper",
20
+ "semantic-release",
21
+ "conventional-changelog",
22
+ "standard-version",
23
+ "commit-and-tag-version"
24
+ ],
25
+ "main": "./src/index.js",
26
+ "type": "module",
27
+ "bin": "bin/cli.js",
28
+ "files": [
29
+ "bin",
30
+ "src",
31
+ "package.json",
32
+ "LICENSE",
33
+ "README.md",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "scripts": {
37
+ "lint": "eslint .",
38
+ "lint:fix": "npm run lint -- --fix",
39
+ "format:base": "prettier \"./**/*.{ts,js}\"",
40
+ "format:fix": "npm run format:base -- --write",
41
+ "format:check": "npm run format:base -- --check",
42
+ "release": "node bin/cli.js --changelog --bump --commit --tag",
43
+ "release:gh-notes": "node bin/cli.js --profile gh-release-notes --changelog"
44
+ },
45
+ "dependencies": {
46
+ "chalk": "^5.4.1",
47
+ "conventional-changelog": "^6.0.0",
48
+ "conventional-changelog-config-spec": "^2.1.0",
49
+ "conventional-changelog-conventionalcommits": "^8.0.0",
50
+ "conventional-recommended-bump": "^11.0.0",
51
+ "detect-indent": "^7.0.1",
52
+ "detect-newline": "^4.0.1",
53
+ "dotgitignore": "^2.1.0",
54
+ "figures": "^6.1.0",
55
+ "find-up": "^7.0.0",
56
+ "git-semver-tags": "^8.0.0",
57
+ "jsdom": "^26.1.0",
58
+ "mergician": "^2.0.2",
59
+ "semver": "^7.7.2",
60
+ "w3c-xmlserializer": "^5.0.0",
61
+ "yaml": "^2.8.0",
62
+ "yargs": "^17.7.2"
63
+ },
64
+ "devDependencies": {
65
+ "@eslint/js": "^9.27.0",
66
+ "eslint": "^9.27.0",
67
+ "eslint-config-prettier": "^10.1.5",
68
+ "eslint-plugin-import": "^2.31.0",
69
+ "eslint-plugin-jest": "^28.11.0",
70
+ "eslint-plugin-n": "^17.18.0",
71
+ "eslint-plugin-promise": "^7.2.1",
72
+ "prettier": "^3.5.3"
73
+ }
74
+ }
@@ -0,0 +1,190 @@
1
+ import spec from 'conventional-changelog-config-spec';
2
+ import { getConfiguration } from './lib/configuration.js';
3
+ import defaults from './defaults.js';
4
+ import yargs from 'yargs/yargs';
5
+ import { hideBin } from 'yargs/helpers';
6
+
7
+ const yargsInstance = yargs(hideBin(process.argv))
8
+ .usage('Usage: $0 [options]')
9
+ .option('packageFiles', {
10
+ default: defaults.packageFiles,
11
+ array: true,
12
+ })
13
+ .option('bumpFiles', {
14
+ default: defaults.bumpFiles,
15
+ array: true,
16
+ })
17
+ .option('release-as', {
18
+ alias: 'r',
19
+ describe: 'Specify the release type manually (like npm version <major|minor|patch>)',
20
+ requiresArg: true,
21
+ string: true,
22
+ })
23
+ .option('prerelease', {
24
+ alias: 'P',
25
+ describe: 'make a pre-release with optional option value to specify a tag id',
26
+ string: true,
27
+ })
28
+ .option('infile', {
29
+ alias: 'i',
30
+ describe: 'Read the CHANGELOG from this file',
31
+ default: defaults.infile,
32
+ })
33
+ .option('message', {
34
+ alias: ['m'],
35
+ describe:
36
+ '[DEPRECATED] Commit message, replaces %s with new version.\nThis option will be removed in the next major version, please use --releaseCommitMessageFormat.',
37
+ type: 'string',
38
+ })
39
+ .option('sign', {
40
+ alias: 's',
41
+ describe: 'Should the git commit and tag be signed?',
42
+ type: 'boolean',
43
+ default: defaults.sign,
44
+ })
45
+ .option('signoff', {
46
+ describe: 'Should the git commit have a "Signed-off-by" trailer',
47
+ type: 'boolean',
48
+ default: defaults.signoff,
49
+ })
50
+ .option('no-verify', {
51
+ alias: 'n',
52
+ describe: 'Bypass pre-commit or commit-msg git hooks during the commit phase',
53
+ type: 'boolean',
54
+ default: defaults.noVerify,
55
+ })
56
+ .option('commit-all', {
57
+ alias: 'C',
58
+ describe: 'Commit all staged changes, not just files affected by relion',
59
+ type: 'boolean',
60
+ default: defaults.commitAll,
61
+ })
62
+ .option('silent', {
63
+ describe: "Don't print logs and errors",
64
+ type: 'boolean',
65
+ default: defaults.silent,
66
+ })
67
+ .option('tag-prefix', {
68
+ alias: 'T',
69
+ describe: 'Set a custom prefix for the git tag to be created',
70
+ type: 'string',
71
+ default: defaults.tagPrefix,
72
+ })
73
+ .option('release-count', {
74
+ describe:
75
+ 'How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all.',
76
+ type: 'number',
77
+ default: defaults.releaseCount,
78
+ })
79
+ .option('tag-force', {
80
+ describe: 'Allow tag replacement',
81
+ type: 'boolean',
82
+ default: defaults.tagForce,
83
+ })
84
+ .option('scripts', {
85
+ describe: 'Provide scripts to execute for lifecycle events (prebump, precommit, etc.,)',
86
+ default: defaults.scripts,
87
+ })
88
+ .option('bump', {
89
+ alias: 'b',
90
+ describe: 'Bump the version in bumpFiles',
91
+ type: 'boolean',
92
+ default: defaults.bump,
93
+ })
94
+ .option('changelog', {
95
+ alias: 'l',
96
+ describe: 'Generate a changelog',
97
+ type: 'boolean',
98
+ default: defaults.changelog,
99
+ })
100
+ .option('commit', {
101
+ alias: 'c',
102
+ describe: 'Create a git commit',
103
+ type: 'boolean',
104
+ default: defaults.commit,
105
+ })
106
+ .option('tag', {
107
+ alias: 't',
108
+ describe: 'Create a git tag',
109
+ type: 'boolean',
110
+ default: defaults.tag,
111
+ })
112
+ .option('all', {
113
+ alias: 'a',
114
+ describe: 'Run all lifecycle events',
115
+ type: 'boolean',
116
+ default: defaults.all,
117
+ })
118
+ .option('context.linkReferences', {
119
+ describe: 'Should all references be linked?',
120
+ type: 'boolean',
121
+ default: defaults.context.linkReferences,
122
+ })
123
+ .option('context.fullChangelogLink', {
124
+ describe: 'Add a "Full Changelog: v1...v2" link to the footer',
125
+ type: 'boolean',
126
+ default: defaults.context.fullChangelogLink,
127
+ })
128
+ .option('profile', {
129
+ alias: 'p',
130
+ describe: 'Specify a named config profile to merge with the base config (properties under _<profile-name> in .versionrc)',
131
+ type: 'string',
132
+ })
133
+ .option('dry-run', {
134
+ type: 'boolean',
135
+ default: defaults.dryRun,
136
+ describe: 'See the commands that running relion would run',
137
+ })
138
+ .option('git-tag-fallback', {
139
+ type: 'boolean',
140
+ default: defaults.gitTagFallback,
141
+ describe:
142
+ 'fallback to git tags for version, if no meta-information file is found (e.g., package.json)',
143
+ })
144
+ .option('path', {
145
+ type: 'string',
146
+ describe: 'Only populate commits made under this path',
147
+ })
148
+ .option('changelogHeader', {
149
+ type: 'string',
150
+ describe:
151
+ '[DEPRECATED] Use a custom header when generating and updating changelog.\nThis option will be removed in the next major version, please use --header.',
152
+ })
153
+ .option('lerna-package', {
154
+ type: 'string',
155
+ describe: 'Name of the package from which the tags will be extracted',
156
+ })
157
+ .option('npmPublishHint', {
158
+ type: 'string',
159
+ default: defaults.npmPublishHint,
160
+ describe: 'Customized publishing hint',
161
+ })
162
+ .check((argv) => {
163
+ if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
164
+ throw Error('scripts must be an object');
165
+ } else {
166
+ return true;
167
+ }
168
+ })
169
+ .alias('version', 'v')
170
+ .alias('help', 'h')
171
+ .example('$0', 'Update changelog and tag release')
172
+ .example(
173
+ '$0 -m "%s: see changelog for details"',
174
+ 'Update changelog and tag release with custom commit message',
175
+ )
176
+ .pkgConf('relion')
177
+ .config(await getConfiguration())
178
+ .wrap(97);
179
+
180
+ Object.keys(spec.properties).forEach((propertyKey) => {
181
+ const property = spec.properties[propertyKey];
182
+ if (!defaults.preset[propertyKey]) return;
183
+ yargsInstance.option('preset.' + propertyKey, {
184
+ type: property.type,
185
+ describe: property.description,
186
+ default: defaults.preset[propertyKey],
187
+ });
188
+ });
189
+
190
+ export default yargsInstance;
@@ -0,0 +1,68 @@
1
+ const defaultPresetURL = import.meta.resolve('./preset/index.js');
2
+
3
+ const defaults = {
4
+ bump: false,
5
+ changelog: false,
6
+ commit: false,
7
+ tag: false,
8
+ all: false,
9
+
10
+ infile: 'CHANGELOG.md',
11
+ sign: false,
12
+ signoff: false,
13
+ noVerify: false,
14
+ commitAll: false,
15
+ silent: false,
16
+ tagPrefix: 'v',
17
+ releaseCount: 1,
18
+ scripts: {},
19
+ dryRun: false,
20
+ tagForce: false,
21
+ gitTagFallback: true,
22
+ npmPublishHint: undefined,
23
+ packageFiles: ['package.json', 'bower.json', 'manifest.json'],
24
+
25
+ context: {
26
+ linkReferences: true,
27
+ fullChangelogLink: false,
28
+ },
29
+
30
+ preset: {
31
+ name: defaultPresetURL,
32
+ // defaults provided by the spec
33
+ // https://github.com/conventional-changelog/conventional-changelog-config-spec/tree/master/versions/2.2.0
34
+ header: '# Changelog\n\n\n',
35
+ types: [
36
+ { type: 'feat', section: 'Features' },
37
+ { type: 'fix', section: 'Bug Fixes' },
38
+ { type: 'chore', hidden: true },
39
+ { type: 'docs', hidden: true },
40
+ { type: 'style', hidden: true },
41
+ { type: 'refactor', hidden: true },
42
+ { type: 'perf', hidden: true },
43
+ { type: 'test', hidden: true },
44
+ ],
45
+ /* preMajor value is defined in spec, but should not be in defaults
46
+ since it's set to true automatically if version < 1.0.0,
47
+ or matches the user config if provided.
48
+ */
49
+ // preMajor: false,
50
+ commitUrlFormat: '{{host}}/{{owner}}/{{repository}}/commit/{{hash}}',
51
+ compareUrlFormat: '{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}',
52
+ issueUrlFormat: '{{host}}/{{owner}}/{{repository}}/issues/{{id}}',
53
+ userUrlFormat: '{{host}}/{{user}}',
54
+ releaseCommitMessageFormat: 'chore(release): {{currentTag}}',
55
+ issuePrefixes: ['#'],
56
+ },
57
+
58
+ writerOpts: {
59
+ commitsSort: false,
60
+ },
61
+ };
62
+
63
+ defaults.bumpFiles = defaults.packageFiles.concat([
64
+ 'package-lock.json',
65
+ 'npm-shrinkwrap.json',
66
+ ]);
67
+
68
+ export default defaults;
package/src/index.js ADDED
@@ -0,0 +1,152 @@
1
+ import bump, { getNewVersion } from './lib/lifecycles/bump.js';
2
+ import changelog from './lib/lifecycles/changelog.js';
3
+ import commit from './lib/lifecycles/commit.js';
4
+ import fs from 'fs';
5
+ import latestSemverTag from './lib/latest-semver-tag.js';
6
+ import path from 'path';
7
+ import printError from './lib/print-error.js';
8
+ import tag from './lib/lifecycles/tag.js';
9
+ import { resolveUpdaterObjectFromArgument } from './lib/updaters/index.js';
10
+ import defaults from './defaults.js';
11
+ import { mergician } from 'mergician';
12
+ import { execSync } from 'child_process';
13
+
14
+ export default async function relion(argv) {
15
+ /**
16
+ * `--message` (`-m`) support will be removed in the next major version.
17
+ */
18
+ const message = argv.m || argv.message;
19
+ if (message) {
20
+ /**
21
+ * The `--message` flag uses `%s` for version substitutions, we swap this
22
+ * for the substitution defined in the config-spec for future-proofing upstream
23
+ * handling.
24
+ */
25
+ argv.preset.releaseCommitMessageFormat = message.replace(/%s/g, '{{currentTag}}');
26
+ if (!argv.silent) {
27
+ console.warn(
28
+ '[relion]: --message (-m) will be removed in the next major release. Use --releaseCommitMessageFormat.',
29
+ );
30
+ }
31
+ }
32
+
33
+ if (argv.changelogHeader) {
34
+ argv.preset.header = argv.changelogHeader;
35
+ if (!argv.silent) {
36
+ console.warn(
37
+ '[relion]: --changelogHeader will be removed in the next major release. Use --header.',
38
+ );
39
+ }
40
+ }
41
+
42
+ if (argv.preset.header && argv.preset.header.search(changelog.START_OF_LAST_RELEASE_PATTERN) !== -1) {
43
+ throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`);
44
+ }
45
+
46
+ /**
47
+ * If an argument for `packageFiles` provided, we include it as a "default" `bumpFile`.
48
+ */
49
+ if (argv.packageFiles) {
50
+ defaults.bumpFiles = defaults.bumpFiles.concat(argv.packageFiles);
51
+ }
52
+
53
+ let args = mergician(defaults, argv);
54
+ if (args.profile) {
55
+ args = mergeProfileConfig(args);
56
+ }
57
+
58
+ let pkg;
59
+ for (const packageFile of args.packageFiles) {
60
+ const updater = await resolveUpdaterObjectFromArgument(packageFile);
61
+ if (!updater) return;
62
+ const pkgPath = path.resolve(process.cwd(), updater.filename);
63
+ try {
64
+ const contents = fs.readFileSync(pkgPath, 'utf8');
65
+ pkg = {
66
+ version: updater.updater.readVersion(contents),
67
+ private:
68
+ typeof updater.updater.isPrivate === 'function'
69
+ ? updater.updater.isPrivate(contents)
70
+ : false,
71
+ };
72
+ break;
73
+ // eslint-disable-next-line no-unused-vars
74
+ } catch (err) {
75
+ /* This probably shouldn't be empty? */
76
+ }
77
+ }
78
+ try {
79
+ let version;
80
+ if (pkg && pkg.version) {
81
+ version = pkg.version;
82
+ } else if (args.gitTagFallback) {
83
+ version = await latestSemverTag(args);
84
+ } else {
85
+ throw new Error('no package file found');
86
+ }
87
+
88
+ if (args.all) {
89
+ args.bump = true;
90
+ args.changelog = true;
91
+ args.commit = true;
92
+ args.tag = true;
93
+ }
94
+
95
+ const newVersion = await getNewVersion(args, version);
96
+ args.context.version = newVersion;
97
+ args.context.newTag = args.tagPrefix + newVersion;
98
+
99
+ if (lastCommitHasTag()) {
100
+ // use the current version as the new version if there's no new commits
101
+ // to avoid empty new release changelog generation
102
+ args.context.version = version;
103
+
104
+ if (args.releaseCount === 1) {
105
+ // genearate the last release changelog
106
+ args.releaseCount = 2;
107
+ }
108
+ }
109
+
110
+ args.bump && (await bump(args, newVersion));
111
+ args.changelog && (await changelog(args, newVersion));
112
+ args.commit && (await commit(args, newVersion));
113
+ args.tag && (await tag(newVersion, pkg ? pkg.private : false, args));
114
+ } catch (err) {
115
+ printError(args, err.message);
116
+ throw err;
117
+ }
118
+ }
119
+
120
+ function lastCommitHasTag() {
121
+ const lastCommit = execSync('git rev-parse HEAD').toString().trim();
122
+ const tags = execSync(`git tag --points-at ${lastCommit}`).toString().trim();
123
+ return !!tags;
124
+ }
125
+
126
+ /**
127
+ * Merge profile config if args.profile is specified.
128
+ * Merges args._<profile> into args, then deletes args._<profile>.
129
+ */
130
+ function mergeProfileConfig(args) {
131
+ function uniqBy(arr, keyFn) {
132
+ const seen = new Set();
133
+ return arr.filter(item => {
134
+ const key = keyFn(item);
135
+ if (seen.has(key)) return false;
136
+ seen.add(key);
137
+ return true;
138
+ });
139
+ }
140
+
141
+ const profileKey = `_${args.profile}`;
142
+ const merged = mergician({
143
+ prependArrays: true,
144
+ dedupArrays: true
145
+ })(args, structuredClone(args[profileKey]));
146
+
147
+ const dedupedTypes = uniqBy(merged.preset.types, item => item.type);
148
+ merged.preset.types = dedupedTypes;
149
+
150
+ delete merged[profileKey];
151
+ return merged;
152
+ }
@@ -0,0 +1,23 @@
1
+ import chalk from 'chalk';
2
+ import figures from 'figures';
3
+ import util from 'util';
4
+
5
+ export default function (argv, msg, args, figure) {
6
+ const defaultFigure = argv.dryRun
7
+ ? chalk.yellow(figures.tick)
8
+ : chalk.green(figures.tick);
9
+ if (!argv.silent) {
10
+ console.info(
11
+ (figure || defaultFigure) +
12
+ ' ' +
13
+ util.format.apply(
14
+ util,
15
+ [msg].concat(
16
+ args.map(function (arg) {
17
+ return chalk.bold(arg);
18
+ }),
19
+ ),
20
+ ),
21
+ );
22
+ }
23
+ }
@@ -0,0 +1,35 @@
1
+ import path from 'path';
2
+ import { findUpSync } from 'find-up';
3
+ import { readFileSync } from 'fs';
4
+ import { pathToFileURL } from 'url';
5
+
6
+
7
+ const CONFIGURATION_FILES = [
8
+ '', '.json', '.js', '.cjs', '.mjs', '.ts']
9
+ .map(ext => `.versionrc${ext}`);
10
+
11
+
12
+ export async function getConfiguration() {
13
+ let config = {};
14
+ const configPath = findUpSync(CONFIGURATION_FILES);
15
+ if (!configPath) return config;
16
+
17
+ const ext = path.extname(configPath);
18
+ const regex = /^\.([cm]?js|ts)$/;
19
+ if (regex.test(ext)) {
20
+ const exportedConfig = (await import(pathToFileURL(configPath).href)).default;
21
+ if (typeof exportedConfig === 'function') {
22
+ config = exportedConfig();
23
+ } else {
24
+ config = exportedConfig;
25
+ }
26
+ } else {
27
+ config = JSON.parse(readFileSync(configPath));
28
+ }
29
+
30
+ if (typeof config !== 'object') {
31
+ throw Error(`[relion] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`,);
32
+ }
33
+
34
+ return config;
35
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * modified from <https://github.com/egoist/detect-package-manager/blob/main/src/index.ts>
3
+ * the original code is licensed under MIT
4
+ * modified to support only detecting lock file and not detecting global package manager
5
+ */
6
+
7
+ import { promises as fs } from 'fs';
8
+ import { resolve } from 'path';
9
+
10
+ /**
11
+ * Check if a path exists
12
+ */
13
+ async function pathExists(p) {
14
+ try {
15
+ await fs.access(p);
16
+ return true;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ function getTypeofLockFile(cwd = '.') {
23
+ return Promise.all([
24
+ pathExists(resolve(cwd, 'yarn.lock')),
25
+ pathExists(resolve(cwd, 'package-lock.json')),
26
+ pathExists(resolve(cwd, 'pnpm-lock.yaml')),
27
+ ]).then(([isYarn, isNpm, isPnpm]) => {
28
+ let value = null;
29
+
30
+ if (isYarn) {
31
+ value = 'yarn';
32
+ } else if (isPnpm) {
33
+ value = 'pnpm';
34
+ } else if (isNpm) {
35
+ value = 'npm';
36
+ }
37
+
38
+ return value;
39
+ });
40
+ }
41
+
42
+ export async function detectPMByLockFile(cwd) {
43
+ const type = await getTypeofLockFile(cwd);
44
+ if (type) {
45
+ return type;
46
+ }
47
+
48
+ return 'npm';
49
+ }
@@ -0,0 +1,4 @@
1
+ export default function (args) {
2
+ const message = String(args.preset.releaseCommitMessageFormat);
3
+ return message.replace(/{{currentTag}}/g, args.tagPrefix + args.context.version)
4
+ }