Skip to content

Commit 8ae1816

Browse files
Separated the files property into updatedFiles and skippedFiles. Added a "file skipped" event.
1 parent e822206 commit 8ae1816

7 files changed

Lines changed: 41 additions & 27 deletions

File tree

src/cli/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable: no-console
2-
import { success } from "log-symbols";
2+
import { info, success } from "log-symbols";
33
import { manifest } from "../manifest";
44
import { ProgressEvent, VersionBumpProgress } from "../types/version-bump-progress";
55
import { versionBump } from "../version-bump";
@@ -44,11 +44,15 @@ export async function main(args: string[]): Promise<void> {
4444
}
4545
}
4646

47-
function progress({ event, files, newVersion }: VersionBumpProgress): void {
47+
function progress({ event, updatedFiles, skippedFiles, newVersion }: VersionBumpProgress): void {
4848
// tslint:disable-next-line: switch-default
4949
switch (event) {
5050
case ProgressEvent.FileUpdated:
51-
console.log(success, `Updated ${files.pop()} to ${newVersion}`);
51+
console.log(success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
52+
break;
53+
54+
case ProgressEvent.FileSkipped:
55+
console.log(info, `${skippedFiles.pop()} did not need to be updated`);
5256
break;
5357

5458
case ProgressEvent.GitCommit:

src/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function gitCommit(operation: Operation): Promise<Operation> {
1111
}
1212

1313
let { all, noVerify, message } = operation.options.commit;
14-
let { files, newVersion } = operation.state;
14+
let { updatedFiles, newVersion } = operation.state;
1515
let args = [];
1616

1717
if (all) {
@@ -30,7 +30,7 @@ export async function gitCommit(operation: Operation): Promise<Operation> {
3030

3131
// Append the file names last, as variadic arguments
3232
if (!all) {
33-
args = args.concat(files);
33+
args = args.concat(updatedFiles);
3434
}
3535

3636
await ezSpawn.async("git", ["commit", ...args]);

src/operation.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ interface OperationState {
1313
newVersion: string;
1414
commitMessage: string;
1515
tagName: string;
16-
files: string[];
16+
updatedFiles: string[];
17+
skippedFiles: string[];
1718
}
1819

1920
interface UpdateOperationState extends Partial<OperationState> {
@@ -39,7 +40,8 @@ export class Operation {
3940
newVersion: "",
4041
commitMessage: "",
4142
tagName: "",
42-
files: [],
43+
updatedFiles: [],
44+
skippedFiles: [],
4345
};
4446

4547
/**
@@ -55,7 +57,8 @@ export class Operation {
5557
newVersion: state.newVersion,
5658
commit: options.commit ? state.commitMessage : false,
5759
tag: options.tag ? state.tagName : false,
58-
files: state.files.slice(),
60+
updatedFiles: state.updatedFiles.slice(),
61+
skippedFiles: state.skippedFiles.slice(),
5962
};
6063
}
6164

@@ -86,21 +89,13 @@ export class Operation {
8689
/**
8790
* Updates the operation state and results, and reports the updated progress to the user.
8891
*/
89-
public update(state: UpdateOperationState): this {
90-
if (state.files) {
91-
// Concatenate the two `files` arrays, rather than overwriting
92-
state.files = this.state.files.concat(state.files);
93-
}
94-
92+
public update({ event, ...newState }: UpdateOperationState): this {
9593
// Update the operation state
96-
Object.assign(this.state, state);
94+
Object.assign(this.state, newState);
9795

98-
if (state.event && this._progress) {
96+
if (event && this._progress) {
9997
// Report the progress to the user
100-
this._progress({
101-
event: state.event,
102-
...this.results
103-
});
98+
this._progress({ event, ...this.results });
10499
}
105100

106101
return this;

src/types/version-bump-progress.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { VersionBumpResults } from "./version-bump-results";
55
*/
66
export const enum ProgressEvent {
77
FileUpdated = "file updated",
8+
FileSkipped = "file skipped",
89
GitCommit = "git commit",
910
GitTag = "git tag",
1011
GitPush = "git push",

src/types/version-bump-results.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export interface VersionBumpResults {
3434
tag: string | false;
3535

3636
/**
37-
* The files that were updated.
37+
* The files that were actually modified.
3838
*/
39-
files: string[];
39+
updatedFiles: string[];
40+
41+
/**
42+
* The files that were not updated because they did not contain the old version number.
43+
*/
44+
skippedFiles: string[];
4045
}

src/update-files.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ export async function updateFiles(operation: Operation): Promise<Operation> {
1616
if (modified) {
1717
operation.update({
1818
event: ProgressEvent.FileUpdated,
19-
files: [relPath],
19+
updatedFiles: operation.state.updatedFiles.concat(relPath),
20+
});
21+
}
22+
else {
23+
operation.update({
24+
event: ProgressEvent.FileSkipped,
25+
skippedFiles: operation.state.skippedFiles.concat(relPath),
2026
});
2127
}
2228
}

test/specs/api.spec.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe("versionBup() API", () => {
2626
newVersion: "2.34.567",
2727
commit: false,
2828
tag: false,
29-
files: ["package.json"],
29+
updatedFiles: ["package.json"],
30+
skippedFiles: [],
3031
});
3132

3233
// The package.json file should have been updated
@@ -51,7 +52,8 @@ describe("versionBup() API", () => {
5152
newVersion: "1.1.0",
5253
commit: false,
5354
tag: false,
54-
files: ["package.json"],
55+
updatedFiles: ["package.json"],
56+
skippedFiles: [],
5557
});
5658

5759
// The package.json file should have been updated
@@ -81,7 +83,7 @@ describe("versionBup() API", () => {
8183
files: [
8284
"random-file.json",
8385
"**/*.md",
84-
]
86+
],
8587
});
8688

8789
expect(results).to.deep.equal({
@@ -90,11 +92,12 @@ describe("versionBup() API", () => {
9092
newVersion: "1.1.0-test.1",
9193
commit: "A test of the upcoming v1.1.0-test.1",
9294
tag: "1.1.0-test.1",
93-
files: [
95+
updatedFiles: [
9496
"random-file.json",
9597
"README.md",
9698
"subdir/deep/changelog.md"
9799
],
100+
skippedFiles: [],
98101
});
99102

100103
// The CWD should not have changed

0 commit comments

Comments
 (0)