User
⚡ Quick Example
1import { Maker, Parser } from 'hbh-psm';3(async () => {4 // 1️⃣ Define project structure using text tree5 const textTree = `6src/7├── index.js.template console.log('Hello {{name}}!');8├── utils.js // Utility functions9README.md # {{projectName}} Project10.env NODE_ENV=development11`;13 // 2️⃣ Parse the text tree into an object structure14 const structure = Parser(textTree, true, { separator: null, metadata: true });16 // 3️⃣ Configure generator options17 const generator = new Maker('./my-project', structure, {18 variables: { name: 'World', projectName: 'AwesomeProject' },19 dryRun: false, // Set true to preview only20 override: true, // Overwrite existing files21 append: false, // Append content to files instead of overwriting22 addBackup: true, // Backup existing files before overwriting23 verbose: true, // Enable step-by-step logging24 ignore: ['.env'], // Example: ignore environment file25 conditions: { 'utils.js': true }, // Conditionally generate utils.js26 onCreate: ({ type, path }) => console.log(`Created ${type}: ${path}`)27 });29 // 4️⃣ Generate the project30 try {31 const result = await generator.generate();32 console.log('✅ Project generation complete!');34 // 5️⃣ Optional: preview result in dry-run mode35 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.