vulcan.process(options.targetUrl || src[0], function(err, inlinedHtml) { if (err) { return grunt.fatal(err); } if (options.csp) { var crisper = require('crisper'); var cspPath = path.resolve(path.dirname(f.dest), options.csp); var out = crisper.split(inlinedHtml, options.csp); inlinedHtml = out.html; grunt.file.write(cspPath, out.js); grunt.log.ok(src[0] + " -> " + cspPath); } grunt.file.write(f.dest, inlinedHtml); grunt.log.ok(src[0] + " -> " + f.dest); filesCount--; if (filesCount <= 0) { done(); } });
return through.obj(function (file, enc, cb) { opts.jsFileName = currentjsFileName || path.basename(file.path, '.html') + '.js'; if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { cb(new gutil.PluginError('gulp-crisper', 'Streaming not supported')); return; } try { var obj = crisper.split(file.contents.toString(), opts.jsFileName); if (typeof obj.html === 'string' && typeof file.path === 'string') { this.push(new gutil.File({ cwd: file.cwd, base: path.dirname(file.path), path: file.path, contents: new Buffer(obj.html) })); this.push(new gutil.File({ cwd: file.cwd, base: path.dirname(file.path), path: path.join(path.dirname(file.path), opts.jsFileName), contents: new Buffer(obj.js) })); cb(); } else { cb(new gutil.PluginError('gulp-crisper', 'Unexpected output')); } } catch (err) { cb(new gutil.PluginError('gulp-crisper', err, {fileName: file.path})); } });