⚡ Quick Example
1import { Maker, Parser } from 'hbh-psm';3(async () => {4 5 const textTree = `6src/7├── index.js.template console.log('Hello {{name}}!');8├── utils.js 9README.md # {{projectName}} Project10.env NODE_ENV=development11`;13 14 const structure = Parser(textTree, true, { separator: null, metadata: true });16 17 const generator = new Maker('./my-project', structure, {18 variables: { name: 'World', projectName: 'AwesomeProject' },19 dryRun: false, 20 override: true, 21 append: false, 22 addBackup: true, 23 verbose: true, 24 ignore: ['.env'], 25 conditions: { 'utils.js': true }, 26 onCreate: ({ type, path }) => console.log(`Created ${type}: ${path}`)27 });29 30 try {31 const result = await generator.generate();32 console.log('✅ Project generation complete!');34 35 if (generator.options.dryRun) {36 console.log('Preview of files/folders:', result);37 }38 } catch (err) {39 console.error('❌ Error generating project:', err);40 }41})();
✅ What this example do:
- Parses a text-based project tree into structured objects.
- Supports template variables (
{{name}}, {{projectName}}) in files.
- Uses dry-run / verbose / backup options safely.
- Skips files dynamically via ignore patterns.
- Supports conditional file generation.
- Hooks into creation callbacks for logging.
- Includes append mode as optional behavior.