Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Fixed issue with package incrementing not working
Browse files Browse the repository at this point in the history
  • Loading branch information
NetOpWibby committed Feb 23, 2020
1 parent 68aa5d2 commit 56f6045
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
38 changes: 16 additions & 22 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,21 @@ export default class ChronVer {
let versionChange = null;
let versionIncrement = null;

if (!incrementType) {
if (!incrementType || incrementType === "package") {
if (incrementType === "package") {
packageFile = appRoot.resolve("/package.json");
// https://stackoverflow.com/a/46190552
packageFileData = JSON.parse(readFileSync(packageFile).toString());
this.__original = packageFileData.version;

const { change, day, month, raw, year } = this.parse(packageFileData.version);

this.change = change;
this.day = day;
this.month = month;
this.year = year;
}

switch(true) {
// Supplied year is less than current year
// Supplied year is current but supplied month is less than current month
Expand All @@ -186,20 +200,6 @@ export default class ChronVer {
}
}

if (incrementType === "package") {
packageFile = appRoot.resolve("/package.json");
// https://stackoverflow.com/a/46190552
packageFileData = JSON.parse(readFileSync(packageFile).toString());
this.__original = packageFileData.version;

const { change, day, month, raw, year } = this.parse(packageFileData.version);

this.change = change;
this.day = day;
this.month = month;
this.year = year;
}

if (incrementType === "change") {
const { change, toIncrement } = processChange(this.version);

Expand Down Expand Up @@ -239,6 +239,7 @@ export default class ChronVer {
break;

case "change":
case "package":
if (typeof this.change === "number")
this.change++;
else {
Expand Down Expand Up @@ -266,13 +267,6 @@ export default class ChronVer {
this._format();

if (packageFile) {
if (this.__original === this.version) {
if (typeof this.change === "number")
this.change++;

this._format();
}

packageFileData.version = this.version;
// Update version in package.json and make it pretty
writeFileSync(packageFile, JSON.stringify(packageFileData, null, 2) + "\n");
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"url": "https://webb.page"
},
"bin": {
"chronver": "dist/bin/chronver.js"
"chronver": "./dist/bin/chronver.js"
},
"dependencies": {
"@webb/order-object": "^2020.2.2-1.1",
Expand All @@ -23,8 +23,8 @@
"updates": "^9.3.3"
},
"files": [
"dist/bin/chronver.js",
"dist/lib/index.js"
"./dist/bin/chronver.js",
"./dist/lib/index.js"
],
"homepage": "https://code.webb.page/ChronVer/chronver",
"husky": {
Expand All @@ -44,7 +44,7 @@
"versions"
],
"license": "MIT",
"main": "dist/lib/index.js",
"main": "./dist/lib/index.js",
"name": "chronver",
"prettier": "@webb/config-prettier",
"publishConfig": {
Expand All @@ -64,6 +64,6 @@
"test:typescript": "tsc",
"test:assert": "ts-node test/index.ts"
},
"types": "dist/lib/index.d.ts",
"version": "2020.02.21.1"
"types": "./dist/lib/index.d.ts",
"version": "2020.02.22"
}

0 comments on commit 56f6045

Please sign in to comment.