@oneblink/release-cli 1.0.0-beta.2 → 1.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/dist/bin.js CHANGED
@@ -1,10 +1,15 @@
1
- #!/usr/bin/env node
2
- import path from 'path';
3
- import updateNotifier from 'update-notifier';
4
- import meow from 'meow';
5
- import enquirer from 'enquirer';
6
- import startReleaseProcess from './startReleaseProcess.js';
7
- const cli = meow(`
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const update_notifier_1 = __importDefault(require("update-notifier"));
9
+ const meow_1 = __importDefault(require("meow"));
10
+ const enquirer_1 = __importDefault(require("enquirer"));
11
+ const startReleaseProcess_1 = __importDefault(require("./startReleaseProcess"));
12
+ const cli = meow_1.default(`
8
13
  oneblink-release [next-version] [--no-git] [--cwd path]
9
14
 
10
15
  next-version ..... The next version, will prompt for this if not supplied,
@@ -22,51 +27,51 @@ Examples
22
27
  oneblink-release 1.1.1
23
28
  oneblink-release 1.1.1 --cwd ../path/to/code
24
29
  oneblink-release 1.1.1-uat.1 --no-git
25
- `, {
26
- flags: {
27
- help: {
28
- type: 'boolean',
29
- default: false,
30
- alias: 'h',
31
- },
32
- version: {
33
- type: 'boolean',
34
- default: false,
35
- alias: 'v',
36
- },
37
- git: {
38
- type: 'boolean',
39
- default: true,
40
- },
41
- cwd: {
42
- type: 'string',
43
- default: process.cwd(),
44
- },
45
- },
46
- });
47
- updateNotifier({
48
- // @ts-expect-error difference in types between packages
49
- pkg: cli.pkg,
50
- }).notify();
51
- run().catch((error) => {
52
- process.exitCode = 1;
53
- console.error(error);
54
- });
55
- async function run() {
56
- let input = cli.input[0];
57
- if (!input) {
58
- const { nextVersion } = await enquirer.prompt([
59
- {
60
- type: 'input',
61
- message: 'Next version? e.g. "1.2.3" or "1.2.3-beta.1"',
62
- name: 'nextVersion',
63
- },
64
- ]);
65
- input = nextVersion;
66
- }
67
- await startReleaseProcess({
68
- nextVersion: input,
69
- git: cli.flags.git,
70
- cwd: path.resolve(process.cwd(), cli.flags.cwd),
71
- });
72
- }
30
+ `, {
31
+ flags: {
32
+ help: {
33
+ type: 'boolean',
34
+ default: false,
35
+ alias: 'h',
36
+ },
37
+ version: {
38
+ type: 'boolean',
39
+ default: false,
40
+ alias: 'v',
41
+ },
42
+ git: {
43
+ type: 'boolean',
44
+ default: true,
45
+ },
46
+ cwd: {
47
+ type: 'string',
48
+ default: process.cwd(),
49
+ },
50
+ },
51
+ });
52
+ update_notifier_1.default({
53
+ // @ts-expect-error difference in types between packages
54
+ pkg: cli.pkg,
55
+ }).notify();
56
+ run().catch((error) => {
57
+ process.exitCode = 1;
58
+ console.error(error);
59
+ });
60
+ async function run() {
61
+ let input = cli.input[0];
62
+ if (!input) {
63
+ const { nextVersion } = await enquirer_1.default.prompt([
64
+ {
65
+ type: 'input',
66
+ message: 'Next version? e.g. "1.2.3" or "1.2.3-beta.1"',
67
+ name: 'nextVersion',
68
+ },
69
+ ]);
70
+ input = nextVersion;
71
+ }
72
+ await startReleaseProcess_1.default({
73
+ nextVersion: input,
74
+ git: cli.flags.git,
75
+ cwd: path_1.default.resolve(process.cwd(), cli.flags.cwd),
76
+ });
77
+ }
@@ -1,110 +1,115 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import util from 'util';
4
- import execa from 'execa';
5
- import prettier from 'prettier';
6
- import parseChangelog from 'changelog-parser';
7
- import { main as packageDiffSummary } from 'package-diff-summary';
8
- import semver from 'semver';
9
- import ora from 'ora';
10
- import { readPackageUpAsync } from 'read-pkg-up';
11
- const readFileAsync = util.promisify(fs.readFile);
12
- const writeFileAsync = util.promisify(fs.writeFile);
13
- const UNRELEASED_VERSION_INDEX = 0;
14
- const GIT_TAG_PREFIX = 'v';
15
- async function wrapWithLoading({ startText, failText }, fn) {
16
- const spinner = ora(startText).start();
17
- try {
18
- const t = await fn(spinner);
19
- if (spinner.isSpinning) {
20
- spinner.stop();
21
- }
22
- return t;
23
- }
24
- catch (error) {
25
- spinner.fail(failText);
26
- throw error;
27
- }
28
- }
29
- async function updateChangelog({ nextSemverVersion, cwd, }) {
30
- const changelogPath = path.join(cwd, 'CHANGELOG.md');
31
- const parsedChangelog = await wrapWithLoading({
32
- startText: `Parsing ${changelogPath}`,
33
- failText: `Failed to parsed ${changelogPath}`,
34
- }, async (spinner) => {
35
- const parsedChangelog = (await parseChangelog(changelogPath));
36
- spinner.succeed(`Parsed ${changelogPath}`);
37
- return parsedChangelog;
38
- });
39
- const dependenciesChangelogEntry = await wrapWithLoading({
40
- startText: 'Checking if the "Dependencies" heading should be added to CHANGELOG.md',
41
- failText: 'Failed to check if the "Dependencies" heading should be added to CHANGELOG.md',
42
- }, async (spinner) => {
43
- const unreleasedVersion = parsedChangelog.versions[UNRELEASED_VERSION_INDEX];
44
- if (!unreleasedVersion ||
45
- !unreleasedVersion.title.toLowerCase().includes('unreleased')) {
46
- throw new Error('"Unreleased" heading in CHANGELOG.md does not exist');
47
- }
48
- const dependenciesChangelogHeading = '### Dependencies';
49
- if (unreleasedVersion.body.includes(dependenciesChangelogHeading)) {
50
- spinner.warn('Skipping inserting the "Dependencies" heading in CHANGELOG.md as it already exists under the "Unreleased" heading. It is recommended to allow this release process to insert instead of adding them as dependencies change.');
51
- return '';
52
- }
53
- const lastVersion = parsedChangelog.versions[1];
54
- if (!lastVersion) {
55
- spinner.info('Skipping inserting the "Dependencies" heading in CHANGELOG.md as this is the first release according to the CHANGELOG.md.');
56
- return '';
57
- }
58
- let dependenciesChangelogEntries = '';
59
- const lastGitTag = `${GIT_TAG_PREFIX}${lastVersion.version}`;
60
- try {
61
- const result = await packageDiffSummary({
62
- cwd,
63
- previousVersion: lastGitTag,
64
- });
65
- dependenciesChangelogEntries = result.trim();
66
- }
67
- catch (error) {
68
- if (error.message.includes(`git show ${lastGitTag}:package.json`)) {
69
- spinner.warn(`Skipping inserting the "Dependencies" heading in CHANGELOG.md as it relies on the last release's git tag having a "v" prefix (i.e. "${lastGitTag}")`);
70
- return '';
71
- }
72
- throw error;
73
- }
74
- if (!dependenciesChangelogEntries) {
75
- spinner.info(`Skipping inserting the "Dependencies" heading in CHANGELOG.md as there were no dependency changes since the last release (${lastVersion.version})`);
76
- return '';
77
- }
78
- spinner.succeed('"Dependencies" heading will be added to CHANGELOG.md');
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const util_1 = __importDefault(require("util"));
9
+ const execa_1 = __importDefault(require("execa"));
10
+ const prettier_1 = __importDefault(require("prettier"));
11
+ const changelog_parser_1 = __importDefault(require("changelog-parser"));
12
+ const package_diff_summary_1 = require("package-diff-summary");
13
+ const semver_1 = __importDefault(require("semver"));
14
+ const ora_1 = __importDefault(require("ora"));
15
+ const read_pkg_up_1 = __importDefault(require("read-pkg-up"));
16
+ const readFileAsync = util_1.default.promisify(fs_1.default.readFile);
17
+ const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
18
+ const UNRELEASED_VERSION_INDEX = 0;
19
+ const GIT_TAG_PREFIX = 'v';
20
+ async function wrapWithLoading({ startText, failText }, fn) {
21
+ const spinner = ora_1.default(startText).start();
22
+ try {
23
+ const t = await fn(spinner);
24
+ if (spinner.isSpinning) {
25
+ spinner.stop();
26
+ }
27
+ return t;
28
+ }
29
+ catch (error) {
30
+ spinner.fail(failText);
31
+ throw error;
32
+ }
33
+ }
34
+ async function updateChangelog({ nextSemverVersion, cwd, }) {
35
+ const changelogPath = path_1.default.join(cwd, 'CHANGELOG.md');
36
+ const parsedChangelog = await wrapWithLoading({
37
+ startText: `Parsing ${changelogPath}`,
38
+ failText: `Failed to parsed ${changelogPath}`,
39
+ }, async (spinner) => {
40
+ const parsedChangelog = (await changelog_parser_1.default(changelogPath));
41
+ spinner.succeed(`Parsed ${changelogPath}`);
42
+ return parsedChangelog;
43
+ });
44
+ const dependenciesChangelogEntry = await wrapWithLoading({
45
+ startText: 'Checking if the "Dependencies" heading should be added to CHANGELOG.md',
46
+ failText: 'Failed to check if the "Dependencies" heading should be added to CHANGELOG.md',
47
+ }, async (spinner) => {
48
+ const unreleasedVersion = parsedChangelog.versions[UNRELEASED_VERSION_INDEX];
49
+ if (!unreleasedVersion ||
50
+ !unreleasedVersion.title.toLowerCase().includes('unreleased')) {
51
+ throw new Error('"Unreleased" heading in CHANGELOG.md does not exist');
52
+ }
53
+ const dependenciesChangelogHeading = '### Dependencies';
54
+ if (unreleasedVersion.body.includes(dependenciesChangelogHeading)) {
55
+ spinner.warn('Skipping inserting the "Dependencies" heading in CHANGELOG.md as it already exists under the "Unreleased" heading. It is recommended to allow this release process to insert instead of adding them as dependencies change.');
56
+ return '';
57
+ }
58
+ const lastVersion = parsedChangelog.versions[1];
59
+ if (!lastVersion) {
60
+ spinner.info('Skipping inserting the "Dependencies" heading in CHANGELOG.md as this is the first release according to the CHANGELOG.md.');
61
+ return '';
62
+ }
63
+ let dependenciesChangelogEntries = '';
64
+ const lastGitTag = `${GIT_TAG_PREFIX}${lastVersion.version}`;
65
+ try {
66
+ const result = await package_diff_summary_1.main({
67
+ cwd,
68
+ previousVersion: lastGitTag,
69
+ });
70
+ dependenciesChangelogEntries = result.trim();
71
+ }
72
+ catch (error) {
73
+ if (error.message.includes(`git show ${lastGitTag}:package.json`)) {
74
+ spinner.warn(`Skipping inserting the "Dependencies" heading in CHANGELOG.md as it relies on the last release's git tag having a "v" prefix (i.e. "${lastGitTag}")`);
75
+ return '';
76
+ }
77
+ throw error;
78
+ }
79
+ if (!dependenciesChangelogEntries) {
80
+ spinner.info(`Skipping inserting the "Dependencies" heading in CHANGELOG.md as there were no dependency changes since the last release (${lastVersion.version})`);
81
+ return '';
82
+ }
83
+ spinner.succeed('"Dependencies" heading will be added to CHANGELOG.md');
79
84
  return `
80
85
  ${dependenciesChangelogHeading}
81
86
 
82
87
  ${dependenciesChangelogEntries}
83
- `;
84
- });
85
- const nextReleaseTitle = `[${nextSemverVersion}] - ${new Date()
86
- .toISOString()
87
- .substring(0, 10)}`;
88
- await wrapWithLoading({
89
- startText: `Updating CHANGELOG.md with next release (${nextReleaseTitle})`,
90
- failText: `Failed to update CHANGELOG.md with next release (${nextReleaseTitle})`,
91
- }, async (spinner) => {
92
- let prettierOptions = {};
93
- try {
94
- const s = await readFileAsync(path.join(cwd, '.prettierrc'), 'UTF-8');
95
- prettierOptions = JSON.parse(s);
96
- }
97
- catch (error) {
98
- // ignore errors attempting to find prettier configuration
99
- }
100
- const changelog = prettier.format(`
88
+ `;
89
+ });
90
+ const nextReleaseTitle = `[${nextSemverVersion}] - ${new Date()
91
+ .toISOString()
92
+ .substring(0, 10)}`;
93
+ await wrapWithLoading({
94
+ startText: `Updating CHANGELOG.md with next release (${nextReleaseTitle})`,
95
+ failText: `Failed to update CHANGELOG.md with next release (${nextReleaseTitle})`,
96
+ }, async (spinner) => {
97
+ let prettierOptions = {};
98
+ try {
99
+ const s = await readFileAsync(path_1.default.join(cwd, '.prettierrc'), 'UTF-8');
100
+ prettierOptions = JSON.parse(s);
101
+ }
102
+ catch (error) {
103
+ // ignore errors attempting to find prettier configuration
104
+ }
105
+ const changelog = prettier_1.default.format(`
101
106
  # ${parsedChangelog.title}
102
107
 
103
108
  ${parsedChangelog.description || ''}
104
109
 
105
- ${parsedChangelog.versions
106
- .map(({ title, body }, index) => {
107
- if (index === UNRELEASED_VERSION_INDEX) {
110
+ ${parsedChangelog.versions
111
+ .map(({ title, body }, index) => {
112
+ if (index === UNRELEASED_VERSION_INDEX) {
108
113
  return `
109
114
  ## ${title}
110
115
 
@@ -113,73 +118,74 @@ ${parsedChangelog.versions
113
118
  ${body}
114
119
 
115
120
  ${dependenciesChangelogEntry}
116
- `;
117
- }
121
+ `;
122
+ }
118
123
  return `
119
124
  ## ${title}
120
125
 
121
126
  ${body}
122
- `;
123
- })
124
- .join('')}`, {
125
- ...prettierOptions,
126
- parser: 'markdown',
127
- });
128
- await writeFileAsync(changelogPath, changelog, 'UTF-8');
129
- spinner.succeed(`Updated CHANGELOG.md with next release (${nextReleaseTitle})`);
130
- });
131
- }
132
- async function checkIfNPMPackageVersionShouldBeUpdated(cwd) {
133
- const result = await readPackageUpAsync({
134
- cwd,
135
- });
136
- return !!result?.packageJson;
137
- }
138
- async function executeCommand(command, args, cwd) {
139
- await wrapWithLoading({
140
- startText: `Running "${command} ${args.join(' ')}"`,
141
- failText: `Failed to run "${command} ${args.join(' ')}"`,
142
- }, async (spinner) => {
143
- await execa(command, args, {
144
- cwd,
145
- });
146
- spinner.succeed(`Ran "${command} ${args.join(' ')}"`);
147
- });
148
- }
149
- export default async function startReleaseProcess({ nextVersion, cwd, git, }) {
150
- const nextSemverVersion = semver.valid(nextVersion);
151
- if (!nextSemverVersion) {
152
- throw new Error('Next version is not valid semver');
153
- }
154
- const npm = await checkIfNPMPackageVersionShouldBeUpdated(cwd);
155
- const preReleaseComponents = semver.prerelease(nextSemverVersion);
156
- if (preReleaseComponents && preReleaseComponents[0]) {
157
- const text = `Skipping changelog updates for "${preReleaseComponents[0]}" release`;
158
- ora(text).start().info(text);
159
- }
160
- else {
161
- await updateChangelog({
162
- nextSemverVersion,
163
- cwd,
164
- });
165
- }
166
- if (npm) {
167
- await executeCommand('npm', ['version', nextSemverVersion, '--no-git-tag-version'], cwd);
168
- }
169
- if (!git) {
170
- const text = `Skipping committing release changes using git`;
171
- ora(text).start().info(text);
172
- return;
173
- }
174
- await executeCommand('git', ['add', '-A'], cwd);
175
- await executeCommand('git', ['commit', '--message', `[RELEASE] ${nextSemverVersion}`], cwd);
176
- await executeCommand('git', ['push'], cwd);
177
- await executeCommand('git', [
178
- 'tag',
179
- '-a',
180
- `${GIT_TAG_PREFIX}${nextSemverVersion}`,
181
- '-m',
182
- `[RELEASE] ${nextSemverVersion}`,
183
- ], cwd);
184
- await executeCommand('git', ['push', '--tags'], cwd);
185
- }
127
+ `;
128
+ })
129
+ .join('')}`, {
130
+ ...prettierOptions,
131
+ parser: 'markdown',
132
+ });
133
+ await writeFileAsync(changelogPath, changelog, 'UTF-8');
134
+ spinner.succeed(`Updated CHANGELOG.md with next release (${nextReleaseTitle})`);
135
+ });
136
+ }
137
+ async function checkIfNPMPackageVersionShouldBeUpdated(cwd) {
138
+ const result = await read_pkg_up_1.default({
139
+ cwd,
140
+ });
141
+ return !!result?.packageJson;
142
+ }
143
+ async function executeCommand(command, args, cwd) {
144
+ await wrapWithLoading({
145
+ startText: `Running "${command} ${args.join(' ')}"`,
146
+ failText: `Failed to run "${command} ${args.join(' ')}"`,
147
+ }, async (spinner) => {
148
+ await execa_1.default(command, args, {
149
+ cwd,
150
+ });
151
+ spinner.succeed(`Ran "${command} ${args.join(' ')}"`);
152
+ });
153
+ }
154
+ async function startReleaseProcess({ nextVersion, cwd, git, }) {
155
+ const nextSemverVersion = semver_1.default.valid(nextVersion);
156
+ if (!nextSemverVersion) {
157
+ throw new Error('Next version is not valid semver');
158
+ }
159
+ const npm = await checkIfNPMPackageVersionShouldBeUpdated(cwd);
160
+ const preReleaseComponents = semver_1.default.prerelease(nextSemverVersion);
161
+ if (preReleaseComponents && preReleaseComponents[0]) {
162
+ const text = `Skipping changelog updates for "${preReleaseComponents[0]}" release`;
163
+ ora_1.default(text).start().info(text);
164
+ }
165
+ else {
166
+ await updateChangelog({
167
+ nextSemverVersion,
168
+ cwd,
169
+ });
170
+ }
171
+ if (npm) {
172
+ await executeCommand('npm', ['version', nextSemverVersion, '--no-git-tag-version'], cwd);
173
+ }
174
+ if (!git) {
175
+ const text = `Skipping committing release changes using git`;
176
+ ora_1.default(text).start().info(text);
177
+ return;
178
+ }
179
+ await executeCommand('git', ['add', '-A'], cwd);
180
+ await executeCommand('git', ['commit', '--message', `[RELEASE] ${nextSemverVersion}`], cwd);
181
+ await executeCommand('git', ['push'], cwd);
182
+ await executeCommand('git', [
183
+ 'tag',
184
+ '-a',
185
+ `${GIT_TAG_PREFIX}${nextSemverVersion}`,
186
+ '-m',
187
+ `[RELEASE] ${nextSemverVersion}`,
188
+ ], cwd);
189
+ await executeCommand('git', ['push', '--tags'], cwd);
190
+ }
191
+ exports.default = startReleaseProcess;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/release-cli",
3
3
  "description": "Used internally by OneBlink to release code bases quickly and consistently",
4
- "version": "1.0.0-beta.2",
4
+ "version": "1.1.1",
5
5
  "author": "OneBlink <developers@oneblink> (https://github.com/oneblink)",
6
6
  "bin": {
7
7
  "oneblink-release": "dist/bin.js"
@@ -17,7 +17,7 @@
17
17
  "ora": "^5.4.0",
18
18
  "package-diff-summary": "^3.0.1",
19
19
  "prettier": "^2.2.1",
20
- "read-pkg-up": "^8.0.0",
20
+ "read-pkg-up": "^7.0.1",
21
21
  "semver": "^7.3.5",
22
22
  "update-notifier": "^5.1.0"
23
23
  },
@@ -33,6 +33,7 @@
33
33
  "eslint-config-prettier": "^8.1.0",
34
34
  "eslint-plugin-prettier": "^3.3.1",
35
35
  "jest": "^26.6.3",
36
+ "patch-package": "^6.4.7",
36
37
  "ts-jest": "^26.5.4",
37
38
  "typescript": "^4.2.3"
38
39
  },
@@ -43,7 +44,6 @@
43
44
  "node": ">=14",
44
45
  "npm": ">=6"
45
46
  },
46
- "exports": "./dist/startReleaseProcess.js",
47
47
  "files": [
48
48
  "dist"
49
49
  ],
@@ -52,6 +52,7 @@
52
52
  "release"
53
53
  ],
54
54
  "license": "GPL-3.0-only",
55
+ "main": "./dist/startReleaseProcess.js",
55
56
  "publishConfig": {
56
57
  "access": "public"
57
58
  },
@@ -65,7 +66,7 @@
65
66
  "jest": "jest --silent",
66
67
  "prepare": "npm run build",
67
68
  "pretest": "npm run eslint",
68
- "test": "npm run jest"
69
- },
70
- "type": "module"
69
+ "test": "npm run jest",
70
+ "postinstall": "patch-package"
71
+ }
71
72
  }
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- - Initial Release