1 | #!/usr/bin/env node
|
2 | var path = require('path');
|
3 | var precompile = require('../src/precompile').precompile;
|
4 | var Environment = require('../src/environment').Environment;
|
5 | var lib = require('../src/lib');
|
6 |
|
7 | var optimist = require('optimist')
|
8 |
|
9 | .usage('$0 [-f|--force] [-a|--filters <filters>] [-n|--name <name>] [-i|--include <regex>] [-x|--exclude <regex>] <path>')
|
10 | .wrap(80)
|
11 |
|
12 | .describe('help', 'Display this help message')
|
13 | .boolean('help')
|
14 | .alias('h', 'help')
|
15 | .alias('?', 'help')
|
16 |
|
17 | .describe('force', 'Force compilation to continue on error')
|
18 | .boolean('force')
|
19 | .alias('f', 'force')
|
20 |
|
21 | .describe('filters', 'Give the compiler a comma-delimited list of asynchronous filters, required for correctly generating code')
|
22 | .string('filters')
|
23 | .alias('a', 'filters')
|
24 |
|
25 | .describe('name', 'Specify the template name when compiling a single file')
|
26 | .string('name')
|
27 | .alias('n', 'n')
|
28 |
|
29 | .describe('include', 'Include a file or folder which match the regex but would otherwise be excluded. You can use this flag multiple times')
|
30 | .string('include' )
|
31 | .default('include', ['\\.html$', '\\.jinja$'])
|
32 | .alias('i', 'include')
|
33 |
|
34 | .describe('exclude', 'Exclude a file or folder which match the regex but would otherwise be included. You can use this flag multiple times')
|
35 | .string('exclude' )
|
36 | .default('exclude', [])
|
37 | .alias('x', 'exclude')
|
38 |
|
39 | .demand(1);
|
40 |
|
41 | var argv = optimist.argv;
|
42 |
|
43 | if (argv.help) {
|
44 | optimist.showHelp();
|
45 | process.exit(1);
|
46 | }
|
47 |
|
48 | var env = new Environment([]);
|
49 |
|
50 | lib.each([].concat(argv.filters).join(',').split(','), function(name) {
|
51 | env.addFilter(name.trim(), function() {}, true);
|
52 | });
|
53 |
|
54 | console.log(precompile(argv._[0], {
|
55 |
|
56 | env : env,
|
57 | force : argv.force,
|
58 | name : argv.name,
|
59 |
|
60 | include : [].concat(argv.include),
|
61 | exclude : [].concat(argv.exclude)
|
62 |
|
63 | }));
|