Skip to content

Commit 8fb1fbc

Browse files
committed
fix: Fix appending the HTML extension to the target report file
* Use parse.name instead of basename to get the base file name. * Fix ignoreMissing for deprecated syntax; it didn't omit the source file. * Fix force to affect missing input files too.
1 parent c04eaa5 commit 8fb1fbc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tasks/grunt-html-html-report-converter.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function (grunt) {
1010
'Converts the JSON report of the grunt-html task to HTML.',
1111
function () {
1212
const data = this.data
13-
const input = data.input
13+
var input = data.input
1414
const output = data.output
1515
const options = this.options({
1616
targetExtension: '.html',
@@ -20,20 +20,24 @@ module.exports = function (grunt) {
2020
const targetExtension = options.targetExtension
2121
const ignoreMissing = options.ignoreMissing
2222
const force = options.force
23+
const warn = force ? grunt.log.warn : grunt.fail.warn
2324
var files = this.files
2425
var converted = 0
2526
var failed = 0
2627

2728
if (input && output) {
2829
grunt.log.warn('Properties "input" and "output" are deprecated. ' +
2930
'Use "src" and "dest" with the same content.')
31+
if (!fs.existsSync(input)) {
32+
input = null
33+
}
3034
files = [
3135
{
3236
orig: {
3337
src: input,
3438
dest: output
3539
},
36-
src: [input],
40+
src: input ? [input] : [],
3741
dest: output
3842
}
3943
]
@@ -49,12 +53,11 @@ module.exports = function (grunt) {
4953
} catch (error) {
5054
grunt.verbose.error(error.stack)
5155
grunt.log.error(error)
52-
const warn = force ? grunt.log.warn : grunt.fail.warn
5356
warn('Converting validation reports failed.')
5457
}
5558
} else {
5659
if (!ignoreMissing) {
57-
grunt.fail.warn('No files specified.')
60+
warn('No files specified.')
5861
}
5962
}
6063

@@ -64,8 +67,7 @@ module.exports = function (grunt) {
6467
src.forEach(convertFile.bind(null, file))
6568
} else {
6669
if (!ignoreMissing) {
67-
grunt.fail.warn('No files found at ' +
68-
chalk.cyan(file.orig.src) + '.')
70+
warn('No files found at ' + chalk.cyan(file.orig.src) + '.')
6971
}
7072
}
7173
}
@@ -77,8 +79,8 @@ module.exports = function (grunt) {
7779
if ((trailingChar === '/' || trailingChar === path.sep) &&
7880
!file.orig.expand) {
7981
dir = dest.substring(0, dest.length - 1)
80-
const parsed = path.basename(src)
81-
dest = path.join(dest, parsed + targetExtension)
82+
const parsed = path.parse(src)
83+
dest = path.join(dest, parsed.name + targetExtension)
8284
} else {
8385
dir = path.dirname(dest)
8486
}

0 commit comments

Comments
 (0)