Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit ca54934

Browse files
Rewrite package json bumper
1 parent be3fbab commit ca54934

File tree

6 files changed

+41
-49
lines changed

6 files changed

+41
-49
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"extends": "eslint:recommended",
77
"parserOptions": {
8-
"ecmaVersion": 6,
8+
"ecmaVersion": 2017,
99
"ecmaFeatures": {
1010
"impliedStrict": true
1111
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"author": "Fagner Brack",
1111
"license": "MIT",
1212
"scripts": {
13-
"test": "eslint *.js \"src/**/*.js\" \"test/**/*.js\" && mocha --trace-warnings",
14-
"test:watch": "eslint \"src/**/*.js\" \"test/**/*.js\" && mocha -w",
13+
"lint": "eslint *.js \"src/**/*.js\" \"test/**/*.js\"",
14+
"test": "mocha --trace-warnings",
15+
"test:watch": "mocha -w",
1516
"release:test": "node release.js fake patch",
1617
"release": "node release.js patch"
1718
},
@@ -27,7 +28,6 @@
2728
"dependencies": {
2829
"app-root-path": "2.0.1",
2930
"bluebird": "3.5.1",
30-
"json-update": "3.0.0",
3131
"nodegit": "0.20.2"
3232
},
3333
"engines": {

release.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Promise = require("bluebird");
22
const Git = require("nodegit");
33

4-
const bumpJSONFiles = require("./src/file/bump-json-files");
4+
const bumpPackageJSON = require("./src/file/bump-package-json");
55
const gitCommit = require("./src/git/git-commit");
66
const gitTag = require("./src/git/git-tag");
77
const gitPushTag = require("./src/git/git-push-tag");
@@ -28,7 +28,7 @@ let localRepo;
2828
Promise.try(() => {
2929
console.log("Bumping package.json...");
3030
if (!isFakeRun) {
31-
return bumpJSONFiles(targetBumpSpec, ["package.json"]);
31+
return bumpPackageJSON(targetBumpSpec, "package.json");
3232
}
3333
}).then(() => {
3434
return Git.Repository.discover(".", 0, ".");

src/file/bump-json-files.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/file/bump-package-json.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const root = require("app-root-path");
2+
const writeFile = require("util").promisify(require("fs").writeFile);
3+
const readFile = require("util").promisify(require("fs").readFile);
4+
5+
const bumpVersion = require(root + "/src/bump-version");
6+
7+
module.exports = async (bumpSpec, filePath) => {
8+
const fileContentAsJSON = JSON.parse(await readFile(filePath, "UTF-8"));
9+
fileContentAsJSON.version = bumpVersion(fileContentAsJSON.version, bumpSpec);
10+
await writeFile(filePath, JSON.stringify(fileContentAsJSON));
11+
};

test/file/bump-json-files.spec.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
const root = require("app-root-path");
21
const expect = require("chai").expect;
3-
const Promise = require("bluebird");
4-
const loadJSON = Promise.promisify(require("json-update").load);
2+
const readFile = require("util").promisify(require("fs").readFile);
3+
const writeFile = require("util").promisify(require("fs").writeFile);
4+
const unlink = require("util").promisify(require("fs").unlink);
55

6-
const bumpJSONFiles = require(root + "/src/file/bump-json-files");
7-
const createFileSync = require(root + "/test/dummy-data/create-file-sync");
6+
const bumpPackageJSON = require(require("app-root-path") + "/src/file/bump-package-json");
87

9-
describe("bump-json-files", function() {
8+
describe("Bump Package JSON", () => {
109

11-
describe("Given a dummy file in JSON format", function() {
12-
const targetFilename = "bump-minor.json";
13-
let removeDummyJSONFileSync;
10+
it("bumps the patch version in the package.json", async () => {
11+
await writeFile("target-package.json", "{\"version\":\"0.0.0\"}");
12+
await bumpPackageJSON("patch", "target-package.json");
13+
const targetFileContent = await readFile("target-package.json", "UTF-8");
14+
expect(targetFileContent).to.equal("{\"version\":\"0.0.1\"}");
15+
await unlink("target-package.json");
1416

15-
beforeEach(function() {
16-
removeDummyJSONFileSync = createFileSync(targetFilename, JSON.stringify({
17-
version: "0.0.0"
18-
}));
19-
});
20-
21-
afterEach(function() {
22-
removeDummyJSONFileSync();
23-
});
17+
await writeFile("another-target-package.json", "{\"version\":\"0.0.0\"}");
18+
await bumpPackageJSON("patch", "another-target-package.json");
19+
const anotherTargetFileContent = await readFile("another-target-package.json", "UTF-8");
20+
expect(anotherTargetFileContent).to.equal("{\"version\":\"0.0.1\"}");
21+
await unlink("another-target-package.json");
22+
});
2423

25-
it("should bump the 'minor' version attribute", function() {
26-
return bumpJSONFiles("minor", [targetFilename]).then(function() {
27-
return loadJSON(targetFilename);
28-
}).then(function(targetFile) {
29-
expect(targetFile).to.have.property("version", "0.1.0");
30-
});
31-
});
24+
it("keeps existing properties intact", async () => {
25+
await writeFile("target-package.json", "{\"existing\":1,\"version\":\"0.0.0\"}");
26+
await bumpPackageJSON("patch", "target-package.json");
27+
const bumpedFile = await readFile("target-package.json", "UTF-8");
28+
expect(bumpedFile).to.equal("{\"existing\":1,\"version\":\"0.0.1\"}");
29+
await unlink("target-package.json");
3230
});
31+
3332
});

0 commit comments

Comments
 (0)