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