grunt-yate
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -41,3 +41,6 @@ /* | ||
autorun: true, | ||
externals: 'test/fixtures/externals.js' | ||
runtime: true, | ||
externals: [ | ||
'test/fixtures/externals.js' | ||
] | ||
}, | ||
@@ -44,0 +47,0 @@ files: { |
{ | ||
"name": "grunt-yate", | ||
"description": "Yate compiler plugin", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"homepage": "https://github.com/lapple/grunt-yate", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -53,2 +53,8 @@ # grunt-yate | ||
#### options.externals | ||
Type: `String|Array` | ||
File pattern or array of patterns to load external functions from. Functions should be | ||
defined in `yr.externals` namespace. | ||
#### options.postprocess | ||
@@ -55,0 +61,0 @@ Type: `Function` |
@@ -18,2 +18,4 @@ /* | ||
var async = grunt.util.async; | ||
grunt.registerMultiTask('yate', 'Yate compiler plugin', function() { | ||
@@ -37,3 +39,3 @@ | ||
// Iterate over all specified file groups. | ||
this.files.forEach(function(f) { | ||
async.forEachSeries(this.files, function(f, next) { | ||
@@ -54,34 +56,36 @@ // Building compiled templates. | ||
return yate.compile(filepath).js; | ||
}).join('\n'); | ||
}).join(grunt.util.linefeed); | ||
// Building a list of files to prepend to the compiled template. | ||
var includes = grunt.file.expand(options.externals); | ||
// It is important to prepend externals with runtime. | ||
if (options.runtime) { | ||
src = runtime(src); | ||
includes.unshift(path.join(yateFolder, 'runtime.js')); | ||
} | ||
// It is important to append externals after runtime. | ||
src = externals(src, options.externals); | ||
async.map(includes, readFile, function(err, scripts) { | ||
if (err) { | ||
grunt.log.warn(err); | ||
return next(false); | ||
} | ||
if (options.autorun) { | ||
src = autorun(src, options.autorun); | ||
} | ||
src = scripts.join(grunt.util.linefeed) + grunt.util.linefeed + src; | ||
src = options.postprocess(src); | ||
if (options.autorun) { | ||
src = autorun(src, options.autorun); | ||
} | ||
// Write the destination file. | ||
grunt.file.write(f.dest, src); | ||
src = options.postprocess(src); | ||
// Print a success message. | ||
grunt.log.writeln('File ' + f.dest.cyan + ' created.'); | ||
}); | ||
}); | ||
// Write the destination file. | ||
grunt.file.write(f.dest, src); | ||
function externals(code, externals) { | ||
return [code].concat(grunt.file.expand(externals).map(function(path) { | ||
return grunt.file.read(path); | ||
})).join(grunt.util.linefeed); | ||
} | ||
// Print a success message. | ||
grunt.log.writeln('File ' + f.dest.cyan + ' created.'); | ||
next(); | ||
}); | ||
function runtime(code) { | ||
return grunt.file.read(path.join(yateFolder, 'runtime.js')) + '\n' + code; | ||
} | ||
}, this.async()); | ||
}); | ||
@@ -91,9 +95,13 @@ function autorun(code, module) { | ||
return iife(code + '\nreturn function(data) { return yr.run("' + main + '", data); };'); | ||
return iife(code + grunt.util.linefeed + 'return function(data) { return yr.run("' + main + '", data); };'); | ||
} | ||
function iife(code) { | ||
return '(function(){\n' + code + '\n})()\n'; | ||
return '(function(){' + grunt.util.linefeed + code + grunt.util.linefeed + '})()' + grunt.util.linefeed; | ||
} | ||
function readFile(path, callback) { | ||
return require('fs').readFile(path, { encoding: 'utf8' }, callback); | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13970
299
122
1