@oxog/dockcraft 1.3.0 → 1.3.1

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/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.1] - 2026-12-02
11
+
12
+ ### Documentation
13
+ - README examples are run by the test suite (`tests/readme/readme-examples.test.ts`): config
14
+ fragments are type-checked inside `defineConfig()` and generated with, ports are probed against
15
+ an in-memory port table and files are written to a temporary directory; the test fails when a
16
+ README example changes without it.
17
+
10
18
  ## [1.3.0] - 2026-12-02
11
19
 
12
20
  ### Fixed
@@ -260,6 +268,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
260
268
 
261
269
  ---
262
270
 
271
+ [1.3.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.1
263
272
  [1.3.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.0
264
273
  [1.2.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.1
265
274
  [1.2.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.0
package/dist/cli/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  // src/version.ts
9
- var VERSION = "1.3.0";
9
+ var VERSION = "1.3.1";
10
10
 
11
11
  // src/cli/parser.ts
12
12
  function parseArgs(args) {
@@ -330,7 +330,10 @@ var NoPortAvailableError = class extends DockcraftError {
330
330
  };
331
331
  var FileWriteError = class extends DockcraftError {
332
332
  constructor(path, code = "FILE_WRITE_ERROR", cause) {
333
- super(`Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`, code);
333
+ super(
334
+ `Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`,
335
+ code
336
+ );
334
337
  this.name = "FileWriteError";
335
338
  if (cause !== void 0) {
336
339
  this.cause = cause;
@@ -737,7 +740,9 @@ async function init(args) {
737
740
  }
738
741
  const unknown = selectedServices.filter((s) => !INIT_SERVICES.includes(s));
739
742
  if (unknown.length > 0) {
740
- throw new Error(`Unknown service(s): ${unknown.join(", ")}. Available services: ${INIT_SERVICES.join(", ")}`);
743
+ throw new Error(
744
+ `Unknown service(s): ${unknown.join(", ")}. Available services: ${INIT_SERVICES.join(", ")}`
745
+ );
741
746
  }
742
747
  const configPath = join2(outputDir, INIT_CONFIG_FILE);
743
748
  if (!force && await fileExists(configPath)) {
@@ -972,11 +977,7 @@ async function findAvailablePortInRange(start, end) {
972
977
  return void 0;
973
978
  }
974
979
  async function resolvePort(options = {}) {
975
- const {
976
- preferred = 3e3,
977
- strategy = "auto",
978
- range
979
- } = options;
980
+ const { preferred = 3e3, strategy = "auto", range } = options;
980
981
  switch (strategy) {
981
982
  case "fixed":
982
983
  if (await isPortAvailable(preferred)) {
@@ -1121,7 +1122,11 @@ async function resolveServicePorts(portConfig, containerPort) {
1121
1122
  const endPort = portConfig.end ?? startPort + 100;
1122
1123
  return {
1123
1124
  port: containerPort,
1124
- hostPort: await resolvePort({ preferred: startPort, strategy: "range", range: [startPort, endPort] })
1125
+ hostPort: await resolvePort({
1126
+ preferred: startPort,
1127
+ strategy: "range",
1128
+ range: [startPort, endPort]
1129
+ })
1125
1130
  };
1126
1131
  }
1127
1132
  return { port: containerPort };
@@ -1157,7 +1162,8 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
1157
1162
  if (mongoConfig.database) env.MONGO_INITDB_DATABASE = mongoConfig.database;
1158
1163
  if (mongoConfig.user) env.MONGO_INITDB_ROOT_USERNAME = mongoConfig.user;
1159
1164
  if (mongoConfig.password) env.MONGO_INITDB_ROOT_PASSWORD = mongoConfig.password;
1160
- if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE) env.MONGO_INITDB_DATABASE = projectName;
1165
+ if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
1166
+ env.MONGO_INITDB_DATABASE = projectName;
1161
1167
  } else if (name === "redis") {
1162
1168
  const redisConfig = config;
1163
1169
  if (redisConfig.password) env.REDIS_PASSWORD = redisConfig.password;
@@ -1245,17 +1251,21 @@ async function resolveConfig(config) {
1245
1251
  var VALID_OUTPUT_FILES = ["dockerfile", "compose", "dockerignore", "env", "scripts", "makefile"];
1246
1252
  function validateProjectName(name) {
1247
1253
  if (isProjectName(name)) return [];
1248
- return [{
1249
- code: "INVALID_NAME",
1250
- message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
1251
- path: "name",
1252
- value: name
1253
- }];
1254
+ return [
1255
+ {
1256
+ code: "INVALID_NAME",
1257
+ message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
1258
+ path: "name",
1259
+ value: name
1260
+ }
1261
+ ];
1254
1262
  }
1255
1263
  function validateStringList(value, path) {
1256
1264
  if (value === void 0) return [];
1257
1265
  if (!Array.isArray(value)) {
1258
- return [{ code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }];
1266
+ return [
1267
+ { code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }
1268
+ ];
1259
1269
  }
1260
1270
  return value.filter((item) => !isSingleLine(item) || item === "").map((item) => ({
1261
1271
  code: "INVALID_VALUE",
@@ -1319,7 +1329,12 @@ function validateAppConfig(config) {
1319
1329
  }
1320
1330
  if (config.env !== void 0) {
1321
1331
  if (!Array.isArray(config.env)) {
1322
- errors.push({ code: "INVALID_TYPE", message: `'app.env' must be an array of variable names.`, path: "app.env", value: config.env });
1332
+ errors.push({
1333
+ code: "INVALID_TYPE",
1334
+ message: `'app.env' must be an array of variable names.`,
1335
+ path: "app.env",
1336
+ value: config.env
1337
+ });
1323
1338
  } else {
1324
1339
  for (const envVar of config.env) {
1325
1340
  if (!isEnvVarName(envVar)) {
@@ -1344,12 +1359,14 @@ function validateServicePort(name, port) {
1344
1359
  return [];
1345
1360
  }
1346
1361
  }
1347
- return [{
1348
- code: "INVALID_PORT",
1349
- message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
1350
- path: `services.${name}.port`,
1351
- value: port
1352
- }];
1362
+ return [
1363
+ {
1364
+ code: "INVALID_PORT",
1365
+ message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
1366
+ path: `services.${name}.port`,
1367
+ value: port
1368
+ }
1369
+ ];
1353
1370
  }
1354
1371
  function validateServiceConfig(name, config) {
1355
1372
  const errors = [];
@@ -1392,7 +1409,12 @@ function validateServiceConfig(name, config) {
1392
1409
  errors.push(...validateServicePort(name, svc.port));
1393
1410
  if (svc.env !== void 0) {
1394
1411
  if (typeof svc.env !== "object" || svc.env === null || Array.isArray(svc.env)) {
1395
- errors.push({ code: "INVALID_TYPE", message: `'services.${name}.env' must be an object of strings.`, path: `services.${name}.env`, value: svc.env });
1412
+ errors.push({
1413
+ code: "INVALID_TYPE",
1414
+ message: `'services.${name}.env' must be an object of strings.`,
1415
+ path: `services.${name}.env`,
1416
+ value: svc.env
1417
+ });
1396
1418
  } else {
1397
1419
  for (const [key, value] of Object.entries(svc.env)) {
1398
1420
  if (key === "" || /[=\s]/.test(key) || typeof value !== "string") {
@@ -1406,7 +1428,14 @@ function validateServiceConfig(name, config) {
1406
1428
  }
1407
1429
  }
1408
1430
  }
1409
- for (const key of ["user", "password", "database", "rootPassword", "command", "healthcheck"]) {
1431
+ for (const key of [
1432
+ "user",
1433
+ "password",
1434
+ "database",
1435
+ "rootPassword",
1436
+ "command",
1437
+ "healthcheck"
1438
+ ]) {
1410
1439
  const value = svc[key];
1411
1440
  if (value !== void 0 && typeof value !== "string") {
1412
1441
  errors.push({
@@ -1449,7 +1478,9 @@ function validateConfig(config) {
1449
1478
  if (typeof config !== "object" || config === null) {
1450
1479
  return {
1451
1480
  valid: false,
1452
- errors: [{ code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }]
1481
+ errors: [
1482
+ { code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }
1483
+ ]
1453
1484
  };
1454
1485
  }
1455
1486
  errors.push(...validateProjectName(config.name));
@@ -1476,7 +1507,10 @@ function validateResolvedConfig(config) {
1476
1507
  const usedPorts = /* @__PURE__ */ new Map();
1477
1508
  usedPorts.set(config.app.port, "app");
1478
1509
  for (const [serviceName, serviceConfig] of Object.entries(config.services)) {
1479
- const published = [serviceConfig.hostPort ?? serviceConfig.port, ...serviceConfig.ports ?? []];
1510
+ const published = [
1511
+ serviceConfig.hostPort ?? serviceConfig.port,
1512
+ ...serviceConfig.ports ?? []
1513
+ ];
1480
1514
  for (const port of published) {
1481
1515
  const owner = usedPorts.get(port);
1482
1516
  if (owner !== void 0) {
@@ -2257,7 +2291,8 @@ ${errorMessages}`, errors);
2257
2291
  }
2258
2292
  function isSafeOutputPath(fileName) {
2259
2293
  if (typeof fileName !== "string" || fileName === "" || fileName.includes("\0")) return false;
2260
- if (isAbsolute3(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\")) return false;
2294
+ if (isAbsolute3(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
2295
+ return false;
2261
2296
  const normalized = normalize(fileName.replace(/\\/g, "/"));
2262
2297
  return !normalized.split(/[\\/]/).includes("..") && normalized !== ".";
2263
2298
  }
@@ -2273,11 +2308,11 @@ async function dockcraft(config, options = {}) {
2273
2308
  }
2274
2309
  const context = {
2275
2310
  config: resolved,
2276
- ports: new Map(
2277
- Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])
2278
- ),
2311
+ ports: new Map(Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])),
2279
2312
  strings: new Map(
2280
- Object.entries(resolved.services).filter((entry) => Boolean(entry[1].connectionString)).map(([name, svc]) => [name, svc.connectionString])
2313
+ Object.entries(resolved.services).filter(
2314
+ (entry) => Boolean(entry[1].connectionString)
2315
+ ).map(([name, svc]) => [name, svc.connectionString])
2281
2316
  )
2282
2317
  };
2283
2318
  context.ports.set("app", resolved.app.port);
@@ -2400,12 +2435,15 @@ async function ports(args) {
2400
2435
  if (asJson) {
2401
2436
  json(Object.fromEntries(results));
2402
2437
  } else {
2403
- table(["Port", "Status"], [
2404
- ...Array.from(results.entries()).map(([port, available]) => [
2405
- String(port),
2406
- available ? "\u2713 Available" : "\u2717 In use"
2407
- ])
2408
- ]);
2438
+ table(
2439
+ ["Port", "Status"],
2440
+ [
2441
+ ...Array.from(results.entries()).map(([port, available]) => [
2442
+ String(port),
2443
+ available ? "\u2713 Available" : "\u2717 In use"
2444
+ ])
2445
+ ]
2446
+ );
2409
2447
  }
2410
2448
  return;
2411
2449
  }
@@ -2414,7 +2452,9 @@ async function ports(args) {
2414
2452
  const start = Number(match?.[1]);
2415
2453
  const end = Number(match?.[2]);
2416
2454
  if (!match || !isPort(start) || !isPort(end) || start > end) {
2417
- throw new Error("Invalid range format. Use: --range START-END with ports 1-65535 (e.g., 3000-3010)");
2455
+ throw new Error(
2456
+ "Invalid range format. Use: --range START-END with ports 1-65535 (e.g., 3000-3010)"
2457
+ );
2418
2458
  }
2419
2459
  const port = await findAvailablePortInRange(start, end);
2420
2460
  if (asJson) {
@@ -2431,9 +2471,10 @@ async function ports(args) {
2431
2471
  json(defaults);
2432
2472
  } else {
2433
2473
  subtitle("Default service ports:");
2434
- table(["Service", "Port"], [
2435
- ...Object.entries(defaults).map(([service, port]) => [service, String(port)])
2436
- ]);
2474
+ table(
2475
+ ["Service", "Port"],
2476
+ [...Object.entries(defaults).map(([service, port]) => [service, String(port)])]
2477
+ );
2437
2478
  }
2438
2479
  }
2439
2480
 
@@ -2443,7 +2484,9 @@ function presets2(args) {
2443
2484
  if (presetName) {
2444
2485
  const preset = getPreset(presetName);
2445
2486
  if (!preset) {
2446
- throw new Error(`Preset '${presetName}' not found. Run "dockcraft presets" to list available presets.`);
2487
+ throw new Error(
2488
+ `Preset '${presetName}' not found. Run "dockcraft presets" to list available presets.`
2489
+ );
2447
2490
  }
2448
2491
  title(`Preset: ${presetName}`);
2449
2492
  if (preset.description) {