Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-caveman

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-caveman - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

75

index.js
'use strict';
var fs = require('fs'),
path = require('path');
var path = require('path');
var Caveman = require('caveman'),
glob = require('glob'),
Concat = require('concat-with-sourcemaps'),
gutil = require('gulp-util'),
through = require('through2');
module.exports = function (templates) {
var File = gutil.File;
module.exports = function () {
var concatenated, lastFile, latestMod;
return through.obj(function (file, enc, cb) {

@@ -23,5 +26,15 @@ if (file.isNull()) {

if (!latestMod || file.stat && file.stat.mtime > latestMod) {
lastFile = file;
latestMod = file.stat && file.stat.mtime;
}
var filename = path.basename(file.path, '.html');
if (!concatenated) {
concatenated = new Concat(false, filename, gutil.linefeed);
}
try {
file.contents = compileTemplates(file.contents, templates, cb);
this.push(file);
concatenated.add(file.relative, compileTemplate(filename, file.contents.toString(), cb));
} catch (err) {

@@ -32,40 +45,28 @@ this.emit('error', new gutil.PluginError('gulp-caveman', err, {fileName: file.path}));

cb();
});
};
}, function (cb) {
if (!lastFile || !concatenated) {
cb();
return;
}
function compileTemplates (contents, templates, cb) {
if (!templates) {
return contents;
}
var file = new File(lastFile);
if (typeof templates === 'string') {
templates = [templates];
}
file.contents = concatenated.content;
var templateCount = 0;
var compiled = templates.map(function (pattern) {
var templateFiles = glob.sync(pattern);
templateCount = templateCount + templateFiles.length;
this.push(file);
cb();
});
};
return templateFiles.reduce(function (previous, current) {
var name = path.basename(current, path.extname(current)),
template = '';
function compileTemplate (fileName, fileContents, cb) {
var template = '';
try {
let compiled = Caveman.compile(fs.readFileSync(current).toString());
template = `Caveman.register("${name}", function(Caveman, d) { ${compiled} });\n`;
} catch (err) {
cb(new gutil.PluginError('gulp-caveman', 'Error compiling Caveman template ' + name));
}
return previous + template;
}, '');
});
if (templateCount) {
let templateMsg = templateCount === 1 ? 'template saved.' : 'templates saved.'
gutil.log(templateCount, templateMsg);
try {
let compiled = Caveman.compile(fileContents);
template = `Caveman.register("${fileName}", function(Caveman, d) { ${compiled} });`;
} catch (err) {
cb(new gutil.PluginError('gulp-caveman', 'Error compiling Caveman template ' + fileName));
}
return new Buffer(compiled.join('') + contents.toString());
return new Buffer(template);
}
{
"name": "gulp-caveman",
"version": "1.0.0",
"version": "2.0.0",
"description": "Compile Caveman templates on the server-side using Gulp.",

@@ -40,3 +40,3 @@ "license": "MIT",

"caveman": "^0.1.4",
"glob": "^6.0.4",
"concat-with-sourcemaps": "^1.0.4",
"gulp-util": "^3.0.7",

@@ -43,0 +43,0 @@ "through2": "^2.0.0"

@@ -20,4 +20,4 @@ # gulp-caveman [![Build Status](https://travis-ci.org/webfella/gulp-caveman.svg?branch=master)](https://travis-ci.org/webfella/gulp-caveman)

gulp.task('default', function () {
return gulp.src('src/app.js')
.pipe(gulpCaveman('src/templates/*.html'))
return gulp.src('src/templates/*.html')
.pipe(gulpCaveman())
.pipe(gulp.dest('public'));

@@ -27,18 +27,4 @@ });

## API
### gulpCaveman(templates)
#### templates
Type: `String` or `Array`
Default: `''`
An array or string to the locations of your templates
```js
['path/to/first/template.html', 'path/to/second/*.html']
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc