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

handlebar-rider

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebar-rider - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

143

lib/handlebar-rider.js

@@ -1,19 +0,12 @@

// handlebar rider
optimist = require('optimist')
handlebars = require('handlebars');
uglify = require('uglify-js');
fs = require('fs');
var optimist = require('optimist')
, handlebars = require('handlebars')
, uglify = require('uglify-js')
, fs = require('fs')
, scli = require('supercli')
, __ = require('underscore')
, watch = require('watch')
;
(function(){
//colored output
var color = {
red : '\u001b[31m',
blue: '\u001b[36m',
green: '\u001b[32m',
yellow: '\u001b[33m',
reset: '\u001b[0m'
}

@@ -24,7 +17,10 @@ //options and helper functions scoped globally in simple namespaced object

in: './app/handlebars/',
out: './public/javascript/templates.js',
out: './public/javascript/templates.js',
templates: [],
ext : ["hb","hbs","handlebars","template","templates","tpl","item","part","prt","pt"],
minify: true
}
};
scli.config.appName("Handlebar-Rider");

@@ -37,2 +33,4 @@ // recursively reads in directory and namespaces template and partial objects

try {
// read the directory

@@ -74,4 +72,43 @@ fs.readdir(dir, function(err, list) {

});
} catch(err) {
scli.error(err);
}
};
var setupWatchTree = function(dir) {
watch.watchTree(rider.in, function (f, curr, prev) {
if (typeof f == "object" && prev === null && curr === null) {
// Finished walking the tree
} else if (prev === null) {
// f is a new file
} else if (curr.nlink === 0) {
// f was removed
} else {
// f was changed
}
}, function () {
});
};
var setupWatchMonitor = function(dir) {
watch.createMonitor(dir, function (monitor) {
monitor.on("created", function (f, stat) {
// Handle file changes
scli.log("Watcher detected change: created");
fileHasChanged();
});
monitor.on("changed", function (f, curr, prev) {
// Handle new files
scli.log("Watcher detected change: changed");
fileHasChanged();
});
monitor.on("removed", function (f, stat) {
// Handle removed files
scli.log("Watcher detected change: removed");
fileHasChanged();
});
});
};

@@ -82,3 +119,3 @@

console.log(color.blue + '[handlebar-rider] change detected to file, recompiling' + color.reset);
scli.log("Change detected to file '" + filename + "'");
compileTemplates();

@@ -92,3 +129,3 @@

console.log(color.blue + '[handlebar-rider] new or removed file detected, recompiling' + color.reset);
scli.log('New or removed file "' + filename + '" detected, recompiling');
readAndCompile(rider.in, rider.watch);

@@ -106,6 +143,15 @@

}
var precompile = function(data) {
if( data == data || "" )
return "";
else
return handlebars.precompile( data, {});
};
//compiles to output destination
var compileTemplates = function(){
scli.log("Compiling templates now!");
var processedFiles = [];
var errors = false;
try {

@@ -119,3 +165,3 @@

for(var t = 0; t < rider.templates.length; t++){
processedFiles.push(rider.templates[t].namespace);
data = fs.readFileSync(rider.templates[t].file, 'utf8');

@@ -130,11 +176,11 @@

compiled = 'templates[\'' + rider.templates[t].namespace.replace(/\/_/,'_') + '\'] = template(' + handlebars.precompile(data, {}) + ');\n'
compiled = 'templates[\'' + rider.templates[t].namespace.replace(/\/_/,'_') + '\'] = template(' + precompile(data) + ');\n'
} else if( rider.templates[t].namespace.indexOf('partial') != 0 ) {
compiled = 'templates[\'' + rider.templates[t].namespace + '\'] = template(' + handlebars.precompile(data, {}) + ');\n'
compiled = 'templates[\'' + rider.templates[t].namespace + '\'] = template(' + precompile(data) + ');\n'
} else {
compiled = 'templates[\'' + rider.templates[t].namespace.replace(/partials\//,'') + '\'] = template(' + handlebars.precompile(data, {}) + ');\n'
compiled = 'templates[\'' + rider.templates[t].namespace.replace(/partials\//,'') + '\'] = template(' + precompile(data) + ');\n'

@@ -147,6 +193,10 @@ }

} catch(e) {
console.log(color.red + '[handlebar-rider] warning - deleted or now missing file ' + color.reset);
var filename = processedFiles.pop();
errors = true;
scli.error('Compile Failure while processing "' + filename + '"');
}
if(errors) {
return false;
}

@@ -170,8 +220,6 @@ //complete output array to single string

fs.writeFileSync(rider.out, output, 'utf8');
console.log(color.green + '[handlebar-rider] compiled template directory ' + rider.in + ' to ' + rider.out + color.reset);
scli.ok('Compiled ' + processedFiles.length + ' templates in "' + rider.in + '" to "' + rider.out + '"');
} catch(e){
console.log(color.red + '[handlebar-rider] ERROR! destination file or directory does not exist.' + color.reset + '\n:' + e);
scli.error('ERROR! destination file or directory does not exist.', e);
}

@@ -192,2 +240,8 @@

// sort filenames to preserve ordering in generated files (so that re-running the script does not produce different md5 sigature)
files = files || "";
if(__.size(files) <= 0 ) {
scli.error('There are no files for Handlebar-Rider to compile. Did you run the command correctly?');
return false;
}
files.sort();

@@ -198,3 +252,3 @@

if(err)
throw new Error('directory does not exists: ' + dir)
throw new Error('directory does not exist: ' + dir)

@@ -207,3 +261,3 @@ for(var f = 0; f < files.length; f++){

if( info[0] == 'file' && (info[1].indexOf('.hb') > 0 || info[1].indexOf('.handlebars') > 0) ){
/*
// watch the file

@@ -214,2 +268,3 @@ if(watch) {

}
*/

@@ -229,3 +284,3 @@ // get the template namespace by using the extra directory

} else if ( info[0] == 'directory') {
/*
// watch the directory for new / removed files

@@ -237,3 +292,3 @@ if(watch){

}
*/
}

@@ -247,7 +302,7 @@

console.log(color.red + '[handlebar-rider] ERROR! check to be sure your directories exist. ' + color.reset + "\n" + e + "\n");
console.log('[handlebar-rider] input directory: ' + dir);
console.log('[handlebar-rider] destination file: ' + rider.out + "\n");
scli.error('ERROR! check to be sure your directories exist. ', e );
scli.log('input directory: ' + dir);
scli.log('destination file: ' + rider.out);
if(rider.help)
console.log(rider.help)
scli.log(rider.help)

@@ -288,5 +343,7 @@ }

if(rider.watch)
console.log(color.yellow + '[handlebar-rider] watching template directory ' + dir + color.reset);
if(rider.watch) {
scli.warn('Watching template directory "' + dir + '"');
setupWatchTree(dir);
setupWatchMonitor(dir);
}
readAndCompile(dir, rider.watch);

@@ -300,3 +357,3 @@

console.log(color.yellow + '[handlebar-rider] watching template directory ' + rider.in + color.reset);
scli.warn('Watching template directory "' + rider.in + '"');
rider.watch = true;

@@ -303,0 +360,0 @@ readAndCompile(rider.in, true);

@@ -5,3 +5,3 @@ {

"description" : "Compiles/watches a directory of handlebar templates files and precompiles into single js output file",
"version" : "0.1.11",
"version" : "0.1.12",

@@ -29,4 +29,5 @@ "repository" : {

"uglify-js" : "1.1.1",
"optimist" : ">= 0.3.4"
"optimist" : ">= 0.3.4",
"supercli" : "*"
}
}

Sorry, the diff of this file is not supported yet

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