-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "grunt-file-comment", | ||
"version": "1.0.0", | ||
"description": "Add Comments To Files.", | ||
"main": "tasks/file-comment.js", | ||
"name": "grunt-file-comment", | ||
"scripts": {}, | ||
"engines": { | ||
"node": ">= 8.9.4", | ||
"npm": ">= 5.6.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/xitedemon/grunt-file-comment.git" | ||
}, | ||
"keywords": [], | ||
"author": "xitedemon", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/xitedemon/grunt-file-comment/issues" | ||
}, | ||
"homepage": "https://github.com/xitedemon/grunt-file-comment#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = function (grunt) { | ||
'use strict'; | ||
var Path = require('path'); | ||
grunt.registerMultiTask('file-comment', 'add comments to file', function () { | ||
var options = this.options({ | ||
comments: ['autogenerated'], | ||
carriageReturn: "\n", | ||
prepend: true, | ||
syntaxes: { | ||
'*': '//', | ||
} | ||
}); | ||
if(!options.syntaxes['*']) | ||
options.syntaxes['*'] = '//'; | ||
|
||
var count = 0; | ||
|
||
var comment = '', content, extension, commentSyntax; | ||
this.files.forEach(function(el) { | ||
|
||
el.src.filter(function(filePath) { | ||
var witness = grunt.file.exists(filePath); | ||
if(!witness) | ||
grunt.log.warn('Source file "' + filePath + '" not found.'); | ||
|
||
return witness; | ||
}).map(function(filePath) { | ||
content = grunt.file.read(filePath); | ||
|
||
extension = Path.extname(filePath); | ||
commentSyntax = ( extension in options.syntaxes ? options.syntaxes[extension] : options.syntaxes['*'] ); | ||
|
||
|
||
comment = ''; | ||
for(var i = 0; i<options.comments.length; i++) { | ||
if(typeof commentSyntax === 'string') | ||
comment += commentSyntax + ' ' + options.comments[i] + options.carriageReturn; | ||
else | ||
comment += commentSyntax[0] + ' ' + options.comments[i] + (commentSyntax.length > 1 ? ' ' + commentSyntax[1] : '') + options.carriageReturn; | ||
} | ||
|
||
content = options.prepend ? comment + grunt.file.read(el.src[0]) : grunt.file.read(el.src[0]) + options.carriageReturn + comment; | ||
|
||
grunt.file.write(el.dest, content); | ||
grunt.log.debug('File "' + el.dest + '" edited.'); | ||
count++; | ||
}); | ||
|
||
}); | ||
grunt.log.ok(count + ' files edited'); | ||
}); | ||
}; |