Skip to content

Commit 97283f1

Browse files
committed
initial commit 0.1.0
0 parents  commit 97283f1

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

LICENSE-MIT

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Patrick Kettner
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "grunt-stringifyjson",
3+
"description": "Uses JSON.stringify to minify JSON files (i.e. removing whitespace)",
4+
"version": "0.1.0",
5+
"author": {
6+
"name": "Nils Heuermann",
7+
"email": "[email protected]",
8+
"url": "http://www.world-of-scripts.de"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/oemmes/grunt-stringifyjson.git"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/oemmes/grunt-stringifyjson/issues"
16+
},
17+
"licenses": [
18+
{
19+
"type": "MIT",
20+
"url": "https://github.com/oemmes/grunt-stringifyjson/blob/master/LICENSE-MIT"
21+
}
22+
],
23+
"//main": "Gruntfile.js",
24+
"engines": {
25+
"node": ">= 0.8.0"
26+
},
27+
"devDependencies": {
28+
"grunt": "~0.4.1",
29+
"grunt-cli": "~0.1.7"
30+
},
31+
"peerDependencies": {
32+
"grunt": "~0.4.1"
33+
},
34+
"keywords": [
35+
"gruntplugin",
36+
"json",
37+
"minify",
38+
"stringify"
39+
]
40+
}

tasks/stringifyjson.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* grunt-stringifyjson
3+
*
4+
* Uses JSON.stringify to minify JSON files (i.e. removing whitespace)
5+
*
6+
* Copyright (c) 2014 Nils Heuermann
7+
* Licensed under the MIT license.
8+
*/
9+
10+
'use strict' ;
11+
12+
module.exports = function(grunt) {
13+
14+
grunt.registerMultiTask('stringifyjson', 'JSON.stringify wrapper for JSON files', function() {
15+
16+
// Stringify and output
17+
this.files.forEach(function(file) {
18+
// Concat the files array
19+
var jsonString = file.src.filter(function(fileSrc) {
20+
if (!grunt.file.exists(fileSrc)) {
21+
grunt.log.warn('JSON source file "' + fileSrc + '" not found.') ;
22+
return false ;
23+
} else {
24+
return true ;
25+
}
26+
}).map(function(fileSrc) {
27+
grunt.verbose.writeln('Processing ' + fileSrc) ;
28+
var json = grunt.file.readJSON(fileSrc) ;
29+
return JSON.stringify(json) ;
30+
}).join(grunt.util.normalizelf(', ')) ;
31+
32+
// write to the output file
33+
grunt.file.write(file.dest, jsonString) ;
34+
35+
// user feedback
36+
grunt.verbose.writeln('Stringified "' + file.dest + '".') ;
37+
38+
}) ;
39+
}) ;
40+
41+
} ;

0 commit comments

Comments
 (0)