gulp-hashify
Advanced tools
Comparing version 0.0.1 to 0.0.2
var through = require('through2'); | ||
var File = require('vinyl'); | ||
var gutil = require('gulp-util'); | ||
var PluginError = gutil.PluginError; | ||
function hashify (fileName) { | ||
function hashify (fileName, varName) { | ||
varName = varName || 'views'; | ||
if (!fileName) { | ||
throw new PluginError('gulp-hashify', 'Missing file option for gulp-hashify'); | ||
throw new PluginError('gulp-hashify', 'Missing fileName option for gulp-hashify'); | ||
} | ||
var views = {}; | ||
var hasViews = false; | ||
@@ -42,11 +47,6 @@ | ||
// Generate the views js file contents | ||
var jsScript = 'var views = ' + | ||
JSON.stringify(views) + | ||
';\nif (typeof module !== "undefined" && module.exports) { module.exports = views; }'; | ||
// Push the views js file into the stream | ||
this.push(new File({ | ||
path: fileName, | ||
contents: new Buffer(jsScript) | ||
contents: new Buffer(genScript(views, varName)) | ||
})); | ||
@@ -60,2 +60,11 @@ | ||
function genScript(views, varName) { | ||
var isProperty = ~varName.indexOf('.'); | ||
return (isProperty ? '' : 'var ') + | ||
varName + '=' + | ||
JSON.stringify(views) + | ||
';\nif (typeof module !== "undefined" && module.exports) { module.exports = views; }'; | ||
} | ||
module.exports = hashify; |
{ | ||
"name": "gulp-hashify", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A gulp plugin for turning a stream of files into a JavaScript object.", | ||
"main": "hashify.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -13,4 +13,13 @@ "author": "Chris Davies", | ||
"gulp": "^3.9.0", | ||
"through2": "^0.6.5" | ||
"jasmine-node": "^1.14.5", | ||
"mocha": "^2.2.5", | ||
"should": "^6.0.3", | ||
"stream-array": "^1.1.0", | ||
"stream-assert": "^2.0.2", | ||
"through2": "^0.6.5", | ||
"vinyl": "^0.4.6" | ||
}, | ||
"dependencies": { | ||
"gulp-util": "^3.0.5" | ||
} | ||
} |
# gulp-hashify | ||
A gulp plugin for turning a stream of files into a JavaScript object. | ||
A gulp plugin for turning a stream of files into a JavaScript object. | ||
## Installation | ||
``` | ||
npm install --save-dev gulp-hashify | ||
``` | ||
## Usage | ||
```javascript | ||
var hashify = require('gulp-hashify'); | ||
gulp.task('hashify', function () { | ||
return gulp.src('./src/views/**/*.html') | ||
.pipe(hashify('views.js')) | ||
.pipe(gulp.dest('./dist/js')); | ||
}); | ||
``` | ||
After running the `hashify` task, there will be a `./dist/js/views.js` file. Let's say that the | ||
`./src/views/` directory looked like this: | ||
``` | ||
/views | ||
/errors | ||
404.html | ||
500.html | ||
index.html | ||
users.html | ||
``` | ||
Then, `./dist/js/views.js` would end up looking like this: | ||
```javascript | ||
var views = { | ||
'errors/404': '<h1>Not found or whatever the content of /views/errors/404.html was</h1>', | ||
'errors/500': '<h1>Doh!</h1>', | ||
'index': 'The contents of /views/index.html', | ||
'users': 'The contents of /views/users.html' | ||
}; | ||
if (typeof module !== "undefined" && module.exports) { | ||
module.exports = views; | ||
} | ||
``` | ||
## Arguments | ||
The hashify function takes two arguments: | ||
- *fileName* = the name of the file to be output | ||
- *varName* = (optional) the name of the variable to be included in the output file. Defaults to views. If varName has a `.` in it, then it will not produce a variable declaration at all. | ||
### Example | ||
```javascript | ||
var hashify = require('gulp-hashify'); | ||
gulp.task('hashify', function () { | ||
return gulp.src('./src/views/**/*.html') | ||
.pipe(hashify('views.js', 'app.templates')) | ||
.pipe(gulp.dest('./dist/js')); | ||
}); | ||
``` | ||
Would produce a file that looked like this: | ||
```javascript | ||
app.templates = { | ||
'errors/404': '<h1>Not found or whatever the content of /views/errors/404.html was</h1>', | ||
'errors/500': '<h1>Doh!</h1>', | ||
'index': 'The contents of /views/index.html', | ||
'users': 'The contents of /views/users.html' | ||
}; | ||
if (typeof module !== "undefined" && module.exports) { | ||
module.exports = views; | ||
} | ||
``` | ||
--- | ||
## License MIT | ||
Copyright (c) 2015 Chris Davies | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
9141
10
172
2
94
1
8
1
+ Addedgulp-util@^3.0.5
+ Addedansi-gray@0.1.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedbeeper@1.1.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclone@1.0.4(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddateformat@2.2.0(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfancy-log@1.3.3(transitive)
+ Addedglogg@1.0.2(transitive)
+ Addedgulp-util@3.0.8(transitive)
+ Addedgulplog@1.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-gulplog@0.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.11.0.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basetostring@3.0.1(transitive)
+ Addedlodash._basevalues@3.0.0(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash._reescape@3.0.0(transitive)
+ Addedlodash._reevaluate@3.0.0(transitive)
+ Addedlodash._reinterpolate@3.0.0(transitive)
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash.escape@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.template@3.6.2(transitive)
+ Addedlodash.templatesettings@3.1.1(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmultipipe@0.1.2(transitive)
+ Addedobject-assign@3.0.0(transitive)
+ Addedparse-node-version@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@1.1.142.3.8(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsparkles@1.0.1(transitive)
+ Addedstring_decoder@0.10.311.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtime-stamp@1.1.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvinyl@0.5.3(transitive)
+ Addedxtend@4.0.2(transitive)