Skip to content

Commit 34561d5

Browse files
committed
Colored output / Output versions plugin / Error handling
1 parent f94b93d commit 34561d5

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build.gradle
2222

2323
```groovy
2424
plugins {
25-
id "com.github.ben-manes.versions" version "0.22.0"
25+
id "com.github.ben-manes.versions" version "0.24.0"
2626
}
2727
```
2828

index.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#! /usr/bin/env node
2+
var colors = require('colors');
3+
24
var argv = require('yargs')
35
.option('resolution', {
46
alias: 'r',
57
describe: 'Controls the dependency resolution strategy.\nSupported options:\n* release: selects the latest release\n* milestone: select the latest version being either a milestone or a release (default)\n* integration: selects the latest revision of the dependency module (such as SNAPSHOT)',
68
type: 'string',
79
nargs: 1,
810
demand: false
9-
}).argv
11+
})
12+
.option('no-color', {
13+
describe: 'Disables color output'
14+
})
15+
.argv
1016

1117
const prompts = require('prompts');
1218
const fs = require('fs');
@@ -26,6 +32,11 @@ try {
2632
} catch (err) {
2733
}
2834

35+
if (!fs.existsSync('build.gradle')) {
36+
console.log('build.gradle file was not found.'.red)
37+
return
38+
}
39+
2940
if (!gradleCommand) {
3041
const gradleVersion = spawnSync('gradle', ['--version'])
3142
if (gradleVersion.status === 0) {
@@ -34,11 +45,11 @@ if (!gradleCommand) {
3445
}
3546

3647
if (!gradleCommand) {
37-
console.log('Unable to find Gradle Wrapper or Gradle CLI.')
48+
console.log('Unable to find Gradle Wrapper or Gradle CLI.'.red)
3849
return
3950
}
4051

41-
console.log('Checking for upgrades')
52+
console.log('Checking for upgrades...')
4253

4354
const gduArgs = ['dependencyUpdates', '-DoutputFormatter=json', '-DoutputDir=build/dependencyUpdates']
4455
const gduResolution = argv.resolution
@@ -49,8 +60,28 @@ if (gduResolution) {
4960
const gdu = spawnSync(gradleCommand, gduArgs);
5061

5162
if (gdu.status !== 0) {
52-
console.log(`Error executing gradle dependency updates (StatusCode=${gdu.status}), have you installed the gradle versions plugin?`)
53-
console.log('https://github.com/ben-manes/gradle-versions-plugin')
63+
console.log(`Error executing gradle dependency updates (StatusCode=${gdu.status}), have you installed the gradle versions plugin?`.red)
64+
console.log('https://github.com/ben-manes/gradle-versions-plugin\n')
65+
console.log(`Plugins block`)
66+
console.log(`
67+
plugins {
68+
id "com.github.ben-manes.versions" version "0.24.0"
69+
}\n`.green)
70+
71+
console.log('buildscript block')
72+
73+
console.log(`
74+
apply plugin: "com.github.ben-manes.versions"
75+
76+
buildscript {
77+
repositories {
78+
jcenter()
79+
}
80+
81+
dependencies {
82+
classpath "com.github.ben-manes:gradle-versions-plugin:0.24.0"
83+
}
84+
}`.green)
5485
return
5586
}
5687

@@ -112,7 +143,7 @@ if (gdu.status !== 0) {
112143
})
113144

114145
fs.writeFile('build.gradle', buildFileAsString, 'utf8', function (err) {
115-
if (err) return console.log("Unable to write gradle build file.\n" + err);
146+
if (err) return console.log(`Unable to write gradle build file.\n${err}`.red);
116147
});
117148

118149
});

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test": "jest"
1717
},
1818
"dependencies": {
19+
"colors": "^1.3.3",
1920
"prompts": "^2.2.1",
2021
"yargs": "^14.0.0"
2122
},

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ [email protected]:
736736
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
737737
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
738738

739+
colors@^1.3.3:
740+
version "1.3.3"
741+
resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d"
742+
integrity sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==
743+
739744
combined-stream@^1.0.6, combined-stream@~1.0.6:
740745
version "1.0.8"
741746
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"

0 commit comments

Comments
 (0)