From 78bbbb2060596685038189bb070628fd8f2617e3 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sun, 17 Aug 2025 16:27:16 +0000 Subject: [PATCH] fix(readme): Update README with comprehensive quick start, usage examples, API reference and advanced guides --- changelog.md | 9 + readme.md | 431 ++++++++++++++++++++++++++++++++++----- ts/00_commitinfo_data.ts | 2 +- 3 files changed, 385 insertions(+), 57 deletions(-) diff --git a/changelog.md b/changelog.md index c1adbff..3b6aa39 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2025-08-17 - 4.0.19 - fix(readme) +Update README with comprehensive quick start, usage examples, API reference and advanced guides + +- Expanded README with a detailed Quick Start guide and installation instructions +- Added examples for creating templates, supplying variables, and scaffolding projects programmatically +- Documented core features: smart variable system, template composition, dynamic file naming, interactive CLI, and post-scaffold scripts +- Included advanced usage, CI/CD integration, template validation, and real-world example templates +- Improved formatting and added code snippets for API reference and ScafTemplate usage + ## 2025-08-17 - 4.0.18 - fix(ScafTemplate) Use interactive shell for post-scaffold scripts; update CI workflows and package metadata diff --git a/readme.md b/readme.md index 19f6388..74dbf09 100644 --- a/readme.md +++ b/readme.md @@ -1,90 +1,409 @@ -# @push.rocks/smartscaf +# @push.rocks/smartscaf 🚀 -scaffold projects quickly +**Lightning-fast project scaffolding with smart templates and variable interpolation** -## Install +## What It Does -To install `@push.rocks/smartscaf`, run the following command in your project directory: +SmartScaf is a powerful TypeScript scaffolding engine that transforms template directories into fully configured projects in seconds. Think of it as your project's DNA replicator - define once, deploy anywhere with custom variables, dependency merging, and automated post-setup scripts. + +Perfect for: +- 🏗️ **Bootstrapping microservices** with consistent structure +- 📦 **Creating npm packages** with standard configurations +- 🎨 **Spinning up frontend projects** with your tech stack +- 🔧 **Standardizing team workflows** with company templates +- ⚡ **Automating repetitive project setups** + +## Installation ```bash -npm install @push.rocks/smartscaf --save +# Install globally for CLI usage +npm install -g @push.rocks/smartscaf + +# Or add to your project +npm install @push.rocks/smartscaf --save-dev ``` -## Usage +## Quick Start -Smartscaf provides a streamlined approach to quickly scaffold projects with predefined templates. It leverages modern TypeScript and ESM syntax to offer a flexible and powerful toolchain for project initialization. This guide will walk you through utilizing Smartscaf to its full potential, including setting up templates, customizing scaffolding processes, and programmatically controlling scaffolding operations. +### Create Your First Template -### Setting Up Your First Template +1. **Set up a template directory** with your project structure: -A Smartscaf template is essentially a directory with a set of files that you want to reuse across projects. It can include source code files, configuration files, and a special `.smartscaf.yml` file for defining template variables and dependencies. +``` +my-template/ +├── .smartscaf.yml # Template configuration +├── package.json # With {{projectName}} variables +├── src/ +│ └── index.ts # Your source files +├── readme.md # With {{description}} placeholder +└── .gitignore # Standard ignores +``` -1. **Create a Template Directory**: This directory should contain all the files and folders representing your template. +2. **Configure your template** in `.smartscaf.yml`: -2. **Define Template Variables in `.smartscaf.yml`**: This YAML file contains metadata about your template, such as default values for variables, dependency templates to merge, and scripts to run after scaffolding. Here's a basic example: +```yaml +# Template defaults and configuration +defaults: + projectName: 'my-awesome-project' + description: 'A fantastic new project' + author: '{{gitName}}' + license: 'MIT' + nodeVersion: '20' - ```yml - defaults: - projectName: 'My Awesome Project' - dependencies: - merge: [] - runafter: - - 'npm install' - ``` +# Merge other templates (optional) +dependencies: + merge: + - ../shared-config-template + - ../company-standards-template -3. **Utilize Handlebars Syntax for Dynamic Content**: Files in your template can use the Handlebars syntax (`{{variableName}}`) for dynamic content that will be replaced during the scaffolding process. +# Post-scaffold automation +runafter: + - 'npm install' + - 'git init' + - 'git add .' + - 'git commit -m "Initial commit from SmartScaf"' +``` -### Scaffolding a New Project +3. **Use Handlebars syntax** in your template files: -Once you have a template ready, you can scaffold a new project by programmatically creating and manipulating a `ScafTemplate` instance from Smartscaf. +```typescript +// src/index.ts +/** + * {{description}} + * @author {{author}} + * @license {{license}} + */ -1. **Import Smartscaf and Create a New Instance**: +export class {{className}} { + constructor() { + console.log('Welcome to {{projectName}}!'); + } +} +``` - ```typescript - import { ScafTemplate } from '@push.rocks/smartscaf'; +### Scaffold a New Project - async function scaffoldProject() { - const myTemplate = await ScafTemplate.createTemplateFromDir( - '', - ); - await myTemplate.readTemplateFromDir(); // Load the template - // Supply any additional variables or override defaults - await myTemplate.supplyVariables({ - projectName: 'My New Project', - }); - // Optionally, interactively ask for missing variables - // await myTemplate.askCliForMissingVariables(); - await myTemplate.writeToDisk(''); // Scaffold! - } +```typescript +import { ScafTemplate } from '@push.rocks/smartscaf'; - scaffoldProject().then(() => - console.log('Project scaffolded successfully!'), - ); - ``` +async function createProject() { + // Load your template + const template = await ScafTemplate.createTemplateFromDir('./my-template'); + await template.readTemplateFromDir(); + + // Supply variables (overrides defaults) + await template.supplyVariables({ + projectName: 'super-api', + description: 'Revolutionary API service', + className: 'SuperAPI', + author: 'John Doe' + }); + + // Interactive mode - asks for any missing variables + await template.askCliForMissingVariables(); + + // Generate the project + await template.writeToDisk('./projects/super-api'); + + console.log('✨ Project scaffolded successfully!'); +} -2. **Customizing the Scaffolding Process**: You can customize the scaffolding process by defining additional logic to manipulate files, directories, or template variables before writing to disk. +createProject(); +``` -### Advanced Features +## Core Features -- **Merging Templates**: Smartscaf allows you to compose complex templates by specifying dependencies in the `.smartscaf.yml` file. This enables you to merge multiple templates into one scaffolded project. -- **Running Scripts After Scaffolding**: Specify an array of shell commands in the `runafter` section of your `.smartscaf.yml` to be executed after the project is scaffolded. This is useful for running installations or initial builds. +### 🎯 Smart Variable System -- **Programmatic API**: Smartscaf's flexible API allows for programmatically controlling every aspect of the scaffolding process, making it suitable for integrating into build tools, command line utilities, or CI/CD pipelines. +SmartScaf intelligently manages template variables through multiple layers: -### Complete Feature Set and Use Cases +```typescript +const template = await ScafTemplate.createTemplateFromDir('./template'); +await template.readTemplateFromDir(); -The usage scenarios outlined above merely scratch the surface of what Smartscaf can do. With its comprehensive API, you can manage complex scaffolding tasks, including but not limited to: +// Access variable collections +console.log(template.defaultVariables); // From .smartscaf.yml defaults +console.log(template.requiredVariables); // Found in template files +console.log(template.suppliedVariables); // What you've provided +console.log(template.missingVariables); // What still needs values +``` -- Creating project templates with varying levels of complexity and customization. -- Dynamically adjusting project structures based on user input or external parameters. -- Integrating scaffolding steps into larger automation workflows, significantly reducing manual setup time for new projects. +### 🔀 Template Composition -In conclusion, Smartscaf empowers developers to streamline their project initialization process, ensuring consistency, reducing boilerplate, and allowing more time to be spent on development rather than setup. Its flexibility and broad feature set make it a valuable tool in a modern developer's toolkit. +Merge multiple templates to create complex project structures: -For further information and a deeper dive into Smartscaf's capabilities, please refer to the [official documentation](https://gitlab.com/push.rocks/smartscaf#README) and explore the [source code](https://gitlab.com/push.rocks/smartscaf) for advanced use cases and customization options. +```yaml +# .smartscaf.yml +dependencies: + merge: + - ../base-template # Common structure + - ../auth-template # Authentication setup + - ../docker-template # Container configuration +``` + +Templates are merged in order, allowing you to build sophisticated scaffolds from modular components. + +### 📝 Dynamic File Naming + +Use frontmatter to dynamically rename files during scaffolding: + +```markdown +--- +fileName: {{projectName}}.config.js +--- + +module.exports = { + name: '{{projectName}}', + version: '{{version}}' +}; +``` + +### 🤖 Interactive CLI Mode + +Let SmartScaf prompt for missing variables: + +```typescript +// Automatically prompts for any variables not yet supplied +await template.askCliForMissingVariables(); +``` + +### 🚀 Post-Scaffold Scripts + +Automate setup tasks after scaffolding: + +```yaml +runafter: + - 'npm install' # Install dependencies + - 'npm run build' # Initial build + - 'npm test' # Verify setup + - 'code .' # Open in VS Code +``` + +Scripts run in order using an interactive shell, ensuring proper environment handling. + +## Advanced Usage + +### Programmatic Control + +```typescript +import { ScafTemplate } from '@push.rocks/smartscaf'; + +class ProjectGenerator { + private template: ScafTemplate; + + async initialize(templatePath: string) { + this.template = await ScafTemplate.createTemplateFromDir(templatePath); + await this.template.readTemplateFromDir(); + } + + async generate(config: any, outputPath: string) { + // Supply configuration + await this.template.supplyVariables(config); + + // Check what's missing + if (this.template.missingVariables.length > 0) { + console.log('Missing:', this.template.missingVariables); + // Handle missing variables programmatically + // or use: await this.template.askCliForMissingVariables(); + } + + // Generate project + await this.template.writeToDisk(outputPath); + } +} +``` + +### Template Validation + +```typescript +// Validate template before using +const template = await ScafTemplate.createTemplateFromDir('./template'); +await template.readTemplateFromDir(); + +// Check template structure +if (template.templateSmartfileArray.length === 0) { + throw new Error('Template is empty!'); +} + +// Verify required variables +const required = template.requiredVariables; +const defaults = Object.keys(template.defaultVariables); +const missing = required.filter(v => !defaults.includes(v)); + +if (missing.length > 0) { + console.warn(`Template needs: ${missing.join(', ')}`); +} +``` + +### Complex Variable Structures + +SmartScaf supports nested object variables: + +```yaml +# .smartscaf.yml +defaults: + app.name: 'MyApp' + app.version: '1.0.0' + database.host: 'localhost' + database.port: 5432 + api.endpoints.users: '/api/users' + api.endpoints.auth: '/api/auth' +``` + +Use in templates: + +```javascript +// config.js +export default { + app: { + name: '{{app.name}}', + version: '{{app.version}}' + }, + database: { + host: '{{database.host}}', + port: {{database.port}} + }, + api: { + users: '{{api.endpoints.users}}', + auth: '{{api.endpoints.auth}}' + } +}; +``` + +### CI/CD Integration + +```typescript +// ci-scaffold.ts +import { ScafTemplate } from '@push.rocks/smartscaf'; + +async function scaffoldForCI() { + const template = await ScafTemplate.createTemplateFromDir( + process.env.TEMPLATE_PATH + ); + await template.readTemplateFromDir(); + + // Get variables from environment + const vars = { + projectName: process.env.PROJECT_NAME, + environment: process.env.DEPLOY_ENV, + apiKey: process.env.API_KEY, + region: process.env.AWS_REGION + }; + + await template.supplyVariables(vars); + await template.writeToDisk(process.env.OUTPUT_PATH); +} + +// Run in CI pipeline +scaffoldForCI().catch(console.error); +``` + +## Real-World Examples + +### Microservice Template + +```yaml +# .smartscaf.yml for microservice template +defaults: + serviceName: 'my-service' + port: 3000 + dockerImage: 'node:20-alpine' + healthPath: '/health' + +dependencies: + merge: + - ../shared/base-service + - ../shared/monitoring + - ../shared/logging + +runafter: + - 'npm install' + - 'docker build -t {{serviceName}}:latest .' + - 'npm run test:integration' +``` + +### React Component Library + +```yaml +# .smartscaf.yml for React library +defaults: + libraryName: 'ui-components' + componentPrefix: 'UI' + useTypeScript: true + useStorybook: true + testRunner: 'jest' + +runafter: + - 'pnpm install' + - 'pnpm build' + - 'pnpm storybook:build' + - 'pnpm test' +``` + +## API Reference + +### ScafTemplate Class + +```typescript +class ScafTemplate { + // Factory method + static createTemplateFromDir(dirPath: string): Promise + + // Core methods + readTemplateFromDir(): Promise + supplyVariables(variables: object): Promise + askCliForMissingVariables(): Promise + writeToDisk(destinationPath: string): Promise + + // Properties + name: string // Template name + description: string // Template description + templateSmartfileArray: SmartFile[] // Loaded template files + defaultVariables: object // Default values from .smartscaf.yml + requiredVariables: string[] // Variables found in templates + suppliedVariables: object // Variables you've provided + missingVariables: string[] // Variables still needed +} +``` + +## Best Practices + +### 📁 Template Organization + +``` +company-templates/ +├── base/ # Shared foundations +│ ├── typescript/ # TS configuration +│ ├── eslint/ # Linting setup +│ └── ci-cd/ # CI/CD pipelines +├── services/ # Service templates +│ ├── rest-api/ +│ ├── graphql-api/ +│ └── worker-service/ +└── frontends/ # Frontend templates + ├── react-app/ + ├── vue-app/ + └── static-site/ +``` + +### 🔒 Security Considerations + +- Never commit sensitive data in templates +- Use environment variables for secrets +- Add `.smartscaf.yml` to `.gitignore` if it contains private defaults +- Validate user input when using in automation + +### 🎨 Template Design Tips + +1. **Start small** - Begin with minimal templates and grow them +2. **Use composition** - Build complex templates from simple ones +3. **Document variables** - Add comments in `.smartscaf.yml` +4. **Test templates** - Create test scaffolds before deploying +5. **Version templates** - Use git tags for template versions ## License and Legal Information -This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. +This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. @@ -99,4 +418,4 @@ Registered at District court Bremen HRB 35230 HB, Germany For any legal inquiries or if you require further information, please contact us via email at hello@task.vc. -By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works. +By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works. \ No newline at end of file diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index db26a19..5ea995e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartscaf', - version: '4.0.18', + version: '4.0.19', description: 'A project aimed at quickly scaffolding projects with support for TypeScript, smart file handling, and template rendering.' }