autorel 0.0.21 → 0.0.23

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
@@ -23,7 +23,7 @@ Autorel automatically does the following, if appropriate:
23
23
  - Unlike some other tools, `autorel` is 100% compliant with Conventional Commits and SemVer out of the box, including "!" for breaking changes
24
24
 
25
25
  **😃 Simple & Easy to Use**
26
- - No confusing configuration files
26
+ - No confusing configuration files or complex setup
27
27
  - Works with any CI/CD system, including GitHub Actions
28
28
  - Out of the box TypeScript support
29
29
 
@@ -35,7 +35,7 @@ Autorel automatically does the following, if appropriate:
35
35
  # Example Usage (CLI)
36
36
 
37
37
  ```bash
38
- npx autorel --publish --run "echo \"Next version is ${NEXT_VERSION}!\""
38
+ npx autorel --publish --run 'echo "Next version is ${NEXT_VERSION}"'
39
39
  ```
40
40
 
41
41
  This will:
@@ -43,7 +43,7 @@ This will:
43
43
  1. Bump the version based on the commit messages since the last release (including pushing the tag and updating package.json)
44
44
  2. Create a new release on GitHub with Release Notes
45
45
  3. Publish the release to NPM
46
- 4. Run the command `echo "Next version is ${NEXT_VERSION}!"`
46
+ 4. Run the command `echo "Next version is ${NEXT_VERSION}"`
47
47
 
48
48
  You can also install `autorel` globally and run it that way:
49
49
 
@@ -114,7 +114,7 @@ Whether to skip creating a release on GitHub. If `true`, the release will not be
114
114
 
115
115
  ## run
116
116
 
117
- A command to run after the release is complete. This will be run via `child_process`. The following environment variables are available:
117
+ A command to run after the release is complete. The following environment variables are available:
118
118
 
119
119
  | Variable | Description |
120
120
  | --- | --- |
@@ -127,9 +127,9 @@ A command to run after the release is complete. This will be run via `child_proc
127
127
 
128
128
  ## runScript (YAML only)
129
129
 
130
- A bash script to run after the release is complete. This will be run via `bash` and `child_process`. Environment variables are available as above.
130
+ A bash script to run after the release is complete. Environment variables are available as above.
131
131
 
132
- > This requires `bash` to be installed on the system.
132
+ > ❗️ This requires `bash` to be installed on the system.
133
133
 
134
134
  You can use the multi-line string syntax in YAML to write a script:
135
135
 
@@ -142,20 +142,14 @@ runScript: |
142
142
  - Argument: `runScript: string`
143
143
  - Default: `undefined`
144
144
 
145
- ## tag
146
-
147
- The tag to use for the release. This will be used verbatim, instead of being generated from the version number. Always results in a release being created unless `noRelease` is `true`. **Advanced usage only.**
148
-
149
- - CLI: `--tag`
150
- - Argument: `tag: string`
151
- - Default: `undefined`
152
-
153
145
  ## pre-release
154
146
 
155
- The pre-release channel to use. This will be appended to the version number. For example, if the version is `1.0.0` and the pre-release is `alpha`, the version will be `1.0.0-alpha.1`. For "production" releases, leave this blank. In this case, "latest" will be used for the NPM tag/channel.
147
+ The pre-release channel to use. This will be appended to the version number. For example, if the version is `1.0.0` and the pre-release is `alpha`, the version will be `1.0.0-alpha.1`. For "production" releases, the "latest" tag will be used for NPM.
148
+
149
+ This is typically set via the `branches` configuration (recommended), but can be overridden here.
156
150
 
157
- - CLI: `--pre`
158
- - Argument: `pre: string`
151
+ - CLI: `--pre-release`
152
+ - Argument: `preRelease: string`
159
153
  - Default: `undefined`
160
154
 
161
155
  ## breakingChangeTitle (YAML only)
@@ -192,6 +186,16 @@ The above will release to the `latest` channel (production) on NPM for the `main
192
186
 
193
187
  - Argument: `branches: ReleaseBranch[]`
194
188
 
189
+ ## useVersion
190
+
191
+ The version to use for the release INSTEAD of the version being generated. Always results in a release being created unless `noRelease` is `true`. **Advanced usage only, not recommended for most users.**
192
+
193
+ - CLI: `--use-version`
194
+ - Argument: `useVersion: string`
195
+ - Default: `undefined`
196
+
197
+ > ❗️ Must be a valid SemVer version, without the `v`.
198
+
195
199
  # Sample YAML Configuration
196
200
 
197
201
  <sub>_.autorel.yaml_</sub>
