code-brick 0.1.0

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 ADDED
@@ -0,0 +1,454 @@
1
+ # 🧱 Brick CLI
2
+
3
+ A **framework-agnostic** CLI tool for managing reusable code templates. Stop copy-pasting code between projects — save it once, use it everywhere.
4
+
5
+ ## The Problem
6
+
7
+ Every developer has faced this workflow:
8
+
9
+ 1. Create a new project (`nest new my-app`)
10
+ 2. Open an existing project with code you want to reuse
11
+ 3. Manually copy-paste files (auth module, pagination utils, config files)
12
+ 4. Adjust imports, fix paths, install missing dependencies
13
+ 5. **Repeat for every new project**
14
+
15
+ **Brick eliminates steps 2-4 entirely.**
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ # Install globally via npm
21
+ npm install -g code-brick
22
+
23
+ # Or with yarn
24
+ yarn global add code-brick
25
+
26
+ # Or with pnpm
27
+ pnpm add -g code-brick
28
+
29
+ # Or with bun
30
+ bun add -g code-brick
31
+ ```
32
+
33
+ After installation, the `brick` command will be available globally:
34
+
35
+ ```bash
36
+ brick --version
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```bash
42
+ # 1. Initialize brick (one-time setup)
43
+ brick init
44
+
45
+ # 2. Save a folder as a reusable template
46
+ brick save my-auth ./src/auth --description "JWT authentication module"
47
+
48
+ # 3. View your saved templates
49
+ brick list
50
+
51
+ # 4. Apply a template to a new project
52
+ cd ~/new-project
53
+ brick apply my-auth ./src/auth
54
+ ```
55
+
56
+ ## Commands
57
+
58
+ ### `brick init`
59
+
60
+ Initialize Brick on your system. Creates the storage directory at `~/.codebrick/`.
61
+
62
+ ```bash
63
+ brick init
64
+ ```
65
+
66
+ ### `brick save <name> [path]`
67
+
68
+ Save a folder as a reusable template.
69
+
70
+ ```bash
71
+ # Save current directory
72
+ brick save my-template
73
+
74
+ # Save a specific path
75
+ brick save nestjs-auth ./src/auth
76
+
77
+ # With options
78
+ brick save nestjs-auth ./src/auth \
79
+ --description "JWT authentication for NestJS" \
80
+ --tags auth,jwt,nestjs \
81
+ --detect-deps
82
+ ```
83
+
84
+ **Options:**
85
+
86
+ - `-d, --description <desc>` — Template description
87
+ - `-t, --tags <tags>` — Comma-separated tags
88
+ - `--include <patterns>` — Glob patterns to include
89
+ - `--exclude <patterns>` — Glob patterns to exclude
90
+ - `--detect-deps` — Auto-detect dependencies from imports
91
+
92
+ ### `brick list`
93
+
94
+ List all saved templates.
95
+
96
+ ```bash
97
+ brick list
98
+
99
+ # Filter by type
100
+ brick list --local
101
+ brick list --remote
102
+
103
+ # Filter by tag
104
+ brick list --tag auth
105
+
106
+ # Detailed view
107
+ brick list --detailed
108
+ ```
109
+
110
+ **Output:**
111
+
112
+ ```
113
+ # Name Type Files Description
114
+ ─────────────────────────────────────────────────────────────────────
115
+ 0 nestjs-auth local 5 JWT authentication module
116
+ 1 react-modal local 3 Animated modal with backdrop
117
+ 2 docker-dev local 4 Docker Compose dev setup
118
+
119
+ 3 templates (3 local, 0 remote)
120
+ ```
121
+
122
+ > 💡 **Tip:** Use the index number (`0`, `1`, `2`) instead of the full name in any command!
123
+
124
+ ### `brick tree <name|index>`
125
+
126
+ Display the file structure of a template.
127
+
128
+ ```bash
129
+ # By name
130
+ brick tree nestjs-auth
131
+
132
+ # By index
133
+ brick tree 0
134
+
135
+ # With file sizes
136
+ brick tree 0 --size
137
+ ```
138
+
139
+ **Output:**
140
+
141
+ ```
142
+ nestjs-auth
143
+ ├── guards/
144
+ │ └── jwt.guard.ts
145
+ ├── strategies/
146
+ │ └── jwt.strategy.ts
147
+ ├── auth.controller.ts
148
+ ├── auth.module.ts
149
+ └── auth.service.ts
150
+
151
+ 5 files, 2 directories
152
+ ```
153
+
154
+ ### `brick apply <name|index> [destination]`
155
+
156
+ Apply a template to your project.
157
+
158
+ ```bash
159
+ # Apply to current directory
160
+ brick apply nestjs-auth
161
+
162
+ # Apply by index
163
+ brick apply 0 ./src/auth
164
+
165
+ # With options
166
+ brick apply 0 --force --latest
167
+ ```
168
+
169
+ **Options:**
170
+
171
+ - `-f, --force` — Overwrite existing files without prompting
172
+ - `--skip-existing` — Skip files that already exist
173
+ - `--dry-run` — Preview changes without writing files
174
+ - `--latest` — Use @latest for all dependency versions
175
+ - `--no-deps` — Skip dependency installation prompts
176
+
177
+ ### `brick info <name|index>`
178
+
179
+ Show detailed information about a template.
180
+
181
+ ```bash
182
+ brick info nestjs-auth
183
+ brick info 0
184
+ ```
185
+
186
+ ### `brick size [name|index]`
187
+
188
+ Show the size of templates.
189
+
190
+ ```bash
191
+ # Show all template sizes
192
+ brick size
193
+
194
+ # Show specific template size
195
+ brick size nestjs-auth
196
+ brick size 0
197
+ ```
198
+
199
+ **Output (all templates):**
200
+
201
+ ```
202
+ # Name Type Files Size
203
+ ─────────────────────────────────────────────────────────────────────
204
+ 0 nestjs-auth local 5 12.4 KB
205
+ 1 react-modal local 3 8.2 KB
206
+ 2 docker-dev local 4 3.1 KB
207
+
208
+ Total: 12 files, 23.7 KB
209
+ ```
210
+
211
+ **Output (single template):**
212
+
213
+ ```
214
+ nestjs-auth
215
+
216
+ Files: 5
217
+ Directories: 2
218
+ Total Size: 12.4 KB
219
+ ```
220
+
221
+ ### `brick add <name|index> <files...>`
222
+
223
+ Add files to an existing template.
224
+
225
+ ```bash
226
+ # Add a single file
227
+ brick add nestjs-auth ./src/auth/dto/login.dto.ts
228
+
229
+ # Add by index
230
+ brick add 0 ./src/auth/dto/*.ts
231
+
232
+ # Add a directory
233
+ brick add 0 ./src/auth/decorators/
234
+ ```
235
+
236
+ ### `brick remove-file <name|index> <files...>`
237
+
238
+ Remove files from a template.
239
+
240
+ ```bash
241
+ brick remove-file nestjs-auth auth.controller.ts
242
+ brick remove-file 0 dto/
243
+ ```
244
+
245
+ ### `brick delete <name|index>`
246
+
247
+ Delete a template entirely.
248
+
249
+ ```bash
250
+ brick delete nestjs-auth
251
+
252
+ # By index
253
+ brick delete 0
254
+
255
+ # Skip confirmation
256
+ brick delete 0 --force
257
+ ```
258
+
259
+ ### `brick clean <name|index>`
260
+
261
+ Remove local/project-specific imports from template files. This makes templates portable by stripping out imports that reference the original project.
262
+
263
+ ```bash
264
+ # Clean a template (auto-detects project name)
265
+ brick clean flutter-clean
266
+
267
+ # By index
268
+ brick clean 0
269
+
270
+ # Preview what will be removed (dry run)
271
+ brick clean 0 --dry-run
272
+
273
+ # Use custom pattern
274
+ brick clean 0 --pattern "package:my_app/"
275
+
276
+ # Also remove external packages (not recommended)
277
+ brick clean 0 --no-keep-external
278
+ ```
279
+
280
+ **Options:**
281
+
282
+ - `-p, --pattern <regex>` — Custom regex pattern to match imports to remove
283
+ - `--dry-run` — Preview changes without modifying files
284
+ - `--no-keep-external` — Also remove external package imports
285
+
286
+ **Example (Flutter/Dart):**
287
+
288
+ Before cleaning:
289
+
290
+ ```dart
291
+ import 'package:my_app/features/auth/login.dart';
292
+ import 'package:my_app/core/utils/helpers.dart';
293
+ import 'package:flutter/material.dart';
294
+ import 'package:go_router/go_router.dart';
295
+ ```
296
+
297
+ After `brick clean flutter-template`:
298
+
299
+ ```dart
300
+ import 'package:flutter/material.dart';
301
+ import 'package:go_router/go_router.dart';
302
+ ```
303
+
304
+ **Supported languages:**
305
+
306
+ | Language | Local Imports Removed | External Imports Kept |
307
+ | --------------- | ---------------------------------- | ---------------------------------- |
308
+ | **Dart/Flutter**| `package:project_name/...` | `package:flutter/`, `package:go_router/`, etc. |
309
+ | **TypeScript/JS** | `./path`, `../path` | `react`, `lodash`, `express`, etc. |
310
+ | **Python** | `from .module`, `from ..` | `from flask`, `import requests` |
311
+ | **Rust** | `use crate::`, `use super::` | `use std::`, external crates |
312
+
313
+ The command auto-detects the project name from `pubspec.yaml`, `package.json`, or `pyproject.toml`.
314
+
315
+ ## Smart Ignore System
316
+
317
+ Brick **automatically ignores** common dependency directories, build outputs, and generated files across all frameworks. This keeps your templates clean and portable.
318
+
319
+ ### Ignored Directories
320
+
321
+ | Framework | Automatically Ignored |
322
+ | ------------- | ------------------------------------------------------------------- |
323
+ | **Node.js** | `node_modules/`, `.npm/`, `.yarn/`, `.pnpm-store/` |
324
+ | **Python** | `__pycache__/`, `.venv/`, `venv/`, `.pytest_cache/`, `.mypy_cache/` |
325
+ | **Flutter** | `.dart_tool/`, `.pub-cache/`, `build/`, `.flutter-plugins*` |
326
+ | **Rust** | `target/` |
327
+ | **Go** | `vendor/` |
328
+ | **Java** | `.gradle/`, `.idea/`, `out/`, `build/` |
329
+ | **iOS** | `Pods/`, `.symlinks/`, `DerivedData/` |
330
+ | **.NET** | `bin/`, `obj/`, `packages/` |
331
+ | **Build** | `dist/`, `build/`, `.next/`, `.nuxt/`, `.output/`, `.vercel/` |
332
+ | **Cache** | `.cache/`, `.temp/`, `.turbo/`, `coverage/` |
333
+ | **VCS** | `.git/`, `.svn/`, `.hg/` |
334
+ | **IDE** | `.idea/`, `.vscode/` (settings, not launch configs) |
335
+
336
+ ### Ignored Files
337
+
338
+ | Category | Files |
339
+ | ------------ | ------------------------------------------------------------------ |
340
+ | **Locks** | `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `Podfile.lock` |
341
+ | **Env** | `.env`, `.env.local`, `.env.production`, `.env.*` |
342
+ | **OS** | `.DS_Store`, `Thumbs.db`, `desktop.ini` |
343
+ | **Logs** | `*.log`, `npm-debug.log*`, `yarn-debug.log*` |
344
+ | **Metadata** | `brick.json` (template metadata) |
345
+
346
+ This means when you save a template, you get **only the source code** — no bloat:
347
+
348
+ ```bash
349
+ # Before smart ignore (hypothetical)
350
+ flutter-app: 1,247 files, 89.2 MB ❌
351
+
352
+ # With smart ignore (actual)
353
+ flutter-app: 42 files, 156 KB ✅
354
+ ```
355
+
356
+ ## Framework Agnostic
357
+
358
+ Brick works with **any language or framework** since it operates at the file level:
359
+
360
+ | Category | Examples |
361
+ | -------------- | ---------------------------------------------------- |
362
+ | Frontend | React, Vue, Angular, Svelte, Solid, Astro |
363
+ | Backend | NestJS, Express, FastAPI, Django, Rails, Spring Boot |
364
+ | Mobile | React Native, Flutter, Swift, Kotlin |
365
+ | Languages | TypeScript, JavaScript, Python, Go, Rust, Java, C# |
366
+ | Infrastructure | Terraform, Pulumi, Docker, Kubernetes configs |
367
+ | Other | Markdown docs, config files, shell scripts |
368
+
369
+ ## Storage Location
370
+
371
+ Templates are stored locally at:
372
+
373
+ ```
374
+ ~/.codebrick/
375
+ ├── config.json # Configuration
376
+ ├── store.json # Template registry
377
+ └── templates/ # Actual template files
378
+ ├── nestjs-auth/
379
+ ├── react-modal/
380
+ └── ...
381
+ ```
382
+
383
+ ## Examples
384
+
385
+ ### Save a NestJS Auth Module
386
+
387
+ ```bash
388
+ # From your existing project with a working auth implementation
389
+ cd ~/projects/my-backend
390
+ brick save nestjs-auth ./src/auth \
391
+ --description "JWT authentication with Passport" \
392
+ --tags nestjs,auth,jwt,passport \
393
+ --detect-deps
394
+ ```
395
+
396
+ ### Apply to a New Project
397
+
398
+ ```bash
399
+ # Create new project
400
+ nest new my-new-api
401
+ cd my-new-api
402
+
403
+ # Apply the auth template (by index or name)
404
+ brick apply 0 ./src/auth
405
+
406
+ # Install dependencies (brick will show you the command)
407
+ npm install @nestjs/jwt @nestjs/passport passport-jwt bcrypt
408
+ ```
409
+
410
+ ### Save React Components
411
+
412
+ ```bash
413
+ brick save react-modal ./src/components/Modal \
414
+ --description "Animated modal with backdrop" \
415
+ --tags react,modal,ui,animation
416
+ ```
417
+
418
+ ### Save Flutter Clean Architecture
419
+
420
+ ```bash
421
+ brick save flutter-clean ./lib \
422
+ --description "Clean architecture with BLoC" \
423
+ --tags flutter,bloc,clean-architecture
424
+ ```
425
+
426
+ ### Save Docker Configs
427
+
428
+ ```bash
429
+ brick save docker-dev ./docker \
430
+ --description "Docker Compose development setup" \
431
+ --tags docker,devops
432
+ ```
433
+
434
+ ### Quick Operations with Index
435
+
436
+ ```bash
437
+ # List templates
438
+ brick list
439
+ # 0 nestjs-auth
440
+ # 1 react-modal
441
+ # 2 flutter-clean
442
+
443
+ # Use index for faster operations
444
+ brick tree 0
445
+ brick info 1
446
+ brick apply 2 ./lib
447
+ brick size 0
448
+ brick clean 2 # Remove local imports
449
+ brick delete 1 --force
450
+ ```
451
+
452
+ ## Contributing
453
+
454
+ Contributions are welcome! Please open an issue or submit a pull request.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node