{"id":23668860,"url":"https://github.com/boluwatifee4/di-config-module-schematic","last_synced_at":"2026-03-01T05:09:22.681Z","repository":{"id":269007373,"uuid":"906123113","full_name":"boluwatifee4/di-config-module-schematic","owner":"boluwatifee4","description":"Custom built schematic that; Generates and updates a DI-configured amgular module","archived":false,"fork":false,"pushed_at":"2025-05-04T22:32:08.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-24T00:04:17.583Z","etag":null,"topics":["angular","dependency-injection","schematics"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/di-config-module-schematic","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boluwatifee4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-20T08:03:32.000Z","updated_at":"2025-05-04T22:32:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c3d2c99-d0fb-4e25-bbf2-e3555014b2ac","html_url":"https://github.com/boluwatifee4/di-config-module-schematic","commit_stats":null,"previous_names":["boluwatifee4/di-config-module-schematic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/boluwatifee4/di-config-module-schematic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boluwatifee4%2Fdi-config-module-schematic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boluwatifee4%2Fdi-config-module-schematic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boluwatifee4%2Fdi-config-module-schematic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boluwatifee4%2Fdi-config-module-schematic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boluwatifee4","download_url":"https://codeload.github.com/boluwatifee4/di-config-module-schematic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boluwatifee4%2Fdi-config-module-schematic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29960269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T01:47:18.291Z","status":"online","status_checked_at":"2026-03-01T02:00:07.437Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","dependency-injection","schematics"],"created_at":"2024-12-29T08:14:24.136Z","updated_at":"2026-03-01T05:09:17.670Z","avatar_url":"https://github.com/boluwatifee4.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **di-config-module-schematic** 🛠️\n\n\u003cimg width=\"801\" alt=\"image\" src=\"https://github.com/user-attachments/assets/b74bfa49-6dd5-4023-bcee-cb3cf571ee69\" /\u003e\n\n## **How to Use** 🧑‍💻\n\nThis schematic generates Angular modules with **Dependency Injection (DI)** support. It supports two key actions: **create** ➕ and **update** 🔄, making it easy to generate new modules or enhance existing ones. The schematic is designed to be directory-aware 📂, meaning:\n\n- For **create** ➕: Run the schematic from the directory where the module should be created.\n- For **update** 🔄: Run the schematic from the directory containing the module to be updated.\n\nYou can use the schematic either **deployed from npm** 🌐 or **locally** 💻 during development.\n\n---\n\n### **Option 1: Use the Deployed Schematic from npm** 🌐\n\n1. Install the schematic globally:\n   ```bash\n   npm install -g di-config-module-schematic\n   ```\n\n2. Run the schematic in your Angular project directory:\n   ```bash\n   ng generate di-module\n   ```\n\n3. Follow the prompts in the terminal. Once completed:\n   - For **create** ➕, a new module will be generated in the current directory.\n   - For **update** 🔄, the specified module will be enhanced with DI support.\n\n---\n\n### **Option 2: Use the Schematic Locally** 💻\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/your-username/di-config-module-schematic.git\n   cd di-config-module-schematic\n   ```\n\n2. Build the project:\n   ```bash\n   npm run build\n   ```\n\n3. Run the schematic in your Angular project:\n   ```bash\n   schematics ./dist/src/di-config-module-schematic:di-module\n   ```\n\n4. Follow the prompts in the terminal. Once completed:\n   - For **create** ➕, a new module will be generated in the current directory.\n   - For **update** 🔄, the specified module will be enhanced with DI support.\n\n---\n\n## **Actions Supported** ✅\n\n### **Create a Module** ➕\n\nTo create a new module:\n1. Navigate 📂 to the directory where you want the module to be created (e.g., `src/app/modules`).\n2. Run the schematic.\n3. Provide the following details when prompted:\n   - Module name 📛\n   - Configuration interface name 📝\n   - InjectionToken name 🔑\n\nThe schematic will generate the module and necessary files in the current directory.\n\n### **Update an Existing Module** 🔄\n\nTo update an existing module:\n1. Navigate 📂 to the directory containing the module to be updated (e.g., `src/app/modules/payments`).\n2. Run the schematic.\n3. Provide the following details when prompted:\n   - Module name 📛\n   - Configuration interface name 📝\n   - InjectionToken name 🔑\n\nThe schematic will:\n- Update the `forRoot` method for DI configuration if not already present.\n- Generate missing files like the configuration interface 📝 and InjectionToken 🔑, if required.\n\n---\n\n## **How to Use a Module with DI Support** 🛠️\n\n### Example: Payments Module 💳\n\nAssume you provided `payments` as the module name during generation.\n\n### **1. Define Configuration Properties** 📝\n\nEdit the `payments-config.interface.ts` file to include the configuration properties:\n\n```typescript\nexport interface PaymentsConfig {\n  baseUrl: string;            // The base URL for the payments API\n  currency: string;           // Default currency for transactions\n  retryAttempts: number;      // Number of retry attempts for failed requests\n  enableDebugMode: boolean;   // Whether to enable debug mode for logging\n}\n```\n\n---\n\n### **2. Import and Configure the Module** 📥\n\nImport the generated module where needed and configure it using the `forRoot` method:\n\n**Example: `app.module.ts`**\n```typescript\nimport { NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\nimport { AppComponent } from './app.component';\nimport { PaymentsModule } from './app/payments/payments.module';\n\n@NgModule({\n  declarations: [AppComponent],\n  imports: [\n    BrowserModule,\n    PaymentsModule.forRoot({\n      baseUrl: 'https://api.example.com/payments',  // Payments API URL\n      currency: 'USD',                             // Default currency\n      retryAttempts: 3,                            // Retry attempts for failed requests\n      enableDebugMode: true,                       // Enable debug mode\n    }),\n  ],\n  providers: [],\n  bootstrap: [AppComponent],\n})\nexport class AppModule {}\n```\n\n---\n\n### **3. Inject Configuration in Components** ⚙️\n\nInject the configuration wherever required using the `PAYMENTS_CONFIG_TOKEN`.\n\n**Example: `app.component.ts`**\n```typescript\nimport { Component, Inject } from '@angular/core';\nimport { PAYMENTS_CONFIG_TOKEN } from './app/payments/payments-injection-tokens';\nimport { PaymentsConfig } from './app/payments/payments-config.interface';\n\n@Component({\n  selector: 'app-root',\n  template: `\n    \u003ch1\u003eWelcome to the Payments App\u003c/h1\u003e\n    \u003cp\u003eBase URL: {{ config.baseUrl }}\u003c/p\u003e\n    \u003cp\u003eDefault Currency: {{ config.currency }}\u003c/p\u003e\n    \u003cp\u003eRetry Attempts: {{ config.retryAttempts }}\u003c/p\u003e\n    \u003cp\u003eDebug Mode: {{ config.enableDebugMode ? 'Enabled' : 'Disabled' }}\u003c/p\u003e\n  `,\n})\nexport class AppComponent {\n  constructor(@Inject(PAYMENTS_CONFIG_TOKEN) public config: PaymentsConfig) {\n    console.log('Config Properties:', config.baseUrl, config.currency, config.retryAttempts, config.enableDebugMode);\n  }\n}\n```\n\n### **Key Challenges and Solutions**\n\n---\n\n#### Path Normalization\n- **Challenge:** \n  Files were created in incorrect locations due to absolute system paths (`/Users/...`) instead of workspace-relative paths (`apps/...`, `libs/...`).\n- **Solution:** \n  Implemented a utility to detect the workspace root (`nx.json` or `angular.json`) and normalize paths dynamically.\n\n---\n\n####  User-Friendly Interaction\n- **Challenge:** \n  Long CLI commands with multiple options were error-prone and intimidating for users.\n- **Solution:** \n  Introduced interactive prompts using `x-prompt` and shortened the schematic name to `di-module` for a streamlined experience.\n\n---\n\n## **Getting Started With Schematics** 🏁\n\nThis repository serves as a starting point to create and publish Angular schematics.\n\n### **Testing Locally** 🧪\n\n1. Install the schematics CLI globally:\n   ```bash\n   npm install -g @angular-devkit/schematics-cli\n   ```\n\n2. Run the schematic locally using the `schematics` CLI:\n   ```bash\n   schematics ./dist/src/di-config-module-schematic:di-module\n   ```\n\n3. Follow the prompts to generate your module.\n\n---\n\n### **Unit Testing** 🧑‍🔬\n\nRun unit tests with:\n```bash\nnpm run test\n```\n\nThis uses Jasmine as the test framework.\n\n---\n\n### **Publishing** 🚀\n\nTo publish, simply do:\n```bash\nnpm run build\nnpm publish\n```\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboluwatifee4%2Fdi-config-module-schematic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboluwatifee4%2Fdi-config-module-schematic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboluwatifee4%2Fdi-config-module-schematic/lists"}