1 | #!/usr/bin/env node
|
2 |
|
3 | var optimist = require('optimist')
|
4 | .usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...', {
|
5 | 'f': {
|
6 | 'type': 'string',
|
7 | 'description': 'Output File',
|
8 | 'alias': 'output'
|
9 | },
|
10 | 'map': {
|
11 | 'type': 'string',
|
12 | 'description': 'Source Map File'
|
13 | },
|
14 | 'a': {
|
15 | 'type': 'boolean',
|
16 | 'description': 'Exports amd style (require.js)',
|
17 | 'alias': 'amd'
|
18 | },
|
19 | 'c': {
|
20 | 'type': 'string',
|
21 | 'description': 'Exports CommonJS style, path to Handlebars module',
|
22 | 'alias': 'commonjs',
|
23 | 'default': null
|
24 | },
|
25 | 'h': {
|
26 | 'type': 'string',
|
27 | 'description': 'Path to handlebar.js (only valid for amd-style)',
|
28 | 'alias': 'handlebarPath',
|
29 | 'default': ''
|
30 | },
|
31 | 'k': {
|
32 | 'type': 'string',
|
33 | 'description': 'Known helpers',
|
34 | 'alias': 'known'
|
35 | },
|
36 | 'o': {
|
37 | 'type': 'boolean',
|
38 | 'description': 'Known helpers only',
|
39 | 'alias': 'knownOnly'
|
40 | },
|
41 | 'm': {
|
42 | 'type': 'boolean',
|
43 | 'description': 'Minimize output',
|
44 | 'alias': 'min'
|
45 | },
|
46 | 'n': {
|
47 | 'type': 'string',
|
48 | 'description': 'Template namespace',
|
49 | 'alias': 'namespace',
|
50 | 'default': 'Handlebars.templates'
|
51 | },
|
52 | 's': {
|
53 | 'type': 'boolean',
|
54 | 'description': 'Output template function only.',
|
55 | 'alias': 'simple'
|
56 | },
|
57 | 'N': {
|
58 | 'type': 'string',
|
59 | 'description': 'Name of passed string templates. Optional if running in a simple mode. Required when operating on multiple templates.',
|
60 | 'alias': 'name'
|
61 | },
|
62 | 'i': {
|
63 | 'type': 'string',
|
64 | 'description': 'Generates a template from the passed CLI argument.\n"-" is treated as a special value and causes stdin to be read for the template value.',
|
65 | 'alias': 'string'
|
66 | },
|
67 | 'r': {
|
68 | 'type': 'string',
|
69 | 'description': 'Template root. Base value that will be stripped from template names.',
|
70 | 'alias': 'root'
|
71 | },
|
72 | 'p': {
|
73 | 'type': 'boolean',
|
74 | 'description': 'Compiling a partial template',
|
75 | 'alias': 'partial'
|
76 | },
|
77 | 'd': {
|
78 | 'type': 'boolean',
|
79 | 'description': 'Include data when compiling',
|
80 | 'alias': 'data'
|
81 | },
|
82 | 'e': {
|
83 | 'type': 'string',
|
84 | 'description': 'Template extension.',
|
85 | 'alias': 'extension',
|
86 | 'default': 'handlebars'
|
87 | },
|
88 | 'b': {
|
89 | 'type': 'boolean',
|
90 | 'description': 'Removes the BOM (Byte Order Mark) from the beginning of the templates.',
|
91 | 'alias': 'bom'
|
92 | },
|
93 | 'v': {
|
94 | 'type': 'boolean',
|
95 | 'description': 'Prints the current compiler version',
|
96 | 'alias': 'version'
|
97 | },
|
98 |
|
99 | 'help': {
|
100 | 'type': 'boolean',
|
101 | 'description': 'Outputs this message'
|
102 | }
|
103 | })
|
104 |
|
105 | .wrap(120)
|
106 | .check(function(argv) {
|
107 | if (argv.version) {
|
108 | return;
|
109 | }
|
110 | });
|
111 |
|
112 |
|
113 | var argv = optimist.argv;
|
114 | argv.files = argv._;
|
115 | delete argv._;
|
116 |
|
117 | var Precompiler = require('../dist/cjs/precompiler');
|
118 | Precompiler.loadTemplates(argv, function(err, opts) {
|
119 | if (err) {
|
120 | throw err;
|
121 | }
|
122 |
|
123 | if (opts.help || (!opts.templates.length && !opts.version)) {
|
124 | optimist.showHelp();
|
125 | } else {
|
126 | Precompiler.cli(opts);
|
127 | }
|
128 | });
|