@oamm/textor 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -89,6 +89,42 @@ Configure this in .textor/config.json:
89
89
  }
90
90
  ```
91
91
 
92
+ ## File Naming Patterns
93
+
94
+ You can override generated file names for feature and component sub-files (api, services, hooks, tests, etc.) using simple patterns. Patterns support `{{componentName}}`, `{{hookName}}`, `{{hookExtension}}`, `{{testExtension}}`, `{{componentExtension}}`, and `{{featureExtension}}`.
95
+
96
+ Example:
97
+ ```json
98
+ {
99
+ "filePatterns": {
100
+ "features": {
101
+ "api": "{{componentName}}.route.ts"
102
+ },
103
+ "components": {
104
+ "api": "{{componentName}}.route.ts"
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ More examples:
111
+ ```json
112
+ {
113
+ "filePatterns": {
114
+ "features": {
115
+ "hook": "use{{componentName}}.ts",
116
+ "test": "{{componentName}}.spec{{testExtension}}",
117
+ "readme": "{{componentName}}.md"
118
+ },
119
+ "components": {
120
+ "api": "{{componentName}}.route{{testExtension}}",
121
+ "services": "{{componentName}}.service{{hookExtension}}",
122
+ "stories": "{{componentName}}.stories.tsx"
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
92
128
  ## 🛡️ Safety & File Tracking
93
129
 
94
130
  Textor uses a multi-layered safety approach to protect your codebase.
@@ -114,10 +150,21 @@ If you have manually edited a Textor-generated file and wish to remove or move i
114
150
  ## 🛠️ Commands
115
151
 
116
152
  ### add-section
117
- Create a route + feature binding.
153
+ Create a route + feature binding, or a standalone feature.
118
154
 
119
155
  ```bash
120
- pnpm textor add-section <route> <featurePath> [options]
156
+ pnpm textor add-section [route] <featurePath> [options]
157
+ ```
158
+
159
+ If `route` is provided, Textor creates both a route adapter (e.g., in `src/pages`) and a feature module. If `route` is omitted, Textor scaffolds only the feature module. This is useful for features that are shared across multiple pages or used as sub-parts of other features.
160
+
161
+ **Examples:**
162
+ ```bash
163
+ # Create a section with a route
164
+ pnpm textor add-section /users users/catalog
165
+
166
+ # Create a standalone feature (no route file)
167
+ pnpm textor add-section auth/login
121
168
  ```
122
169
 
123
170
  **Options:**
@@ -149,6 +196,14 @@ pnpm textor move-section /old /new
149
196
  ### remove-section / remove-component
150
197
  Safely remove Textor-managed modules.
151
198
 
199
+ ```bash
200
+ # Remove by route
201
+ pnpm textor remove-section /users
202
+
203
+ # Remove a standalone feature by its name or path
204
+ pnpm textor remove-section auth/login
205
+ ```
206
+
152
207
  ### list-sections
153
208
  List all Textor-managed modules, including their architectural capabilities (API, Hooks, etc.).
154
209
 
@@ -204,6 +259,16 @@ pnpm textor adopt /users
204
259
  pnpm textor adopt --all
205
260
  ```
206
261
 
262
+ ### upgrade-config
263
+ Upgrade `.textor/config.json` to the latest schema version without recreating it.
264
+
265
+ ```bash
266
+ pnpm textor upgrade-config
267
+ ```
268
+
269
+ **Options:**
270
+ - `--dry-run`: Print the upgraded config without writing it.
271
+
207
272
  ## 🏗️ Technical Architecture
208
273
 
209
274
  Textor is designed with enterprise-grade robustness, moving beyond simple scaffolding to provide a reliable refactoring engine.
@@ -250,9 +315,11 @@ When moving or renaming sections, Textor performs scoped AST-like updates:
250
315
  ## ⚙️ Configuration
251
316
 
252
317
  The .textor/config.json file allows full control over the tool's behavior.
318
+ `configVersion` tracks schema changes and is updated by `textor upgrade-config`.
253
319
 
254
320
  ```json
255
321
  {
322
+ "configVersion": 2,
256
323
  "paths": {
257
324
  "pages": "src/pages",
258
325
  "features": "src/features",
@@ -383,16 +450,79 @@ The .textor/config.json file allows full control over the tool's behavior.
383
450
 
384
451
  ## 📝 Template Overrides
385
452
 
386
- Customize generated code by placing templates in .textor/templates/. Supported templates:
387
- - route.astro
388
- - feature.astro
389
- - component.astro
390
- - hook.ts
391
- - context.tsx
392
- - test.tsx
393
- - index.ts
453
+ You can customize the code generated by Textor by providing your own templates. Textor looks for override files in the `.textor/templates/` directory at your project root.
454
+
455
+ ### How to use Template Overrides
456
+
457
+ 1. Create the `.textor/templates/` directory if it doesn't exist.
458
+ 2. Create a file named according to the table below (e.g., `feature.astro` or `component.tsx`).
459
+ 3. Use `{{variable}}` placeholders in your template. Textor will automatically replace them when generating files.
460
+
461
+ ### Supported Templates
462
+
463
+ | Template Name | File to create in `.textor/templates/` | Available Variables |
464
+ | :--- | :--- | :--- |
465
+ | **Route** | `route.astro` | `{{layoutName}}`, `{{layoutImportPath}}`, `{{featureImportPath}}`, `{{featureComponentName}}` |
466
+ | **Feature** | `feature.astro` or `feature.tsx` | `{{componentName}}`, `{{scriptImportPath}}` |
467
+ | **Component** | `component.astro` or `component.tsx` | `{{componentName}}` |
468
+ | **Hook** | `hook.ts` | `{{componentName}}`, `{{hookName}}` |
469
+ | **Context** | `context.tsx` | `{{componentName}}` |
470
+ | **Test** | `test.tsx` | `{{componentName}}`, `{{componentPath}}` |
471
+ | **Index** | `index.ts` | `{{componentName}}`, `{{componentExtension}}` |
472
+ | **Types** | `types.ts` | `{{componentName}}` |
473
+ | **API** | `api.ts` | `{{componentName}}` |
474
+ | **Endpoint** | `endpoint.ts` | `{{componentName}}` |
475
+ | **Service** | `service.ts` | `{{componentName}}` |
476
+ | **Schema** | `schema.ts` | `{{componentName}}` |
477
+ | **Readme** | `readme.md` | `{{componentName}}` |
478
+ | **Stories** | `stories.tsx` | `{{componentName}}`, `{{componentPath}}` |
479
+ | **Config** | `config.ts` | `{{componentName}}` |
480
+ | **Constants** | `constants.ts` | `{{componentName}}` |
481
+ | **Scripts Index**| `scripts-index.ts` | (none) |
482
+
483
+ > **Note:** For `feature` and `component` templates, use the extension that matches your configured framework (`.astro` for Astro, `.tsx` for React). Other templates have fixed extensions for the override file, regardless of your project's configuration.
484
+
485
+ ### Variables Description
486
+
487
+ - `{{componentName}}`: The PascalCase name of the feature or component (e.g., `UserCatalog`).
488
+ - `{{hookName}}`: The camelCase name of the generated hook (e.g., `useUserCatalog`).
489
+ - `{{componentPath}}`: Relative path to the component file (useful for imports in tests or stories).
490
+ - `{{featureComponentName}}`: The name of the feature component as imported in a route.
491
+ - `{{featureImportPath}}`: The import path for the feature component.
492
+ - `{{layoutName}}`: The name of the layout component being used.
493
+ - `{{layoutImportPath}}`: The import path for the layout component.
494
+ - `{{scriptImportPath}}`: Relative path to the client-side script entry point.
495
+ - `{{componentExtension}}`: The file extension of the component (e.g., `.astro` or `.tsx`).
496
+
497
+ ### Example: Custom Feature Template (`.textor/templates/feature.astro`)
498
+
499
+ ```astro
500
+ ---
501
+ /**
502
+ * @generated by Textor
503
+ * Feature: {{componentName}}
504
+ */
505
+
506
+ interface Props {
507
+ title?: string;
508
+ }
509
+
510
+ const { title = "{{componentName}}" } = Astro.props;
511
+ ---
512
+
513
+ <section class="feature-{{componentName}}">
514
+ <h2>{title}</h2>
515
+ <slot />
516
+ </section>
517
+
518
+ <script src="{{scriptImportPath}}"></script>
394
519
 
395
- Templates use {{variable}} syntax for placeholder replacement.
520
+ <style>
521
+ .feature-{{componentName}} {
522
+ padding: 2rem;
523
+ }
524
+ </style>
525
+ ```
396
526
 
397
527
  ---
398
528