@@ -215,7 +219,7 @@ You can find the types defined at [src/index.ts](src/index.ts).
215
219
  - Issue a PR against `main` and request review. Make sure all tests pass and coverage is good.
216
220
  - Write about `autorel` in your blog, tweet about it, or share it with your friends!
217
221
 
218
- ## Sponors
222
+ ## Sponsors
219
223
 
220
224
  <picture>
221
225
  <source srcset="docs/aeroview-logo-lockup.svg" media="(prefers-color-scheme: dark)">
package/dist/cli.d.ts CHANGED
@@ -1 +1,8 @@
1
- export {};
1
+ export type CliFlags = {
2
+ dry?: boolean;
3
+ preRelease?: string;
4
+ useVersion?: string;
5
+ run?: string;
6
+ noRelease?: boolean;
7
+ publish?: boolean;
8
+ };
package/dist/cli.js CHANGED
@@ -17,24 +17,24 @@ console.log('----------------------------');
17
17
  program
18
18
  .version(packageJson.version, '-v, --version')
19
19
  .description('An example CLI for managing a directory')
20
- .option('--dry', 'Do a dry run')
21
- .option('--pre-release <value>', 'Pre-release channel. If specified, the release will be marked as a pre-release. Overrides any other configuration.')
22
- .option('--tag <value>', 'Specify a tag to be used instead of calculating it from commit analysis. Overrides --pre.')
23
- .option('--run <value>', 'Command to run after the release is successful')
24
- .option('--no-release', 'Does not create a release on GitHub (advanced use only)')
25
- .option('--publish', 'Publish the package to npm, requires passing --npm-token or NPM_TOKEN environment variable')
20
+ .option('--dry', 'Do a dry run (arg: dryRun)')
21
+ .option('--pre-release <value>', 'Pre-release channel. If specified, the release will be marked as a pre-release. Overrides branches configuration. (arg: preRelease)')
22
+ .option('--use-version <value>', 'Specify a version to be used instead of calculating it from commit analysis. Must be a valid SemVer version, with no \'v\'. Overrides --pre-release, commitType, and branches configuration. (arg: useVersion)')
23
+ .option('--run <value>', 'Command to run after the release is successful. (arg: run)')
24
+ .option('--no-release', 'Skips creating a release on GitHub. (arg: noRelease)')
25
+ .option('--publish', 'Publish the package to npm, requires passing --npm-token or NPM_TOKEN environment variable. (arg: publish)')
26
26
  .parse(process.argv);
27
27
  const options = program.opts();
28
- const config = (0, config_1.getConfig)();
29
- output_1.default.debug(`Options: ${JSON.stringify(options, null, 2)}`);
30
- output_1.default.debug(`Config: ${JSON.stringify(config, null, 2)}`);
31
- (0, _1.autorel)({
32
- ...config,
28
+ const cliOptions = {
33
29
  dryRun: options.dry,
34
30
  run: options.run,
35
31
  prereleaseChannel: options.preRelease,
36
- tag: options.tag,
32
+ useVersion: options.useVersion,
37
33
  publish: options.publish,
38
- noRelease: options.noRelease,
39
- });
34
+ noRelease: options.release === false,
35
+ };
36
+ const config = (0, config_1.getConfig)(cliOptions);
37
+ output_1.default.debug(`CLI Options: ${JSON.stringify(cliOptions, null, 2)}`);
38
+ output_1.default.debug(`Config: ${JSON.stringify(config, null, 2)}`);
39
+ (0, _1.autorel)(config);
40
40
  //# sourceMappingURL=cli.js.map
