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 yargs = require('yargs')
|
8 |
|
9 | .usage('$0 [-f|--force] [-a|--filters <filters>] [-n|--name <name>] [-i|--include <regex>] [-x|--exclude <regex>] [-w|--wrapper <wrapper>] <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 | .describe('wrapper', 'Load a external plugin to change the output format of the precompiled templates (for example, "-w custom" will load a module named "nunjucks-custom")')
|
40 | .string('wrapper')
|
41 | .alias('w', 'wrapper')
|
42 |
|
43 | .demand(1);
|
44 |
|
45 | var argv = yargs.argv;
|
46 |
|
47 | if (argv.help) {
|
48 | yargs.showHelp();
|
49 | process.exit(1);
|
50 | }
|
51 |
|
52 | var env = new Environment([]);
|
53 |
|
54 | lib.each([].concat(argv.filters).join(',').split(','), function(name) {
|
55 | env.addFilter(name.trim(), function() {}, true);
|
56 | });
|
57 |
|
58 | if(argv.wrapper) {
|
59 | argv.wrapper = require('nunjucks-' + argv.wrapper).wrapper;
|
60 | }
|
61 |
|
62 | console.log(precompile(argv._[0], {
|
63 | env : env,
|
64 | force : argv.force,
|
65 | name : argv.name,
|
66 | wrapper: argv.wrapper,
|
67 |
|
68 | include : [].concat(argv.include),
|
69 | exclude : [].concat(argv.exclude)
|
70 | }));
|