Skip to content

Commit 4075979

Browse files
committed
feat(cli): add custom template support for init command
Add support for loading templates from GitHub repositories or local paths when initializing LaunchQL workspaces and modules, similar to create-cosmos-app and create-interchain-app patterns. Features: - Load templates from GitHub repositories via --repo option - Load templates from local paths via --template-path option - Specify branch when using GitHub templates via --from-branch option - Automatic template type detection (workspace vs module) - Support for both boilerplates root directory and direct template paths Changes: - Add loadTemplates() function in @launchql/templatizer package - Add TemplateSource interface for template configuration - Update init command to support new template options - Update LaunchQLPackage.initModule() to accept templateSource parameter - Improve makeTemplates.ts path handling with environment variable support - Add comprehensive test coverage for template loading scenarios - Update CLI documentation (README.md and AGENTS.md) Technical notes: - GitHub templates are cloned to temporary directories and cleaned up Fixes: Template loading functionality for custom boilerplates
1 parent 1666101 commit 4075979

11 files changed

Lines changed: 604 additions & 41 deletions

File tree

packages/cli/AGENTS.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ lql init --workspace # Initialize workspace
130130
lql init # Initialize module (in workspace)
131131
```
132132

133+
**Template Options:**
134+
- `--repo <repo>` - Use templates from GitHub repository (e.g., `owner/repo`)
135+
- `--template-path <path>` - Use templates from local path
136+
- `--from-branch <branch>` - Specify branch when using `--repo` (default: `main`)
137+
138+
**Examples:**
139+
```bash
140+
lql init --workspace --repo launchql/launchql
141+
lql init --workspace --template-path ./custom-templates
142+
lql init --repo owner/repo --from-branch develop
143+
```
144+
145+
**Implementation:**
146+
- Supports loading templates from GitHub repositories or local paths
147+
- Automatically detects template type (workspace vs module)
148+
- Uses `loadTemplates()` from `@launchql/templatizer` to load custom templates
149+
133150
### 3. Server Command
134151
**File:** `src/commands/server.ts`
135152
**Purpose:** Start GraphQL development server with hot-reload
@@ -318,7 +335,7 @@ try {
318335
### Development Commands
319336
| Command | Purpose | Key Options |
320337
|---------|---------|-------------|
321-
| `init` | Initialize workspace/module | `--workspace` |
338+
| `init` | Initialize workspace/module | `--workspace`, `--repo`, `--template-path`, `--from-branch` |
322339
| `server` | Start development server | `--port`, `--no-postgis` |
323340
| `explorer` | Launch GraphiQL explorer | `--origin` |
324341

packages/cli/README.md

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LaunchQL CLI is a comprehensive command-line tool that transforms your PostgreSQ
88

99
- 🚀 **Database-First Development** - Design your database, get your GraphQL API automatically
1010
- 🔐 **Built-in Security** - Role-based access control and security policies
11-
- 📦 **Module System** - Reusable database modules with dependency management
11+
- 📦 **Module System** - Reusable database modules with dependency management
1212
- 🔄 **Smart Migrations** - Automated migration generation and deployment
1313
- 🛠️ **Developer Experience** - Hot-reload development server with GraphiQL explorer
1414
- 🏗️ **Production Ready** - Deployment plans, versioning, and rollback support
@@ -60,6 +60,7 @@ Visit `http://localhost:5555` to explore your GraphQL API!
6060
### Getting Started
6161

6262
#### `lql init`
63+
6364
Initialize a new LaunchQL workspace or module.
6465

6566
```bash
@@ -68,11 +69,27 @@ lql init --workspace
6869

6970
# Create a new module (run inside workspace)
7071
lql init
72+
73+
# Use templates from GitHub repository
74+
lql init --workspace --repo owner/repo
75+
lql init --repo owner/repo --from-branch develop
76+
77+
# Use templates from local path
78+
lql init --workspace --template-path ./custom-templates
79+
lql init --template-path ./custom-templates/module
7180
```
7281

82+
**Options:**
83+
84+
- `--workspace` - Initialize workspace instead of module
85+
- `--repo <repo>` - Use templates from GitHub repository (e.g., `owner/repo`)
86+
- `--template-path <path>` - Use templates from local path
87+
- `--from-branch <branch>` - Specify branch when using `--repo` (default: `main`)
88+
7389
### Development
7490

7591
#### `lql server`
92+
7693
Start the GraphQL development server with hot-reload.
7794

7895
```bash
@@ -84,6 +101,7 @@ lql server --port 8080 --no-postgis
84101
```
85102

86103
#### `lql explorer`
104+
87105
Launch GraphiQL explorer for your API.
88106

