deploy-vir 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/dist/cli/cli.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { assertWrap } from '@augment-vir/assert';
2
2
  import { awaitedForEach, extractErrorMessage, log } from '@augment-vir/common';
3
+ import { select } from '@inquirer/prompts';
3
4
  import { resolve } from 'node:path';
4
- import simpleGit from 'simple-git';
5
+ import { simpleGit } from 'simple-git';
5
6
  import { getGitRemoteName, pushDeploy } from '../git.js';
6
7
  import { KnownError } from '../known.error.js';
7
8
  import { sendNotifications } from '../notifications/send-notifications.js';
@@ -12,9 +13,23 @@ import { sendNotifications } from '../notifications/send-notifications.js';
12
13
  */
13
14
  export async function runDeployVirCli({ args, y, }, cwd = process.cwd()) {
14
15
  const configPath = assertWrap.isTruthy(args[0], 'Missing config path.');
15
- const repoName = assertWrap.isTruthy(args[1], 'Missing repo name.');
16
- const deployName = assertWrap.isTruthy(args[2], 'Missing deploy name.');
17
16
  const config = (await import(resolve(cwd, configPath))).default;
17
+ const repoName = assertWrap.isTruthy(args[1] ||
18
+ (await select({
19
+ message: 'Choose a repo to deploy:',
20
+ choices: config.repos.map((repo) => {
21
+ return repo.name;
22
+ }),
23
+ })), 'Missing repo name.');
24
+ const deployName = assertWrap.isTruthy(args[2] ||
25
+ (await select({
26
+ message: 'Choose a deploy to trigger:',
27
+ choices: assertWrap
28
+ .isDefined(config.repos.find((repo) => repo.name === repoName), `Invalid repo name: '${repoName}'`)
29
+ .deploys.map((deploy) => {
30
+ return deploy.deployName;
31
+ }),
32
+ })), 'Missing deploy name.');
18
33
  await runDeployVir({
19
34
  cwd,
20
35
  deployName,
package/dist/git.d.ts CHANGED
@@ -38,6 +38,7 @@ export type DeployBranchStatus = {
38
38
  export type DeployResult = {
39
39
  deployCommits: DeployCommits;
40
40
  branchStatus: DeployBranchStatus;
41
+ toBranchName: string;
41
42
  };
42
43
  /**
43
44
  * Push the deploy via git.
package/dist/git.js CHANGED
@@ -88,6 +88,7 @@ export async function pushDeploy(git, { deployName, branches }, remoteName, bypa
88
88
  await git.push(remoteName, pushString);
89
89
  }
90
90
  return {
91
+ toBranchName: toBranch,
91
92
  deployCommits: {
92
93
  deployedCommits: commitsAhead,
93
94
  overwrittenCommits: commitsBehind,
@@ -5,4 +5,4 @@ export { type ChatPostMessageArguments } from '@slack/web-api';
5
5
  *
6
6
  * @category Internal
7
7
  */
8
- export declare function sendNotificationToSlack({ branchConfig, deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
8
+ export declare function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
@@ -38,7 +38,7 @@ function chunkSectionLines(lines) {
38
38
  *
39
39
  * @category Internal
40
40
  */
41
- export async function sendNotificationToSlack({ branchConfig, deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, }, notification, repoConfig, }) {
41
+ export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }) {
42
42
  const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
43
43
  const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
44
44
  const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
@@ -56,7 +56,7 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
56
56
  type: 'section',
57
57
  text: {
58
58
  type: 'mrkdwn',
59
- text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(branchConfig.deployName, StringCase.Upper)}* Pushed`,
59
+ text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
60
60
  },
61
61
  },
62
62
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-vir",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Deploy a branch to another branch with notifications.",
5
5
  "keywords": [
6
6
  "deploy",
@@ -41,9 +41,9 @@
41
41
  "test:update": "npm run test update"
42
42
  },
43
43
  "dependencies": {
44
- "@augment-vir/assert": "^31.57.1",
45
- "@augment-vir/common": "^31.57.1",
46
- "@augment-vir/node": "^31.57.1",
44
+ "@augment-vir/assert": "^31.57.5",
45
+ "@augment-vir/common": "^31.57.5",
46
+ "@augment-vir/node": "^31.57.5",
47
47
  "@inquirer/prompts": "^8.1.0",
48
48
  "@slack/web-api": "^7.13.0",
49
49
  "cli-vir": "^1.0.3",
@@ -57,9 +57,9 @@
57
57
  "@stylistic/eslint-plugin": "^5.6.1",
58
58
  "@stylistic/eslint-plugin-ts": "^4.4.1",
59
59
  "@types/node": "^25.0.3",
60
- "@typescript-eslint/eslint-plugin": "^8.50.1",
60
+ "@typescript-eslint/eslint-plugin": "^8.52.0",
61
61
  "cspell": "^9.4.0",
62
- "dependency-cruiser": "^17.3.5",
62
+ "dependency-cruiser": "^17.3.6",
63
63
  "esbuild": "^0.27.2",
64
64
  "eslint": "^9.39.2",
65
65
  "eslint-config-prettier": "^10.1.8",
@@ -72,7 +72,7 @@
72
72
  "eslint-plugin-unicorn": "^62.0.0",
73
73
  "istanbul-smart-text-reporter": "^1.1.5",
74
74
  "markdown-code-example-inserter": "^3.0.3",
75
- "npm-check-updates": "^19.2.0",
75
+ "npm-check-updates": "^19.3.1",
76
76
  "prettier": "~3.3.3",
77
77
  "prettier-plugin-interpolated-html-tags": "^2.0.1",
78
78
  "prettier-plugin-jsdoc": "^1.8.0",
@@ -84,8 +84,8 @@
84
84
  "runstorm": "^1.0.0",
85
85
  "typedoc": "^0.28.15",
86
86
  "typescript": "^5.9.3",
87
- "typescript-eslint": "^8.50.1",
88
- "virmator": "^14.4.0"
87
+ "typescript-eslint": "^8.52.0",
88
+ "virmator": "^14.4.2"
89
89
  },
90
90
  "engines": {
91
91
  "node": ">=22"
package/src/cli/cli.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import {assertWrap} from '@augment-vir/assert';
2
2
  import {awaitedForEach, extractErrorMessage, log} from '@augment-vir/common';
3
+ import {select} from '@inquirer/prompts';
3
4
  import {resolve} from 'node:path';
4
- import simpleGit from 'simple-git';
5
+ import {simpleGit} from 'simple-git';
5
6
  import {type DeployVirConfig} from '../config.js';
6
7
  import {getGitRemoteName, pushDeploy} from '../git.js';
7
8
  import {KnownError} from '../known.error.js';
@@ -23,10 +24,34 @@ export async function runDeployVirCli(
23
24
  cwd = process.cwd(),
24
25
  ) {
25
26
  const configPath = assertWrap.isTruthy(args[0], 'Missing config path.');
26
- const repoName = assertWrap.isTruthy(args[1], 'Missing repo name.');
27
- const deployName = assertWrap.isTruthy(args[2], 'Missing deploy name.');
28
27
 
29
- const config = (await import(resolve(cwd, configPath))).default;
28
+ const config = (await import(resolve(cwd, configPath))).default as DeployVirConfig;
29
+
30
+ const repoName = assertWrap.isTruthy(
31
+ args[1] ||
32
+ (await select({
33
+ message: 'Choose a repo to deploy:',
34
+ choices: config.repos.map((repo) => {
35
+ return repo.name;
36
+ }),
37
+ })),
38
+ 'Missing repo name.',
39
+ );
40
+ const deployName = assertWrap.isTruthy(
41
+ args[2] ||
42
+ (await select({
43
+ message: 'Choose a deploy to trigger:',
44
+ choices: assertWrap
45
+ .isDefined(
46
+ config.repos.find((repo) => repo.name === repoName),
47
+ `Invalid repo name: '${repoName}'`,
48
+ )
49
+ .deploys.map((deploy) => {
50
+ return deploy.deployName;
51
+ }),
52
+ })),
53
+ 'Missing deploy name.',
54
+ );
30
55
 
31
56
  await runDeployVir(
32
57
  {
package/src/git.ts CHANGED
@@ -79,6 +79,7 @@ export type DeployBranchStatus = {
79
79
  export type DeployResult = {
80
80
  deployCommits: DeployCommits;
81
81
  branchStatus: DeployBranchStatus;
82
+ toBranchName: string;
82
83
  };
83
84
 
84
85
  /**
@@ -92,108 +93,112 @@ export async function pushDeploy(
92
93
  remoteName: string,
93
94
  bypassConfirmation = false,
94
95
  ): Promise<DeployResult[]> {
95
- return await awaitedBlockingMap(branches, async ({fromBranch, toBranch}) => {
96
- assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
97
- assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
98
- assert.isTruthy(remoteName, 'Remote name cannot be empty.');
99
-
100
- log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
101
-
102
- await git.fetch(remoteName, fromBranch);
103
- await git.fetch(remoteName, toBranch);
96
+ return await awaitedBlockingMap(
97
+ branches,
98
+ async ({fromBranch, toBranch}): Promise<DeployResult> => {
99
+ assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
100
+ assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
101
+ assert.isTruthy(remoteName, 'Remote name cannot be empty.');
102
+
103
+ log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
104
+
105
+ await git.fetch(remoteName, fromBranch);
106
+ await git.fetch(remoteName, toBranch);
107
+
108
+ const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
109
+
110
+ // Get the current commit on the target branch before pushing
111
+ const beforeCommit = assertWrap.isDefined(
112
+ (
113
+ await git.log([
114
+ `${remoteName}/${toBranch}`,
115
+ '-1',
116
+ ])
117
+ ).latest,
118
+ `Failed to get current commit for ${remoteName}/${toBranch}`,
119
+ );
104
120
 
105
- const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
121
+ const afterCommit = assertWrap.isDefined(
122
+ (
123
+ await git.log([
124
+ `${remoteName}/${fromBranch}`,
125
+ '-1',
126
+ ])
127
+ ).latest,
128
+ `Failed to get current commit for ${remoteName}/${fromBranch}`,
129
+ );
106
130
 
107
- // Get the current commit on the target branch before pushing
108
- const beforeCommit = assertWrap.isDefined(
109
- (
131
+ /** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
132
+ const commitsAhead = (
110
133
  await git.log([
111
- `${remoteName}/${toBranch}`,
112
- '-1',
134
+ `${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
113
135
  ])
114
- ).latest,
115
- `Failed to get current commit for ${remoteName}/${toBranch}`,
116
- );
136
+ ).all;
137
+
138
+ if (!commitsAhead.length) {
139
+ throw new KnownError('No commit diff: nothing to deploy!');
140
+ }
117
141
 
118
- const afterCommit = assertWrap.isDefined(
119
- (
142
+ /** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
143
+ const commitsBehind = (
120
144
  await git.log([
121
- `${remoteName}/${fromBranch}`,
122
- '-1',
145
+ `${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
123
146
  ])
124
- ).latest,
125
- `Failed to get current commit for ${remoteName}/${fromBranch}`,
126
- );
127
-
128
- /** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
129
- const commitsAhead = (
130
- await git.log([
131
- `${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
132
- ])
133
- ).all;
134
-
135
- if (!commitsAhead.length) {
136
- throw new KnownError('No commit diff: nothing to deploy!');
137
- }
138
-
139
- /** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
140
- const commitsBehind = (
141
- await git.log([
142
- `${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
143
- ])
144
- ).all;
145
-
146
- const requiresForcePush = commitsBehind.length > 0;
147
-
148
- log.info(
149
- `\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
150
- );
151
- commitsAhead.forEach((commit, index) => {
152
- log.faint(
153
- ` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
154
- );
155
- });
147
+ ).all;
156
148
 
157
- if (requiresForcePush) {
158
- log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
159
- commitsBehind.forEach((commit, index) => {
149
+ const requiresForcePush = commitsBehind.length > 0;
150
+
151
+ log.info(
152
+ `\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
153
+ );
154
+ commitsAhead.forEach((commit, index) => {
160
155
  log.faint(
161
156
  ` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
162
157
  );
163
158
  });
164
- }
165
-
166
- const shouldPush =
167
- bypassConfirmation ||
168
- (await confirm({
169
- message: requiresForcePush
170
- ? `\n${logColors.warning}Do you want to force push ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.normalWeight}?\n\nThis will overwrite the commits only on ${logColors.bold}${toBranch}${logColors.normalWeight}.${logColors.reset}?`
171
- : 'Ready to deploy?',
172
- default: false,
173
- }));
174
-
175
- if (!shouldPush) {
176
- throw new KnownError(`Deploy aborted.`);
177
- }
178
-
179
- if (requiresForcePush) {
180
- await git.push(remoteName, pushString, ['--force']);
181
- log.warning(
182
- `Force pushed ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.reset}.`,
183
- );
184
- } else {
185
- await git.push(remoteName, pushString);
186
- }
187
-
188
- return {
189
- deployCommits: {
190
- deployedCommits: commitsAhead,
191
- overwrittenCommits: commitsBehind,
192
- },
193
- branchStatus: {
194
- before: beforeCommit,
195
- after: afterCommit,
196
- },
197
- };
198
- });
159
+
160
+ if (requiresForcePush) {
161
+ log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
162
+ commitsBehind.forEach((commit, index) => {
163
+ log.faint(
164
+ ` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
165
+ );
166
+ });
167
+ }
168
+
169
+ const shouldPush =
170
+ bypassConfirmation ||
171
+ (await confirm({
172
+ message: requiresForcePush
173
+ ? `\n${logColors.warning}Do you want to force push ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.normalWeight}?\n\nThis will overwrite the commits only on ${logColors.bold}${toBranch}${logColors.normalWeight}.${logColors.reset}?`
174
+ : 'Ready to deploy?',
175
+ default: false,
176
+ }));
177
+
178
+ if (!shouldPush) {
179
+ throw new KnownError(`Deploy aborted.`);
180
+ }
181
+
182
+ if (requiresForcePush) {
183
+ await git.push(remoteName, pushString, ['--force']);
184
+ log.warning(
185
+ `Force pushed ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.reset}.`,
186
+ );
187
+ } else {
188
+ await git.push(remoteName, pushString);
189
+ }
190
+
191
+ return {
192
+ toBranchName: toBranch,
193
+ deployCommits: {
194
+ deployedCommits: commitsAhead,
195
+ overwrittenCommits: commitsBehind,
196
+ },
197
+ branchStatus: {
198
+ before: beforeCommit,
199
+ after: afterCommit,
200
+ },
201
+ };
202
+ },
203
+ );
199
204
  }
@@ -53,10 +53,10 @@ function chunkSectionLines(lines: ReadonlyArray<string>): string[][] {
53
53
  * @category Internal
54
54
  */
55
55
  export async function sendNotificationToSlack({
56
- branchConfig,
57
56
  deployResult: {
58
57
  deployCommits: {deployedCommits, overwrittenCommits},
59
58
  branchStatus: {after, before},
59
+ toBranchName,
60
60
  },
61
61
  notification,
62
62
  repoConfig,
@@ -86,7 +86,7 @@ export async function sendNotificationToSlack({
86
86
  type: 'section',
87
87
  text: {
88
88
  type: 'mrkdwn',
89
- text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(branchConfig.deployName, StringCase.Upper)}* Pushed`,
89
+ text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
90
90
  },
91
91
  },
92
92
  {