angular-tpl2js
Advanced tools
Comparing version 0.0.1 to 0.0.2
124
index.js
@@ -1,1 +0,123 @@ | ||
// like woah | ||
var async = require('async'); | ||
var engine = new TemplateEngine(); | ||
var fs = require('fs'); | ||
var minify = require('html-minifier').minify; | ||
var path = require('path'); | ||
function TemplateEngine() { | ||
var self = this; | ||
function readAsync(file, callback) { | ||
if (file) | ||
fs.readFile(file, 'utf8', callback); | ||
} | ||
self.source = { | ||
hash: function (raw, base) { | ||
var source = {contents: raw, templates: []}; | ||
var parts = source.contents.split(/(?=templateUrl)/g); | ||
parts.forEach(function (element, index) { | ||
var match = (element.match(/(?!,)templateUrl(.*)$/gm)); | ||
if (match) { | ||
var templateUrl = match[0].split(':')[1].split(',')[0].replace(/"/g, '').replace(/'/g, '').trim() | ||
var relative = path.resolve(__dirname + base, '../' + templateUrl); | ||
source.templates.push(relative); | ||
} | ||
}); | ||
return source; | ||
}, | ||
read: function (target) { | ||
var deferred = new Promise(function (resolve, reject) { | ||
fs.readFile(__dirname + target, 'utf8', function (err, data) { | ||
resolve(data); | ||
}); | ||
}); | ||
return deferred; | ||
} | ||
} | ||
self.templates = { | ||
get: function (source) { | ||
var deferred = new Promise(function (resolve, reject) { | ||
async.map(source.templates, readAsync, function (err, results) { | ||
results.forEach(function (element, index, arr) { | ||
source.templates[index] = minify(element, {collapseWhitespace: true, removeComments: true}) // minify the markup | ||
}); | ||
resolve(source); | ||
}); | ||
}); | ||
return deferred; | ||
}, | ||
set: function (transformed) { | ||
var deferred = new Promise(function (resolve, reject) { | ||
var parts = transformed.contents.split(/(?=templateUrl)(?!,)/g); | ||
parts.forEach(function (element, index, arr) { | ||
var match = (element.match(/(?!,)templateUrl(.*)$/gm)); | ||
if (match) | ||
arr[index] = arr[index].replace(/(?!,)templateUrl(.*),$/gm, 'template: \'' + transformed.templates.shift().replace(/'/g, "\\'") + '\',') | ||
}); | ||
resolve(parts.join('')); | ||
}); | ||
return deferred; | ||
} | ||
} | ||
} | ||
// TODO - solve pathing weirdness | ||
// TODO - refine poor regex check | ||
// TODO - identify passed options, likely relayed to html-minifier | ||
// TODO - identify failure points and return error through callbacks | ||
// TODO - recurse templating for ng-include support | ||
// TODO - travis ci | ||
// TODO - README | ||
function TemplateManager() { | ||
var self = this; | ||
self.inline = function (input, options, done) { // -- in | ||
if (options.gulp) { | ||
var base = '/' + path.dirname(path.relative(__dirname, options.target)); | ||
var source = engine.source.hash(input, base); | ||
engine.templates.get(source).then(function (transformed) { | ||
engine.templates.set(transformed).then(function (output) { | ||
done(output); // -- out | ||
}); | ||
}); | ||
} else { | ||
engine.source.read(input).then(function (data) { | ||
var base = path.dirname(input); | ||
var source = engine.source.hash(data, base); | ||
engine.templates.get(source).then(function (transformed) { | ||
engine.templates.set(transformed).then(function (output) { | ||
done(output); // -- out | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
module.exports = new TemplateManager(); | ||
module.exports.engine = engine; |
{ | ||
"name": "angular-tpl2js", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Convert Angular templates to inline JavaScript", | ||
@@ -17,3 +17,7 @@ "files": [ | ||
"mocha": "^2.4.5" | ||
}, | ||
"dependencies": { | ||
"async": "^1.5.2", | ||
"html-minifier": "^1.2.0" | ||
} | ||
} |
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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
5554
92
0
2
1
+ Addedasync@^1.5.2
+ Addedhtml-minifier@^1.2.0
+ Addedalign-text@0.1.4(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedasync@0.2.101.5.2(transitive)
+ Addedcamel-case@1.2.2(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedchange-case@2.3.1(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedcommander@2.8.12.9.0(transitive)
+ Addedconcat-stream@1.5.2(transitive)
+ Addedconstant-case@1.1.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddot-case@1.1.2(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedhe@1.0.0(transitive)
+ Addedhtml-minifier@1.5.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-lower-case@1.1.3(transitive)
+ Addedis-upper-case@1.1.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedlower-case-first@1.0.2(transitive)
+ Addedncname@1.0.0(transitive)
+ Addedparam-case@1.1.2(transitive)
+ Addedpascal-case@1.1.2(transitive)
+ Addedpath-case@1.1.2(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrelateurl@0.2.7(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedsentence-case@1.1.3(transitive)
+ Addedsnake-case@1.1.2(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedswap-case@1.1.2(transitive)
+ Addedtitle-case@1.1.2(transitive)
+ Addedtypedarray@0.0.7(transitive)
+ Addeduglify-js@2.6.4(transitive)
+ Addeduglify-to-browserify@1.0.2(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedupper-case-first@1.1.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwindow-size@0.1.0(transitive)
+ Addedwordwrap@0.0.2(transitive)
+ Addedxml-char-classes@1.0.0(transitive)
+ Addedyargs@3.10.0(transitive)