or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

auto-processing.mdcli-tools.mdhtml-encoding.mdindex.mdtemplate-compilation.mdtemplate-syntax.md
tile.json

cli-tools.mddocs/

CLI Tools

Command-line interface for template compilation and packaging with support for multiple output formats and automated build processes.

Capabilities

dottojs Command

Command-line tool for compiling doT templates from directories with flexible output options.

# Basic syntax
dottojs [options]

# Available options:
-s, --source [value]    # Source folder/file path for templates
-d, --dest [value]      # Destination folder for compiled files  
-g, --global [value]    # Global variable name for browser templates (default: "window.render")
-p, --package [value]   # Package all templates into specified minified file
-h, --help             # Display help information
-V, --version          # Display version number

Usage Examples:

# Compile templates from views folder to output folder
dottojs -s ./views -d ./output

# Compile with custom global variable
dottojs -s ./templates -d ./dist -g "MyApp.templates"

# Compile and package into single minified file
dottojs -s ./src/templates -d ./dist -p ./dist/templates.min.js

# Compile from current directory to current directory
dottojs -s .

# Full example with all options
dottojs -s ./src/views -d ./dist/templates -g "App.render" -p ./dist/all-templates.min.js

File Processing Behavior

The CLI tool processes template files with the same behavior as the programmatic doT.process() function.

// CLI processing equivalent to:
doT.process({
  path: sourceOption,
  destination: destOption, 
  global: globalOption
});

// File type processing:
// .def files -> Template definitions/partials
// .dot files -> Compiled to functions (not output as files)
// .jst files -> Compiled to standalone .js files

Processing Flow:

  1. Scan Source Directory: Find all .def, .dot, and .jst files
  2. Load Definitions: Process .def files as template partials
  3. Compile Templates: Process .dot and .jst files
  4. Generate Output: Create .js files in destination directory
  5. Package (Optional): Minify and combine all generated files

Output File Generation

Generated JavaScript files are compatible with multiple module systems.

// Generated file structure for .jst templates:
(function(){
  var templateName = function(it) {
    // Compiled template function
  };
  
  // Multi-format module export
  if(typeof module!=='undefined' && module.exports) {
    module.exports = templateName;           // CommonJS
  } else if(typeof define==='function') {
    define(function(){return templateName;}); // AMD
  } else {
    window.render = window.render || {};     // Browser global
    window.render['templateName'] = templateName;
  }
}());

Usage of Generated Files:

// CommonJS usage
const userTemplate = require('./dist/user.js');
const html = userTemplate({ name: "Alice", email: "alice@example.com" });

// AMD usage
define(['./dist/user'], function(userTemplate) {
  return userTemplate({ name: "Bob", email: "bob@example.com" });
});

// Browser global usage
const html = window.render.user({ name: "Charlie", email: "charlie@example.com" });

Template Directory Structure

Example directory structure and CLI processing results.

Input Directory (./views):

views/
├── layout.def          # Page layout partial
├── header.def          # Header partial  
├── footer.def          # Footer partial
├── user.dot            # User template (not output as file)
├── product.dot         # Product template (not output as file)
├── newsletter.jst      # Newsletter template -> newsletter.js
├── email.jst           # Email template -> email.js
└── report.jst          # Report template -> report.js

CLI Command:

dottojs -s ./views -d ./dist/templates -g "MyApp.templates"

Output Directory (./dist/templates):

dist/templates/
├── newsletter.js       # Standalone newsletter template
├── email.js           # Standalone email template  
└── report.js          # Standalone report template

Result:

  • .def files loaded as partials (no output files)
  • .dot files compiled but not output as files
  • .jst files compiled to standalone .js files
  • All templates can reference partials via {{#def.layout}}, {{#def.header}}, etc.

Packaging and Minification

The --package option combines and minifies all generated template files.

# Package all templates into single minified file
dottojs -s ./templates -d ./dist -p ./dist/all-templates.min.js

# This internally uses uglify-js to minify and combine files

Packaging Process:

  1. Compile all templates to individual .js files
  2. Collect all generated .js files from destination directory
  3. Minify and combine using UglifyJS
  4. Write combined output to package file
  5. Individual .js files remain in destination directory

Package File Usage:

<!-- Browser usage -->
<script src="./dist/all-templates.min.js"></script>
<script>
  // All templates available under configured global variable
  const html = MyApp.templates.newsletter({ title: "Weekly Update" });
</script>

Error Handling

The CLI tool provides error reporting for common issues.

# Directory creation errors
dottojs -s ./templates -d ./invalid/deep/path/dest
# Error: Cannot create destination directory

# Source directory not found
dottojs -s ./nonexistent -d ./dist
# Error: Source directory does not exist

# Template compilation errors
dottojs -s ./templates-with-syntax-errors -d ./dist
# Error: Template compilation failed for filename.jst

Common Error Solutions:

  • Ensure source directory exists and contains template files
  • Verify destination directory is writable
  • Check template syntax for JavaScript errors
  • Ensure sufficient disk space for output files
  • Validate file permissions for read/write operations

Integration with Build Systems

CLI tool can be integrated into build processes and package.json scripts.

{
  "scripts": {
    "build-templates": "dottojs -s ./src/templates -d ./dist/templates",
    "build-templates-prod": "dottojs -s ./src/templates -d ./dist/templates -p ./dist/templates.min.js",
    "watch-templates": "chokidar './src/templates/**/*.{dot,def,jst}' -c 'npm run build-templates'"
  },
  "devDependencies": {
    "dot": "^1.1.3",
    "chokidar-cli": "^2.1.0"
  }
}

Build Integration Examples:

# Development build
npm run build-templates

# Production build with packaging
npm run build-templates-prod

# Watch for changes during development
npm run watch-templates

# Integration with other build tools
gulp.task('templates', function() {
  return exec('dottojs -s ./src/templates -d ./dist/templates');
});