Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions bin/npm-html2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ var args = process.argv.slice(2);

var templateModule = fs.readFileSync(path.join(__dirname, './../tmpl/templateModule.tmpl'), 'utf-8');
var templateCache = fs.readFileSync(path.join(__dirname, './../tmpl/templateCache.tmpl'), 'utf-8');
var usage = fs.readFileSync(path.join(__dirname, './../tmpl/usage.md')).toString()
var usage = fs.readFileSync(path.join(__dirname, './../tmpl/usage.md')).toString();

var opts = {};
opts.extension = 'html';
opts.tplPath = '**/*.tpl.'
opts.moduleName = 'app.template'
opts.tplPath = '**/*.tpl.';
opts.moduleName = 'app.template';

var arg;
while (args.length) {
Expand All @@ -27,38 +27,53 @@ while (args.length) {
break;
case '-i':
case '--input':
opts.tplPath = args.shift()
opts.tplPath = args.shift();
break;
case '-o':
case '--output':
opts.filename = args.shift()
opts.filename = args.shift();
break;
case '-e':
case '--exclude':
opts.exclude = args.shift()
opts.exclude = args.shift();
break;
case '-m':
case '--module':
opts.moduleName = args.shift()
opts.moduleName = args.shift();
break;
case '-b':
case '--base':
opts.basePath = args.shift()
opts.basePath = args.shift();
break;
case '-q':
case '--quotes':
opts.quotes = true
opts.quotes = true;
break;
case '--minify':
opts.minify = true
opts.minify = true;
break;
case '--collapseBooleanAttributes':
opts.collapseBooleanAttributes = (args.shift() !== 'false');
break;
case '--collapseWhitespace':
opts.collapseWhitespace = (args.shift() !== 'false');
break;
case '--conservativeCollapse':
opts.conservativeCollapse = (args.shift() !== 'false');
break;
case '--removeComments':
opts.removeComments = (args.shift() !== 'false');
break;
case '--minifyInlineCss':
opts.minifyInlineCss = (args.shift() !== 'false');
break;
default:
break;
}
}

opts.output = (opts.filename) ? path.join(process.cwd(), opts.filename) : null
opts.output = (opts.filename) ? path.join(process.cwd(), opts.filename) : null;

opts.tplPath = (opts.tplPath === '**/*.tpl.') ? opts.tplPath + opts.extension : opts.tplPath;

html2js(opts)
html2js(opts);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"chai": "^1.10.0",
"combined-stream": "0.0.7",
"glob": "^4.3.2",
"htmlmin": "0.0.4",
"html-minifier": "3.2.3",
"jade": "^1.8.2",
"through2": "^0.6.3"
},
Expand Down
17 changes: 12 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var glob = require('glob')
var jade = require('jade');
var path = require('path');
var util = require('util');
var htmlmin = require('htmlmin');
var htmlminify = require('html-minifier').minify;

var templateModule = fs.readFileSync(path.join(__dirname, './../tmpl/templateModule.tmpl'), 'utf-8');
var templateCache = fs.readFileSync(path.join(__dirname, './../tmpl/templateCache.tmpl'), 'utf-8');
Expand All @@ -21,6 +21,11 @@ module.exports = function (opts, callback) {
var quotes = opts.quotes;
var exclude = opts.exclude || '';
var minify = opts.minify;
var collapseBooleanAttributes = opts.collapseBooleanAttributes !== undefined ? opts.collapseBooleanAttributes : true;
var collapseWhitespace = opts.collapseWhitespace !== undefined ? opts.collapseWhitespace : true;
var conservativeCollapse = opts.conservativeCollapse !== undefined ? opts.conservativeCollapse : false;
var removeComments = opts.removeComments !== undefined ? opts.removeComments : true;
var minifyInlineCss = opts.minifyInlineCss !== undefined ? opts.minifyInlineCss : true;

function processFileData(route, html) {

Expand All @@ -29,10 +34,12 @@ module.exports = function (opts, callback) {
if (route.indexOf('.jade') !== -1)
html = jade.render(html, {pretty: true});
if (minify)
html = htmlmin(html, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeComments: true
html = htmlminify(html, {
collapseBooleanAttributes: collapseBooleanAttributes,
collapseWhitespace: collapseWhitespace,
conservativeCollapse: conservativeCollapse,
removeComments: removeComments,
minifyCSS: minifyInlineCss
});

html = html.replace(/\\/g, '\\\\');
Expand Down