var raptorTemplatesCompiler = require('../compiler'); var fs = require('fs'); var nodePath = require('path'); var Minimatch = require('minimatch').Minimatch; var cwd = process.cwd(); require('raptor-ecma/es6'); var mmOptions = { matchBase: true, dot: true, flipNegate: true }; function relPath(path) { if (path.startsWith(cwd)) { return path.substring(cwd.length+1); } } var args = require('raptor-args').createParser({ '--help': { type: 'boolean', description: 'Show this help message' }, '--files --file -f *': { type: 'string[]', description: 'A set of directories or files to compile' }, '--ignore -i': { type: 'string[]', description: 'An ignore rule (default: --ignore "/node_modules" ".*")' }, '--clean -c': { type: 'boolean', description: 'Clean all of the *.rhtml.js files' } }) .usage('Usage: $0 [options]') .example('Compile a single template', '$0 template.rhtml') .example('Compile all templates in the current directory', '$0 .') .example('Compile multiple templates', '$0 template.rhtml src/ foo/') .example('Delete all *.rhtml.js files in the current directory', '$0 . --clean') .validate(function(result) { if (result.help) { this.printUsage(); process.exit(0); } if (!result.files || result.files.length === 0) { this.printUsage(); process.exit(1); } }) .onError(function(err) { this.printUsage(); if (err) { console.log(); console.log(err); } process.exit(1); }) .parse(); var ignoreRules = args.ignore; if (!ignoreRules) { ignoreRules = ['/node_modules', '.*']; } ignoreRules = ignoreRules.filter(function (s) { s = s.trim(); return s && !s.match(/^#/); }); ignoreRules = ignoreRules.map(function (pattern) { return new Minimatch(pattern, mmOptions); }); function isIgnored(path, dir, stat) { if (path.startsWith(dir)) { path = path.substring(dir.length); } path = path.replace(/\\/g, '/'); var ignore = false; var ignoreRulesLength = ignoreRules.length; for (var i=0; i