handlebars 3.3 KB

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