@oxog/dockcraft 1.0.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.
@@ -0,0 +1,446 @@
1
+ /**
2
+ * Main configuration for dockcraft
3
+ */
4
+ interface DockcraftConfig {
5
+ /** Project/service name */
6
+ name: string;
7
+ /** Optional preset to start from */
8
+ preset?: PresetName;
9
+ /** Application configuration */
10
+ app: AppConfig;
11
+ /** Service definitions */
12
+ services?: ServicesConfig;
13
+ /** Output options */
14
+ output?: OutputConfig;
15
+ /** Custom plugins */
16
+ plugins?: Plugin[];
17
+ }
18
+ /**
19
+ * Application configuration
20
+ */
21
+ interface AppConfig {
22
+ /** Application port (number or 'auto' for automatic assignment) */
23
+ port: number | 'auto';
24
+ /** Node.js Docker image version (default: '20-alpine') */
25
+ node?: string;
26
+ /** Working directory in container (default: '/app') */
27
+ workdir?: string;
28
+ /** Start command (default: 'npm start') */
29
+ command?: string;
30
+ /** Build command for multi-stage builds (default: 'npm run build') */
31
+ buildCommand?: string;
32
+ /** Required environment variable names (for documentation) */
33
+ env?: string[];
34
+ /** Volume mappings */
35
+ volumes?: string[];
36
+ /** Health check endpoint path */
37
+ healthcheck?: string;
38
+ /** Use multi-stage build (default: true) */
39
+ multiStage?: boolean;
40
+ }
41
+ /**
42
+ * Service configuration base
43
+ */
44
+ interface ServiceConfig {
45
+ /** Service image version */
46
+ version?: string;
47
+ /** Port configuration (number, 'auto', or range) */
48
+ port?: number | 'auto' | {
49
+ start: number;
50
+ end?: number;
51
+ };
52
+ /** Environment variables */
53
+ env?: Record<string, string>;
54
+ /** Volume definitions */
55
+ volumes?: string[];
56
+ /** Override command */
57
+ command?: string;
58
+ }
59
+ /**
60
+ * PostgreSQL service configuration
61
+ */
62
+ interface PostgresConfig extends ServiceConfig {
63
+ /** Database name (default: project name) */
64
+ database?: string;
65
+ /** User name (default: 'postgres') */
66
+ user?: string;
67
+ /** Password (default: 'postgres') */
68
+ password?: string;
69
+ }
70
+ /**
71
+ * MySQL service configuration
72
+ */
73
+ interface MySQLConfig extends ServiceConfig {
74
+ /** Database name (default: project name) */
75
+ database?: string;
76
+ /** User name (default: 'root') */
77
+ user?: string;
78
+ /** Password */
79
+ password?: string;
80
+ /** Root password (default: 'root') */
81
+ rootPassword?: string;
82
+ }
83
+ /**
84
+ * MongoDB service configuration
85
+ */
86
+ interface MongoConfig extends ServiceConfig {
87
+ /** Database name (default: project name) */
88
+ database?: string;
89
+ /** User name (default: 'mongo') */
90
+ user?: string;
91
+ /** Password (default: 'mongo') */
92
+ password?: string;
93
+ }
94
+ /**
95
+ * Redis service configuration
96
+ */
97
+ interface RedisConfig extends ServiceConfig {
98
+ /** Password for Redis */
99
+ password?: string;
100
+ }
101
+ /**
102
+ * Custom service configuration
103
+ */
104
+ interface CustomServiceConfig extends ServiceConfig {
105
+ /** Custom Docker image (e.g., 'elasticsearch:8.11.0') */
106
+ image: string;
107
+ }
108
+ /**
109
+ * Service configuration (union type for all supported services)
110
+ */
111
+ type ServiceConfigUnion = PostgresConfig | MySQLConfig | MongoConfig | RedisConfig | CustomServiceConfig;
112
+ /**
113
+ * Services configuration object
114
+ */
115
+ type ServicesConfig = {
116
+ postgres?: PostgresConfig;
117
+ mysql?: MySQLConfig;
118
+ mongo?: MongoConfig;
119
+ redis?: RedisConfig;
120
+ } & Record<string, ServiceConfigUnion | undefined>;
121
+ /**
122
+ * Output file types
123
+ */
124
+ type OutputFile = 'dockerfile' | 'compose' | 'dockerignore' | 'env' | 'scripts' | 'makefile';
125
+ /**
126
+ * Output configuration
127
+ */
128
+ interface OutputConfig {
129
+ /** Output directory (default: './') */
130
+ dir?: string;
131
+ /** Files to generate (default: all) */
132
+ files?: OutputFile[];
133
+ /** Overwrite existing files (default: false) */
134
+ overwrite?: boolean;
135
+ }
136
+ /**
137
+ * Available preset names
138
+ */
139
+ type PresetName = 'express-postgres' | 'express-postgres-redis' | 'express-mongo' | 'express-mongo-redis' | 'express-mysql' | 'express-mysql-redis' | 'fastify-postgres' | 'fastify-postgres-redis' | 'nest-postgres' | 'nest-mongo' | 'node-minimal';
140
+ /**
141
+ * Preset configuration
142
+ */
143
+ interface PresetConfig {
144
+ /** Description of the preset */
145
+ description?: string;
146
+ /** Application configuration overrides */
147
+ app?: Partial<AppConfig>;
148
+ /** Service configuration */
149
+ services?: Partial<ServicesConfig>;
150
+ /** Output configuration */
151
+ output?: Partial<OutputConfig>;
152
+ }
153
+ /**
154
+ * Resolved application configuration
155
+ */
156
+ interface ResolvedAppConfig extends AppConfig {
157
+ port: number;
158
+ node: string;
159
+ workdir: string;
160
+ command: string;
161
+ buildCommand: string;
162
+ env: string[];
163
+ volumes: string[];
164
+ multiStage: boolean;
165
+ }
166
+ /**
167
+ * Resolved service configuration
168
+ */
169
+ interface ResolvedServiceConfig {
170
+ /** Service name */
171
+ name: string;
172
+ /** Docker image */
173
+ image: string;
174
+ /** Container port */
175
+ port: number;
176
+ /** Host port mapping */
177
+ hostPort?: number;
178
+ /** Environment variables */
179
+ env: Record<string, string>;
180
+ /** Volume definitions */
181
+ volumes: string[];
182
+ /** Command override */
183
+ command?: string;
184
+ /** Health check command */
185
+ healthcheck?: string;
186
+ /** Connection string */
187
+ connectionString?: string;
188
+ /** Additional ports to expose */
189
+ ports?: number[];
190
+ }
191
+ /**
192
+ * Resolved configuration
193
+ */
194
+ interface ResolvedConfig {
195
+ /** Project name */
196
+ name: string;
197
+ /** Application configuration */
198
+ app: ResolvedAppConfig;
199
+ /** Service configurations */
200
+ services: Record<string, ResolvedServiceConfig>;
201
+ /** Output configuration */
202
+ output: OutputConfig;
203
+ }
204
+ /**
205
+ * Generator context
206
+ */
207
+ interface GeneratorContext {
208
+ /** Resolved configuration */
209
+ config: ResolvedConfig;
210
+ /** Port mappings (service name -> port) */
211
+ ports: Map<string, number>;
212
+ /** Connection strings (service name -> connection string) */
213
+ strings: Map<string, string>;
214
+ }
215
+ /**
216
+ * Service definition
217
+ */
218
+ interface ServiceDefinition {
219
+ /** Service name */
220
+ name: string;
221
+ /** Docker image (string or function) */
222
+ image: string | ((version: string) => string);
223
+ /** Default port */
224
+ defaultPort: number;
225
+ /** Default version */
226
+ defaultVersion: string;
227
+ /** Default environment variables */
228
+ env?: Record<string, string>;
229
+ /** Default volume definitions */
230
+ volumes?: string[];
231
+ /** Additional ports to expose */
232
+ ports?: number[];
233
+ /** Health check command */
234
+ healthcheck?: string;
235
+ /** Connection string generator */
236
+ connectionString?: (config: ResolvedServiceConfig) => string;
237
+ }
238
+ /**
239
+ * Output generator function
240
+ */
241
+ type OutputGeneratorFunction = (config: ResolvedConfig, context: GeneratorContext) => string;
242
+ /**
243
+ * Output generator
244
+ */
245
+ interface OutputGenerator {
246
+ /** Generator name */
247
+ name: string;
248
+ /** Output filename */
249
+ file: string;
250
+ /** Generate function */
251
+ generate: OutputGeneratorFunction;
252
+ }
253
+ /**
254
+ * Plugin configuration
255
+ */
256
+ interface Plugin {
257
+ /** Plugin name */
258
+ name: string;
259
+ /** Custom services */
260
+ services?: Record<string, ServiceDefinition>;
261
+ /** Custom output generators */
262
+ outputs?: OutputGenerator[];
263
+ }
264
+ /**
265
+ * Port resolution strategy
266
+ */
267
+ type PortStrategy = 'fixed' | 'auto' | 'range';
268
+ /**
269
+ * Port resolution options
270
+ */
271
+ interface PortResolveOptions {
272
+ /** Preferred port (default: 3000) */
273
+ preferred?: number;
274
+ /** Resolution strategy (default: 'auto') */
275
+ strategy?: PortStrategy;
276
+ /** Port range for range strategy */
277
+ range?: [number, number];
278
+ }
279
+ /**
280
+ * Parsed CLI arguments
281
+ */
282
+ interface ParsedArgs {
283
+ /** Command name */
284
+ command: string;
285
+ /** Flags that are set */
286
+ flags: Set<string>;
287
+ /** Options with values */
288
+ options: Map<string, string>;
289
+ /** Positional arguments */
290
+ positionals: string[];
291
+ }
292
+ /**
293
+ * Dockcraft result
294
+ */
295
+ interface DockcraftResult {
296
+ /** Generated files map (filename -> content) */
297
+ files: Map<string, string>;
298
+ /** Files that were written to disk */
299
+ written: string[];
300
+ /** Configuration used */
301
+ config: ResolvedConfig;
302
+ }
303
+ /**
304
+ * Validation error detail item
305
+ */
306
+ interface ValidationErrorItem {
307
+ /** Error code */
308
+ code: string;
309
+ /** Error message */
310
+ message: string;
311
+ /** Path to the invalid value */
312
+ path?: string;
313
+ /** Invalid value */
314
+ value?: unknown;
315
+ }
316
+ /**
317
+ * Validation result
318
+ */
319
+ interface ValidationResult {
320
+ /** Whether validation passed */
321
+ valid: boolean;
322
+ /** Validation errors */
323
+ errors: ValidationErrorItem[];
324
+ }
325
+ /**
326
+ * Base Dockcraft error
327
+ */
328
+ declare class DockcraftError extends Error {
329
+ code: string;
330
+ constructor(message: string, code: string);
331
+ }
332
+ /**
333
+ * Configuration error
334
+ */
335
+ declare class ConfigError extends DockcraftError {
336
+ constructor(message: string, code?: string);
337
+ }
338
+ /**
339
+ * Validation error
340
+ */
341
+ declare class ValidationError extends DockcraftError {
342
+ errors: ValidationErrorItem[];
343
+ constructor(message: string, errors: ValidationErrorItem[], code?: string);
344
+ }
345
+ /**
346
+ * Port conflict error
347
+ */
348
+ declare class PortConflictError extends DockcraftError {
349
+ constructor(port: number, code?: string);
350
+ }
351
+ /**
352
+ * No available port error
353
+ */
354
+ declare class NoPortAvailableError extends DockcraftError {
355
+ constructor(range: [number, number], code?: string);
356
+ }
357
+ /**
358
+ * File write error
359
+ */
360
+ declare class FileWriteError extends DockcraftError {
361
+ constructor(path: string, code?: string);
362
+ }
363
+ /**
364
+ * Preset not found error
365
+ */
366
+ declare class PresetNotFoundError extends DockcraftError {
367
+ constructor(name: string, code?: string);
368
+ }
369
+ /**
370
+ * Service not found error
371
+ */
372
+ declare class ServiceNotFoundError extends DockcraftError {
373
+ constructor(name: string, code?: string);
374
+ }
375
+
376
+ /**
377
+ * Main dockcraft function - generates all Docker files
378
+ */
379
+ declare function dockcraft(config: DockcraftConfig, options?: {
380
+ dryRun?: boolean;
381
+ }): Promise<DockcraftResult>;
382
+ /**
383
+ * Generate configuration object helper
384
+ */
385
+ declare function defineConfig(config: DockcraftConfig): DockcraftConfig;
386
+
387
+ /**
388
+ * Define a service plugin
389
+ */
390
+ declare function defineService(def: ServiceDefinition): Plugin;
391
+
392
+ /**
393
+ * Register a service definition
394
+ */
395
+ declare function registerService(def: ServiceDefinition): void;
396
+ /**
397
+ * Get a service definition by name
398
+ */
399
+ declare function getService(name: string): ServiceDefinition | undefined;
400
+ /**
401
+ * List all registered service names
402
+ */
403
+ declare function listServices(): string[];
404
+
405
+ /**
406
+ * Get a preset configuration by name
407
+ */
408
+ declare function getPreset(name: string): PresetConfig | undefined;
409
+ /**
410
+ * List all registered preset names
411
+ */
412
+ declare function listPresets(): string[];
413
+
414
+ /**
415
+ * Check if a port is available on localhost
416
+ * Returns true if port is available, false if in use
417
+ */
418
+ declare function isPortAvailable(port: number): Promise<boolean>;
419
+ /**
420
+ * Check multiple ports for availability
421
+ * Returns a Map of port -> available (boolean)
422
+ */
423
+ declare function checkPorts(ports: number[]): Promise<Map<number, boolean>>;
424
+ /**
425
+ * Resolve port based on strategy
426
+ */
427
+ declare function resolvePort(options?: PortResolveOptions): Promise<number>;
428
+
429
+ /**
430
+ * Get the default port for a service
431
+ */
432
+ declare function getDefaultPort(service: string): number | undefined;
433
+ /**
434
+ * List all available default ports
435
+ */
436
+ declare function listDefaultPorts(): Record<string, number>;
437
+
438
+ declare function getConnectionString(service: string, config: {
439
+ host: string;
440
+ port: number;
441
+ database?: string;
442
+ user?: string;
443
+ password?: string;
444
+ }): string;
445
+
446
+ export { type AppConfig, ConfigError, type CustomServiceConfig, type DockcraftConfig, DockcraftError, type DockcraftResult, FileWriteError, type GeneratorContext, type MongoConfig, type MySQLConfig, NoPortAvailableError, type OutputConfig, type OutputFile, type OutputGenerator, type OutputGeneratorFunction, type ParsedArgs, type Plugin, PortConflictError, type PortResolveOptions, type PortStrategy, type PostgresConfig, type PresetConfig, type PresetName, PresetNotFoundError, type RedisConfig, type ResolvedConfig, type ResolvedServiceConfig, type ServiceConfig, type ServiceDefinition, type ServiceDefinition as ServiceDefinitionType, ServiceNotFoundError, type ServicesConfig, ValidationError, ValidationError as ValidationErrorClass, type ValidationResult, checkPorts, defineConfig, defineService, dockcraft, getConnectionString, getDefaultPort, getPreset, getService, isPortAvailable, listDefaultPorts, listPresets, listServices, registerService, resolvePort };