package/dist/config.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Args } from '.';
2
- export declare function getConfig(): Args;
1
+ import { Config } from '.';
2
+ export declare function getConfig(overrides?: Partial<Config>): Config;
package/dist/config.js CHANGED
@@ -38,7 +38,7 @@ const validateConfig = rtype_1.predicates.object({
38
38
  run: rtype_1.predicates.optional(rtype_1.predicates.string()),
39
39
  runScript: rtype_1.predicates.optional(rtype_1.predicates.string()),
40
40
  prereleaseChannel: rtype_1.predicates.optional(rtype_1.predicates.string()),
41
- tag: rtype_1.predicates.optional(rtype_1.predicates.string()),
41
+ useVersion: rtype_1.predicates.optional(rtype_1.predicates.string()),
42
42
  noRelease: rtype_1.predicates.optional(rtype_1.predicates.boolean()),
43
43
  publish: rtype_1.predicates.optional(rtype_1.predicates.boolean()),
44
44
  breakingChangeTitle: rtype_1.predicates.optional(rtype_1.predicates.string()),
@@ -64,6 +64,9 @@ function readAutorelYaml(filePath = '.autorel.yaml') {
64
64
  output_1.default.log('.autorel.yaml not found, using default configuration');
65
65
  return {};
66
66
  }
67
+ else {
68
+ output_1.default.log('Using .autorel.yaml configuration');
69
+ }
67
70
  const [readErr, fileContents] = (0, rtype_1.toResult)(() => fs.readFileSync(absolutePath, 'utf8'));
68
71
  if (readErr) {
69
72
  output_1.default.error('Error reading .autorel.yaml file:');
@@ -81,11 +84,12 @@ function readAutorelYaml(filePath = '.autorel.yaml') {
81
84
  }
82
85
  return parsedData;
83
86
  }
84
- function getConfig() {
87
+ function getConfig(overrides) {
85
88
  const localConfig = readAutorelYaml();
86
89
  return {
87
90
  ...defaults_1.defaultConfig,
88
91
  ...localConfig,
92
+ ...overrides,
89
93
  };
90
94
  }
91
95
  exports.getConfig = getConfig;
@@ -1,2 +1,2 @@
1
- import { Args } from '.';
2
- export declare const defaultConfig: Args;
1
+ import { Config } from '.';
2
+ export declare const defaultConfig: Config;
package/dist/index.d.ts CHANGED
@@ -7,17 +7,17 @@ export type ReleaseBranch = {
7
7
  name: string;
8
8
  prereleaseChannel?: string;
9
9
  };
10
- export type Args = {
10
+ export type Config = {
11
11
  dryRun?: boolean;
12
12
  run?: string;
13
13
  runScript?: string;
14
14
  prereleaseChannel?: string;
15
- tag?: string;
15
+ useVersion?: string;
16
16
  noRelease?: boolean;
17
17
  publish?: boolean;
18
18
  breakingChangeTitle: string;
19
19
  commitTypes: CommitType[];
20
20
  branches: ReleaseBranch[];
21
21
  };
22
- export declare function getPrereleaseChannel(args: Args): string | undefined;
23
- export declare function autorel(args: Args): Promise<void>;
22
+ export declare function getPrereleaseChannel(config: Config): string | undefined;
23
+ export declare function autorel(args: Config): Promise<void>;
package/dist/index.js CHANGED
@@ -36,16 +36,14 @@ const color = __importStar(require("./lib/colors"));
36
36
  const changelog_1 = require("./changelog");
37
37
  const github = __importStar(require("./services/github"));
38
38
  const output_1 = __importDefault(require("./lib/output"));
39
- const config_1 = require("./config");
40
39
  const versionBump_1 = require("./versionBump");
41
40
  const sh_1 = require("./lib/sh");
42
- function getPrereleaseChannel(args) {
43
- if (args.prereleaseChannel)
44
- return args.prereleaseChannel;
41
+ function getPrereleaseChannel(config) {
42
+ if (config.prereleaseChannel)
43
+ return config.prereleaseChannel;
45
44
  const branch = git.getCurrentBranch();
46
45
  if (!branch)
47
46
  throw new Error('Could not get the current branch.');
48
- const config = (0, config_1.getConfig)();
49
47
  if (!config.branches || !config.branches.length)
50
48
  throw new Error('Branches are not defined in the configuration.');
51
49
  const matchingBranch = config.branches.find((b) => b.name === branch);
@@ -59,7 +57,7 @@ async function autorel(args) {
59
57
  if (args.dryRun) {
60
58
  output_1.default.warn('Running in dry-run mode. No changes will be made.');
61
59
  }
62
- if (prereleaseChannel && !args.tag) {
60
+ if (prereleaseChannel && !args.useVersion) {
63
61
  output_1.default.log(`Using prerelease channel: ${color.bold(prereleaseChannel)}`);
64
62
  }
65
63
  const commitTypeMap = new Map(args.commitTypes.map((type) => [type.type, type]));
@@ -77,29 +75,39 @@ async function autorel(args) {
77
75
  || (releaseType === 'minor' && color.yellow('minor'))
78
76
  || (releaseType === 'patch' && color.green('patch'));
79
77
  output_1.default.log(`The release type is: ${releaseTypeStr}`);
80
- if (releaseType === 'none' && !args.tag) {
81
- output_1.default.log('No release is needed. Have a nice day ^_^');
78
+ if (releaseType === 'none' && !args.useVersion) {
79
+ output_1.default.log('No release is needed. Have a nice day (^_^)/');
82
80
  return;
83
81
  }
84
- const nextTag = semver.incrementVersion(lastProdTag || 'v0.0.1', lastTag || 'v0.0.1', releaseType, prereleaseChannel);
85
- if (args.tag) {
86
- output_1.default.log(`The next version would be ${nextTag}, but the tag was set by --tag to be ${color.bold(args.tag)}.`);
87
- output_1.default.warn('The tag was overriden by the --tag parameter. This may cause the next release to be incorrect. Make sure you know what you are doing. This may fail if the tag already exists.');
82
+ const nextTagCalculated = semver.incrementVersion(lastProdTag || 'v0.0.1', lastTag || 'v0.0.1', releaseType, prereleaseChannel);
83
+ if (args.useVersion) {
84
+ if (/^v(.+)$/.test(args.useVersion))
85
+ throw new Error('useVersion should not start with a "v".');
86
+ if (!semver.isValidVersion(args.useVersion))
87
+ throw new Error('useVersion must be a valid SemVer version');
88
+ if (releaseType === 'none') {
89
+ output_1.default.warn(`We didn't find any commmits that would create a release, but you have set 'useVersion', which will force a release as: ${color.bold(args.useVersion)}.`);
90
+ }
91
+ else {
92
+ output_1.default.warn(`The next version would be ${nextTagCalculated}, but the version was set by useVersion to be: ${color.bold(args.useVersion)}.`);
93
+ }
94
+ output_1.default.warn('I hope you know what you\'re doing. (=^・ω・^=)');
88
95
  }
89
96
  else {
90
- output_1.default.log(`The next version is: ${color.bold(nextTag)}`);
97
+ output_1.default.log(`The next version is: ${color.bold(nextTagCalculated)}`);
91
98
  }
99
+ const nextTag = args.useVersion ? `v${args.useVersion}` : nextTagCalculated;
92
100
  const changelog = (0, changelog_1.generateChangelog)(parsedCommits, commitTypeMap, args.breakingChangeTitle);
93
101
  output_1.default.debug(`The changelog is:\n${changelog}`);
94
102
  if (args.dryRun)
95
103
  return;
96
- git.createAndPushTag(args.tag ? args.tag : nextTag);
104
+ git.createAndPushTag(nextTag);
97
105
  const { owner, repository } = git.getRepo();
98
106
  !args.noRelease && github.createRelease({
99
107
  token: process.env.GITHUB_TOKEN,
100
108
  owner,
101
109
  repository,
102
- tag: args.tag ? args.tag : nextTag,
110
+ tag: nextTag,
103
111
  name: nextTag,
104
112
  body: changelog,
105
113
  });
@@ -112,11 +120,9 @@ async function autorel(args) {
112
120
  // run post-release script
113
121
  if (args.run) {
114
122
  output_1.default.log('Running post-release command:');
115
- output_1.default.log('');
116
123
  output_1.default.log('----------------------------');
117
124
  output_1.default.log(args.run);
118
125
  output_1.default.log('----------------------------');
119
- output_1.default.log('');
120
126
  (0, sh_1.cmd)(args.run);
121
127
  }
122
128
  else if (args.runScript) {
package/dist/semver.d.ts CHANGED
@@ -13,4 +13,5 @@ export declare function incrPatch(version: Semver): Semver;
13
13
  export declare function incrMinor(version: Semver): Semver;
14
14
  export declare function incrMajor(version: Semver): Semver;
15
15
  export declare function returnHighestVersion(version1: Semver, version2: Semver): Semver;
16
+ export declare function isValidVersion(ver: string): boolean;
16
17
  export {};
package/dist/semver.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.returnHighestVersion = exports.incrMajor = exports.incrMinor = exports.incrPatch = exports.incrByType = exports.incrementVersion = exports.fromTag = exports.toTag = void 0;
3
+ exports.isValidVersion = exports.returnHighestVersion = exports.incrMajor = exports.incrMinor = exports.incrPatch = exports.incrByType = exports.incrementVersion = exports.fromTag = exports.toTag = void 0;
4
4
  function toTag(version) {
5
5
  let versionString = `${version.major}.${version.minor}.${version.patch}`;
6
6
  if (version.channel) {
@@ -226,4 +226,8 @@ function returnHighestVersion(version1, version2) {
226
226
  return version1;
227
227
  }
228
228
  exports.returnHighestVersion = returnHighestVersion;
229
+ function isValidVersion(ver) {
230
+ return !!fromTag(`v${ver}`);
231
+ }
232
+ exports.isValidVersion = isValidVersion;
229
233
  //# sourceMappingURL=semver.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autorel",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Automate semantic releases based on conventional commits. Similar to semantic-release but much simpler.",
5
5
  "license": "MIT",
6
6
  "author": "Marc H. Weiner <mhweiner234@gmail.com> (https://mhweiner.com)",