UNPKG

1.91 kBPlain TextView Raw
1#!/usr/bin/env node
2var path = require('path');
3var precompile = require('../src/precompile').precompile;
4var Environment = require('../src/environment').Environment;
5var lib = require('../src/lib');
6
7var 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
41var argv = optimist.argv;
42
43if (argv.help) {
44 optimist.showHelp();
45 process.exit(1);
46}
47
48var env = new Environment([]);
49
50lib.each([].concat(argv.filters).join(',').split(','), function(name) {
51 env.addFilter(name.trim(), function() {}, true);
52});
53
54console.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}));