89107
```bash
@@ -97,6 +115,7 @@ lql explorer --origin http://localhost:3000
97115
### Database Operations
98116

99117
#### `lql deploy`
118+
100119
Deploy your database changes and migrations.
101120

102121
```bash
@@ -114,6 +133,7 @@ lql deploy --fast --no-tx
114133
```
115134

116135
#### `lql verify`
136+
117137
Verify your database state matches expected migrations.
118138

119139
```bash
@@ -125,6 +145,7 @@ lql verify --package mypackage
125145
```
126146

127147
#### `lql revert`
148+
128149
Safely revert database changes.
129150

130151
```bash
@@ -138,13 +159,14 @@ lql revert --to @v1.0.0
138159
### Migration Management
139160

140161
#### `lql migrate`
162+
141163
Comprehensive migration management.
142164

143165
```bash
144166
# Initialize migration tracking
145167
lql migrate init
146168

147-
# Check migration status
169+
# Check migration status
148170
lql migrate status
149171

150172
# List all changes
@@ -157,6 +179,7 @@ lql migrate deps
157179
### Module Management
158180

159181
#### `lql install`
182+
160183
Install LaunchQL modules as dependencies.
161184

162185
```bash
@@ -168,13 +191,15 @@ lql install @launchql/auth @launchql/utils
168191
```
169192

170193
#### `lql extension`
194+
171195
Interactively manage module dependencies.
172196

173197
```bash
174198
lql extension
175199
```
176200

177201
#### `lql tag`
202+
178203
Version your changes with tags.
179204

180205
```bash
@@ -191,13 +216,15 @@ lql tag v1.1.0 --package mypackage --changeName my-change
191216
### Packaging and Distribution
192217

193218
#### `lql plan`
219+
194220
Generate deployment plans for your modules.
195221

196222
```bash
197223
lql plan
198224
```
199225

200226
#### `lql package`
227+
201228
Package your module for distribution.
202229

203230
```bash
@@ -211,13 +238,15 @@ lql package --no-plan
211238
### Utilities
212239

213240
#### `lql export`
241+
214242
Export migrations from existing databases.
215243

216244
```bash
217245
lql export
218246
```
219247

220248
#### `lql kill`
249+
221250
Clean up database connections and optionally drop databases.
222251

223252
```bash
@@ -237,7 +266,7 @@ lql kill --no-drop
237266
mkdir my-app && cd my-app
238267
lql init --workspace
239268

240-
# 2. Create your first module
269+
# 2. Create your first module
241270
lql init
242271

243272
# 3. Add some SQL migrations to sql/ directory
@@ -248,6 +277,31 @@ lql deploy --createdb
248277
lql server
249278
```
250279

280+
### Using Custom Templates
281+
282+
You can use custom templates from GitHub repositories or local paths:
283+
284+
```bash
285+
# Initialize workspace with templates from GitHub
286+
lql init --workspace --repo owner/repo
287+
288+
# Initialize workspace with templates from local path
289+
lql init --workspace --template-path ./my-custom-templates
290+
291+
# Initialize module with custom templates
292+
lql init --template-path ./my-custom-templates
293+
294+
# Use specific branch from GitHub repository
295+
lql init --workspace --repo owner/repo --from-branch develop
296+
```
297+
298+
**Template Structure:**
299+
Custom templates should follow the same structure as the default templates:
300+
301+
- For workspace: `boilerplates/workspace/` directory
302+
- For module: `boilerplates/module/` directory
303+
- Or provide direct path to `workspace/` or `module/` directory
304+
251305
### Working with Existing Projects
252306

253307
```bash
@@ -302,7 +356,7 @@ export PGPASSWORD=password
302356
# Global help
303357
lql --help
304358

305-
# Command-specific help
359+
# Command-specific help
306360
lql deploy --help
307361
lql server -h
308362
```
@@ -312,51 +366,50 @@ lql server -h
312366
Most commands support these global options:
313367

314368
- `--help, -h` - Show help information
315-
- `--version, -v` - Show version information
369+
- `--version, -v` - Show version information
316370
- `--cwd <dir>` - Set working directory
317371

318372
## Related LaunchQL Tooling
319373

320374
### 🧪 Testing
321375

322-
* [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
323-
* [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
324-
* [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
376+
- [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
377+
- [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
378+
- [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
325379

326380
### 🧠 Parsing & AST
327381

328-
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
329-
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
330-
* [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
331-
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
332-
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
333-
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
334-
* [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
382+
- [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
383+
- [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
384+
- [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
385+
- [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
386+
- [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
387+
- [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
388+
- [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
335389

336390
### 🚀 API & Dev Tools
337391

338-
* [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
339-
* [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
392+
- [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
393+
- [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
340394

341395
### 🔁 Streaming & Uploads
342396

343-
* [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
344-
* [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
345-
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
346-
* [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
347-
* [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
348-
* [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
397+
- [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
398+
- [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
399+
- [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
400+
- [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
401+
- [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
402+
- [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
349403

350404
### 🧰 CLI & Codegen
351405

352-
* [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
353-
* [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
354-
* [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
355-
* [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
406+
- [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
407+
- [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
408+
- [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
409+
- [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
356410

357411
## Disclaimer
358412

359413
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
360414

361415
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
362-

0 commit comments

Comments
 (0)