@oxog/dockcraft 1.2.0 → 1.3.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/CHANGELOG.md CHANGED
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.0] - 2026-12-02
11
+
12
+ ### Fixed
13
+
14
+ - **`dockcraft init -p 8080` used `8080` as both the port and the preset.** Any
15
+ single-letter option stood for every long option starting with that letter
16
+ (`-p` for `--port` and `--preset`). Short options are now an explicit list
17
+ (`-n --name`, `-s --services`, `-o --output`, `-f --force`, `-y --yes`,
18
+ `-c --config` / `--check`, `-d --dry-run`, `-r --range`, `-j --json`, `-h`, `-v`,
19
+ shown in each command's `--help`), and a letter that could mean several
20
+ options of the command fails with `Option -p is ambiguous: use --preset or --port.`
21
+
22
+ ### Documentation
23
+
24
+ - `.env.example` is written in the Docker Compose `.env` format; the README now
25
+ says so and explains how the npm `dotenv` package reads its double-quoted values
26
+ differently.
27
+
28
+ ## [1.2.1] - 2026-12-02
29
+
30
+ ### Fixed
31
+
32
+ - **`app.command` with a `VAR=value` prefix or a shell builtin produced a CMD
33
+ that could not start.** `NODE_OPTIONS=--max-old-space-size=4096 node dist/index.js`,
34
+ `exec node server.js` or `cd dist ...` were written in exec (JSON) form, where
35
+ Docker runs the first word as a program and no shell is involved. Such commands
36
+ now use the shell form; plain commands keep the exec form.
37
+ - **`.env.example` values containing a single quote and a `$` were interpolated by
38
+ Compose.** They are double-quoted, and `$` was not escaped, so a password such as
39
+ `it's$ecret` was read as `it's` plus the (empty) variable `ecret`. `$` is now
40
+ written as `\$` inside double quotes.
41
+
10
42
  ## [1.2.0] - 2026-12-02
11
43
 
12
44
  ### Changed
@@ -228,6 +260,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
228
260
 
229
261
  ---
230
262
 
263
+ [1.3.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.0
264
+ [1.2.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.1
231
265
  [1.2.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.0
232
266
  [1.1.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.1
233
267
  [1.1.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.0
package/README.md CHANGED
@@ -438,6 +438,16 @@ It lists the same variables the app container gets: `POSTGRES_URL` (also as
438
438
  plugin services, and the `*_HOST`, `*_PORT`, `*_USER`, `*_PASSWORD` and
439
439
  database variables of each service.
440
440
 
441
+ Values are written in the Docker Compose `.env` format: plain values as-is,
442
+ values with spaces or special characters (`#`, `$`, quotes, ...) in single
443
+ quotes (taken literally), and values that contain a single quote or a line
444
+ break in double quotes with `\\`, `"`, `$`, `\n` and `\r` escaped. Compose
445
+ (`docker compose --env-file`, `env_file:`) reads every value back exactly.
446
+ Other loaders differ only for those double-quoted values: the npm `dotenv`
447
+ package, for example, does not unescape `\\`, `\"` or `\$`, so check such
448
+ values (they only occur when a password or other value contains a `'`) if
449
+ your app loads the file with `dotenv`.
450
+
441
451
  ## License
442
452
 
443
453
  MIT
package/dist/cli/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  // src/version.ts
9
- var VERSION = "1.2.0";
9
+ var VERSION = "1.3.0";
10
10
 
11
11
  // src/cli/parser.ts
12
12
  function parseArgs(args) {
@@ -73,17 +73,48 @@ function parseArgs(args) {
73
73
  }
74
74
  return result;
75
75
  }
76
+ var SHORT_ALIASES = {
77
+ help: "h",
78
+ version: "v",
79
+ yes: "y",
80
+ force: "f",
81
+ name: "n",
82
+ services: "s",
83
+ output: "o",
84
+ config: "c",
85
+ "dry-run": "d",
86
+ check: "c",
87
+ range: "r",
88
+ json: "j"
89
+ };
90
+ var COMMAND_OPTIONS = {
91
+ init: ["preset", "name", "port", "services", "output", "force", "yes"],
92
+ generate: ["config", "dry-run", "force", "output"],
93
+ ports: ["check", "range", "json"]
94
+ };
95
+ function ambiguousShortOption(args) {
96
+ const longs = COMMAND_OPTIONS[args.command] ?? [];
97
+ for (const key of [...args.flags, ...args.options.keys()]) {
98
+ if (key.length !== 1 || key === "h" || key === "v") continue;
99
+ if (longs.some((long) => SHORT_ALIASES[long] === key)) continue;
100
+ const candidates = longs.filter((long) => long.startsWith(key));
101
+ if (candidates.length > 1) {
102
+ return `Option -${key} is ambiguous: use ${candidates.map((long) => `--${long}`).join(" or ")}.`;
103
+ }
104
+ }
105
+ return void 0;
106
+ }
76
107
  function hasFlag(args, flag) {
77
108
  if (args.flags.has(flag)) return true;
78
- const firstChar = flag[0];
79
- return firstChar !== void 0 && args.flags.has(firstChar);
109
+ const short = SHORT_ALIASES[flag];
110
+ return short !== void 0 && args.flags.has(short);
80
111
  }
81
112
  function getOption(args, option, defaultValue = "") {
82
113
  const value = args.options.get(option);
83
114
  if (value !== void 0) return value;
84
- const firstChar = option[0];
85
- if (firstChar !== void 0) {
86
- const shortValue = args.options.get(firstChar);
115
+ const short = SHORT_ALIASES[option];
116
+ if (short !== void 0) {
117
+ const shortValue = args.options.get(short);
87
118
  if (shortValue !== void 0) return shortValue;
88
119
  }
89
120
  return defaultValue;
@@ -1472,9 +1503,47 @@ function nodeHealthcheckScript(port, path) {
1472
1503
  }
1473
1504
 
1474
1505
  // src/generators/dockerfile.ts
1506
+ var SHELL_BUILTINS = /* @__PURE__ */ new Set([
1507
+ ".",
1508
+ ":",
1509
+ "!",
1510
+ "alias",
1511
+ "bg",
1512
+ "break",
1513
+ "case",
1514
+ "cd",
1515
+ "command",
1516
+ "continue",
1517
+ "eval",
1518
+ "exec",
1519
+ "exit",
1520
+ "export",
1521
+ "fg",
1522
+ "for",
1523
+ "if",
1524
+ "jobs",
1525
+ "read",
1526
+ "readonly",
1527
+ "return",
1528
+ "set",
1529
+ "shift",
1530
+ "source",
1531
+ "time",
1532
+ "times",
1533
+ "trap",
1534
+ "ulimit",
1535
+ "umask",
1536
+ "unalias",
1537
+ "unset",
1538
+ "until",
1539
+ "wait",
1540
+ "while"
1541
+ ]);
1475
1542
  function dockerCmd(command) {
1476
1543
  const words = command.trim().split(/\s+/);
1477
- if (words.every((word) => /^[\w@%+=:,./-]+$/.test(word))) {
1544
+ const first = words[0] ?? "";
1545
+ const needsShell = SHELL_BUILTINS.has(first) || /^[A-Za-z_]\w*=/.test(first);
1546
+ if (!needsShell && words.every((word) => /^[\w@%+=:,./-]+$/.test(word))) {
1478
1547
  return `CMD ${JSON.stringify(words).replace(/","/g, '", "')}`;
1479
1548
  }
1480
1549
  return `CMD ${command.trim()}`;
@@ -1921,7 +1990,7 @@ function envValue(value) {
1921
1990
  if (!/['\r\n]/.test(value)) {
1922
1991
  return `'${value}'`;
1923
1992
  }
1924
- const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1993
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1925
1994
  return `"${escaped}"`;
1926
1995
  }
1927
1996
  function generateEnvExample(config) {
@@ -2446,13 +2515,13 @@ USAGE:
2446
2515
  dockcraft init [options]
2447
2516
 
2448
2517
  OPTIONS:
2449
- --preset <name> Use a preset configuration
2450
- --name <name> Project name
2451
- --port <port> App port
2452
- --services <list> Comma-separated service list
2453
- --output <dir> Directory to write dockcraft.config.mts to
2454
- --force Overwrite an existing config file
2455
- -y, --yes Skip prompts, use defaults (required without a terminal)
2518
+ --preset <name> Use a preset configuration
2519
+ -n, --name <name> Project name
2520
+ --port <port> App port
2521
+ -s, --services <list> Comma-separated service list
2522
+ -o, --output <dir> Directory to write dockcraft.config.mts to
2523
+ -f, --force Overwrite an existing config file
2524
+ -y, --yes Skip prompts, use defaults (required without a terminal)
2456
2525
  `);
2457
2526
  break;
2458
2527
  case "generate":
@@ -2461,10 +2530,10 @@ USAGE:
2461
2530
  dockcraft generate [options]
2462
2531
 
2463
2532
  OPTIONS:
2464
- --config <file> Config file path (default: first of dockcraft.config.{ts,mts,js,mjs,cjs})
2465
- --dry-run Preview without writing
2466
- --force Overwrite existing files
2467
- --output <dir> Output directory
2533
+ -c, --config <file> Config file path (default: first of dockcraft.config.{ts,mts,js,mjs,cjs})
2534
+ -d, --dry-run Preview without writing
2535
+ -f, --force Overwrite existing files
2536
+ -o, --output <dir> Output directory
2468
2537
  `);
2469
2538
  break;
2470
2539
  case "ports":
@@ -2473,9 +2542,9 @@ USAGE:
2473
2542
  dockcraft ports [options]
2474
2543
 
2475
2544
  OPTIONS:
2476
- --check <ports> Check specific ports (comma-separated)
2477
- --range <start-end> Scan port range
2478
- --json Output as JSON
2545
+ -c, --check <ports> Check specific ports (comma-separated)
2546
+ -r, --range <start-end> Scan port range
2547
+ -j, --json Output as JSON
2479
2548
  `);
2480
2549
  break;
2481
2550
  case "presets":
@@ -2525,6 +2594,12 @@ async function main(cliArgs = process.argv.slice(2)) {
2525
2594
  process.exitCode = 1;
2526
2595
  return;
2527
2596
  }
2597
+ const ambiguous = ambiguousShortOption(args);
2598
+ if (ambiguous) {
2599
+ error(ambiguous);
2600
+ process.exitCode = 1;
2601
+ return;
2602
+ }
2528
2603
  try {
2529
2604
  await handler(args);
2530
2605
  } catch (err) {