Globbing Reference
File pattern matching for templates
Globbing Reference
Glob patterns control which files are included, excluded, and how they're processed. These patterns are configured within CyanGlob objects as part of the Cyan configuration structure's files array.
Basic Patterns
Match All
glob: '**/*'
**- Match any number of directories*- Match any number of characters (except/)
Match by Extension
glob: '**/*.md' // All markdown filesglob: '**/*.ts' // All TypeScript filesglob: '**/*.json' // All JSON files
Match Specific Directory
glob: 'src/**/*' // Everything under src/glob: 'docs/**/*.md' // Markdown files under docs/
Pattern Syntax
| Pattern | Description | Example Match |
|---|---|---|
* | Any characters (no /) | file.ts, component.tsx |
** | Any directories | src/, src/lib/, src/lib/utils/ |
**/* | Any file in any directory | src/index.ts, lib/utils.ts |
*.ext | Files with extension | file.md, readme.md |
**/*.ext | All files with extension in any directory | src/file.ts, lib/utils.ts |
? | Single character | file1.ts, file2.ts |
[abc] | Character set | file-a.ts, file-b.ts |
[!abc] | Negated set | file-x.ts (not a, b, or c) |
{a,b,c} | Brace expansion | *.{ts,tsx} matches TypeScript files |
Multiple Patterns
Import
import { GlobType } from '@atomicloud/cyan-sdk';
Multiple File Groups
Use multiple file groups for different processing:
files: [{ root: 'templates', glob: '**/*.md', exclude: [], type: GlobType.Template },{ root: 'templates', glob: '**/*.json', exclude: [], type: GlobType.Template },{ root: 'templates', glob: '**/*.png', exclude: [], type: GlobType.Copy },{ root: 'templates', glob: '**/*.jpg', exclude: [], type: GlobType.Copy }]
Multiple Extensions in One Pattern
// Match .ts and .tsx filesglob: '**/*.ts?(x)'// Match .js, .jsx, .ts, .tsxglob: '**/*.@(js|ts)?(x)'
Extglob patterns like ?(x) and @(a|b) use bash extended glob syntax. The Node SDK uses minimatch which supports these by default. Test your patterns if using other SDKs.
Exclude Patterns
Exclude files from processing:
files: [{root: 'templates', // Defaults to '.' (current directory) if omittedglob: '**/*',exclude: ['**/node_modules/**', // Exclude node_modules'**/test/**', // Exclude test directories'**/*.test.*', // Exclude test files'**/*.spec.*', // Exclude spec files'**/.DS_Store', // Exclude macOS files'**/dist/**', // Exclude build output'**/.git/**' // Exclude git directory],type: GlobType.Template}]
Common Patterns
Source Code Only
glob: 'src/**/*.{ts,tsx,js,jsx}'
Documentation
glob: 'docs/**/*.md'
Configuration Files
glob: '*.{json,yaml,yml,toml}'
Assets
glob: 'assets/**/*.{png,jpg,svg,ico}'
Ignore Hidden Files
exclude: ['**/.*'] // Files starting with dot
GlobType Reference
The GlobType enum controls how files are processed:
| Type | Use Case |
|---|---|
GlobType.Template | Text files needing variable substitution |
GlobType.Copy | Binary files and files without variables |
Python SDK Note: The Python SDK uses different enum values: GlobType.Template = 1 and GlobType.Copy = 2 (instead of 0 and 1 in Node/.NET). Always use the symbolic names rather than numeric values for cross-SDK compatibility.
Best Practices
1. Be Explicit
// Good: Explicit file typesglob: '**/*.{md,json,ts,tsx}'// Bad: Too broad, might catch unwanted filesglob: '**/*'
2. Separate by Processing Type
files: [// Template files{ root: 'templates', glob: '**/*.md', exclude: [], type: GlobType.Template },{ root: 'templates', glob: '**/*.json', exclude: [], type: GlobType.Template },// Binary files (never template!){ root: 'templates', glob: '**/*.png', exclude: [], type: GlobType.Copy },{ root: 'templates', glob: '**/*.woff2', exclude: [], type: GlobType.Copy }]
3. Use Meaningful Excludes
exclude: ['**/node_modules/**', // Dependencies'**/dist/**', // Build output'**/.cache/**', // Cache directories'**/*.log', // Log files'**/.env*' // Environment files]
Testing Patterns
Test your glob patterns to ensure they match expected files:
# Using find (note: use single * for -name, not **)find templates -name "*.md"# Using shell globbing (zsh/bash with globstar enabled)ls templates/**/*.md# Using the glob CLI toolglob "**/*.md" templates/
Related
- Tutorial: Changing Glob - Glob patterns tutorial
- Pass Images and Binaries - Handling binary files
- Conditional Files - Conditional file inclusion