Skip to content

Commit 98277d9

Browse files
authored
Fix: error for missing package.json, warning for different version (#5)
* Fix: add new version of tagged-git-commits * Chore: update dependencies * Test: update tests * Test: update test * Style: remove console.log * Refactor: update console.warn * Fix: add error for missing package.json
1 parent b410aac commit 98277d9

File tree

5 files changed

+53
-13
lines changed

5 files changed

+53
-13
lines changed

lib/cli.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env node
22

3+
import chalk from 'chalk';
34
import inquirer from 'inquirer';
45
import isAdded from 'is-git-added';
56
import isGit from 'is-git-repository';
67
import getGitRemotes from 'get-git-remotes';
78
import getCommitRange from 'git-commit-range';
8-
import taggedCommits from 'tagged-git-commit';
9+
import taggedCommits from 'tagged-git-commits';
910
import updateNotifier from 'update-notifier';
1011
import yargs from 'yargs';
1112

@@ -28,20 +29,22 @@ updateNotifier({ pkg }).notify();
2829
const cli = () => {
2930
const cwd = process.cwd();
3031
const latestTaggedCommits = taggedCommits({ path: cwd });
31-
const latestTaggedCommit = latestTaggedCommits.length === 0 ? '' : latestTaggedCommits[0];
32+
const latestTaggedCommit = latestTaggedCommits.length === 0 ? '' : latestTaggedCommits[0].commit;
3233
const commits = getCommitRange({ path: cwd, from: latestTaggedCommit });
3334
const latestVersion = getLatestVersion();
3435
const newVersions = generateVersions(latestVersion);
3536
const questionsList = questions(newVersions);
3637

3738
if (!isGit(cwd)) {
38-
return console.warn('Error: this is not a git repository... make sure you are in the right directory');
39+
return console.warn(chalk.red('Error: this is not a git repository... make sure you are in the right directory'));
3940
} else if (!isAdded(cwd) && commits.length === 0) {
40-
return console.warn('Error: no changes... try to git add <files>');
41+
return console.warn(chalk.red('Error: no changes... try to git add <files>'));
4142
} else if (commits.length === 0) {
42-
return console.warn('Error: no commits yet... try to git commit -m <message>');
43+
return console.warn(chalk.red('Error: no commits yet... try to git commit -m <message>'));
4344
} else if (!getGitRemotes(cwd)) {
44-
return console.warn('Error: it seems you do not have a remote repository set... try to git remote add origin <remote-url>');
45+
return console.warn(chalk.red('Error: it seems you do not have a remote repository set... try to git remote add origin <remote-url>'));
46+
} else if (latestVersion === '') {
47+
return console.warn(chalk.red('Error: it seems you do not have a package.json... try npm init'));
4548
}
4649

4750
return inquirer

lib/helpers/getLatestVersion.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import taggedCommits from 'tagged-git-commit';
1+
import chalk from 'chalk';
2+
import taggedCommits from 'tagged-git-commits';
23
import path from 'path';
34
import fs from 'fs-extra';
45

@@ -18,7 +19,7 @@ const getLatestVersion = () => {
1819
let latestTaggedVersion;
1920

2021
if (latestTag[0]) {
21-
latestTaggedVersion = latestTag[0].split('refs/tags/')[1];
22+
latestTaggedVersion = latestTag[0].commit;
2223
} else {
2324
latestTaggedVersion = undefined;
2425
}
@@ -29,7 +30,12 @@ const getLatestVersion = () => {
2930
} else if (`v${latestPkgVersion}` === `${latestTaggedVersion}`) {
3031
latestVersion = `v${latestPkgVersion}`;
3132
} else {
32-
latestVersion = '';
33+
console.warn(
34+
chalk.yellow('WARNING: the versions from package.json and the latest tag differ...\n'),
35+
chalk.yellow('if you increase the version with `sgr`, it will write all commits since the last tag into the new version..\n'),
36+
chalk.yellow('you might consider tagging your last verion before using `sgr`...\n'),
37+
);
38+
latestVersion = `v${latestPkgVersion}`;
3339
}
3440

3541
return latestVersion;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"nyc": "^10.1.2"
6767
},
6868
"dependencies": {
69+
"chalk": "^2.0.1",
6970
"execa": "^0.6.3",
7071
"fs-extra": "^3.0.1",
7172
"get-git-remotes": "^1.0.1",
@@ -78,7 +79,7 @@
7879
"listr": "^0.12.0",
7980
"moment": "^2.18.1",
8081
"semver": "^5.3.0",
81-
"tagged-git-commit": "^1.0.0",
82+
"tagged-git-commits": "^1.0.0",
8283
"update-notifier": "^2.1.0",
8384
"yargs": "^8.0.1"
8485
}

test/lib-helpers/getLatestVersion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test.serial('LATEST VERSION | tagged version !== package.json version', async (t
3737

3838
const latestVersion = await getLatestVersion();
3939

40-
t.is(latestVersion, '');
40+
t.is(latestVersion, 'v0.0.1');
4141

4242
await fs.unlinkSync(path.join(cwd, 'package.json'));
4343

yarn.lock

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ ansi-styles@^2.2.1:
103103
version "2.2.1"
104104
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
105105

106+
ansi-styles@^3.1.0:
107+
version "3.1.0"
108+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.1.0.tgz#09c202d5c917ec23188caa5c9cb9179cd9547750"
109+
dependencies:
110+
color-convert "^1.0.0"
111+
106112
ansi-styles@~1.0.0:
107113
version "1.0.0"
108114
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178"
@@ -992,6 +998,14 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
992998
strip-ansi "^3.0.0"
993999
supports-color "^2.0.0"
9941000

1001+
chalk@^2.0.1:
1002+
version "2.0.1"
1003+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.0.1.tgz#dbec49436d2ae15f536114e76d14656cdbc0f44d"
1004+
dependencies:
1005+
ansi-styles "^3.1.0"
1006+
escape-string-regexp "^1.0.5"
1007+
supports-color "^4.0.0"
1008+
9951009
chokidar@^1.4.2, chokidar@^1.6.1:
9961010
version "1.7.0"
9971011
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@@ -1094,6 +1108,16 @@ code-point-at@^1.0.0:
10941108
version "1.1.0"
10951109
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
10961110

1111+
color-convert@^1.0.0:
1112+
version "1.9.0"
1113+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a"
1114+
dependencies:
1115+
color-name "^1.1.1"
1116+
1117+
color-name@^1.1.1:
1118+
version "1.1.2"
1119+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.2.tgz#5c8ab72b64bd2215d617ae9559ebb148475cf98d"
1120+
10971121
combined-stream@^1.0.5, combined-stream@~1.0.5:
10981122
version "1.0.5"
10991123
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
@@ -3894,6 +3918,12 @@ supports-color@^3.1.2:
38943918
dependencies:
38953919
has-flag "^1.0.0"
38963920

3921+
supports-color@^4.0.0:
3922+
version "4.1.0"
3923+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.1.0.tgz#92cc14bb3dad8928ca5656c33e19a19f20af5c7a"
3924+
dependencies:
3925+
has-flag "^2.0.0"
3926+
38973927
symbol-observable@^0.2.2:
38983928
version "0.2.4"
38993929
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-0.2.4.tgz#95a83db26186d6af7e7a18dbd9760a2f86d08f40"
@@ -3913,9 +3943,9 @@ table@^3.7.8:
39133943
slice-ansi "0.0.4"
39143944
string-width "^2.0.0"
39153945

3916-
tagged-git-commit@^1.0.0:
3946+
tagged-git-commits@^1.0.0:
39173947
version "1.0.0"
3918-
resolved "https://registry.yarnpkg.com/tagged-git-commit/-/tagged-git-commit-1.0.0.tgz#01512638d0addc34364fa263329cec37f6cc8204"
3948+
resolved "https://registry.yarnpkg.com/tagged-git-commits/-/tagged-git-commits-1.0.0.tgz#481f2e13296d0ade56fa827d000fe66374694ab6"
39193949
dependencies:
39203950
execa "^0.6.1"
39213951
fs-extra "^3.0.1"

0 commit comments

Comments
 (0)