diff options
-rw-r--r-- | Gruntfile.js | 2 | ||||
-rwxr-xr-x | bin/handlebars | 2 | ||||
-rw-r--r-- | lib/precompiler.js | 34 | ||||
-rw-r--r-- | spec/precompiler.js | 2 |
4 files changed, 19 insertions, 21 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index cff9945..70239bf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,7 +52,7 @@ module.exports = function(grunt) { files: [{ expand: true, cwd: 'lib/', - src: '**/!(index|precompiler).js', + src: '**/!(index).js', dest: 'dist/amd/' }] }, diff --git a/bin/handlebars b/bin/handlebars index bf64784..4ed98b3 100755 --- a/bin/handlebars +++ b/bin/handlebars @@ -108,4 +108,4 @@ if (argv.help || (!argv.templates.length && !argv.version)) { return; } -return require('../lib/precompiler').cli(argv); +return require('../dist/cjs/precompiler').cli(argv); diff --git a/lib/precompiler.js b/lib/precompiler.js index f0955e7..48cfebd 100644 --- a/lib/precompiler.js +++ b/lib/precompiler.js @@ -1,11 +1,9 @@ /*eslint-disable no-console */ -var fs = require('fs'), - Handlebars = require('./index'), - basename = require('path').basename, - SourceMap = require('source-map'), - SourceMapConsumer = SourceMap.SourceMapConsumer, - SourceNode = SourceMap.SourceNode, - uglify = require('uglify-js'); +import fs from 'fs'; +import * as Handlebars from './handlebars'; +import {basename} from 'path'; +import {SourceMapConsumer, SourceNode} from 'source-map'; +import uglify from 'uglify-js'; module.exports.cli = function(opts) { if (opts.version) { @@ -21,7 +19,7 @@ module.exports.cli = function(opts) { try { fs.statSync(template); } catch (err) { - throw new Handlebars.Exception('Unable to open template file "' + template + '"'); + throw new Handlebars.Exception(`Unable to open template file "${template}"`); } }); @@ -33,21 +31,21 @@ module.exports.cli = function(opts) { } // Convert the known list into a hash - var known = {}; + let known = {}; if (opts.known && !Array.isArray(opts.known)) { opts.known = [opts.known]; } if (opts.known) { - for (var i = 0, len = opts.known.length; i < len; i++) { + for (let i = 0, len = opts.known.length; i < len; i++) { known[opts.known[i]] = true; } } // Build file extension pattern - var extension = opts.extension.replace(/[\\^$*+?.():=!|{}\-\[\]]/g, function(arg) { return '\\' + arg; }); + let extension = opts.extension.replace(/[\\^$*+?.():=!|{}\-\[\]]/g, function(arg) { return '\\' + arg; }); extension = new RegExp('\\.' + extension + '$'); - var output = new SourceNode(); + let output = new SourceNode(); if (!opts.simple) { if (opts.amd) { output.add('define([\'' + opts.handlebarPath + 'handlebars.runtime\'], function(Handlebars) {\n Handlebars = Handlebars["default"];'); @@ -66,24 +64,24 @@ module.exports.cli = function(opts) { output.add('{};\n'); } function processTemplate(template, root) { - var path = template, + let path = template, stat = fs.statSync(path); if (stat.isDirectory()) { fs.readdirSync(template).map(function(file) { - var childPath = template + '/' + file; + let childPath = template + '/' + file; if (extension.test(childPath) || fs.statSync(childPath).isDirectory()) { processTemplate(childPath, root || template); } }); } else { - var data = fs.readFileSync(path, 'utf8'); + let data = fs.readFileSync(path, 'utf8'); if (opts.bom && data.indexOf('\uFEFF') === 0) { data = data.substring(1); } - var options = { + let options = { knownHelpers: known, knownHelpersOnly: opts.o }; @@ -103,11 +101,11 @@ module.exports.cli = function(opts) { } template = template.replace(extension, ''); - var precompiled = Handlebars.precompile(data, options); + let precompiled = Handlebars.precompile(data, options); // If we are generating a source map, we have to reconstruct the SourceNode object if (opts.map) { - var consumer = new SourceMapConsumer(precompiled.map); + let consumer = new SourceMapConsumer(precompiled.map); precompiled = SourceNode.fromStringWithSourceMap(precompiled.code, consumer); } diff --git a/spec/precompiler.js b/spec/precompiler.js index f877c29..21e25b0 100644 --- a/spec/precompiler.js +++ b/spec/precompiler.js @@ -6,7 +6,7 @@ describe('precompiler', function() { } var Handlebars = require('../lib'), - Precompiler = require('../lib/precompiler'), + Precompiler = require('../dist/cjs/precompiler'), fs = require('fs'), uglify = require('uglify-js'); |