@kosdev-code/kos-ui-cli 3.0.2 → 3.0.4

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/lib/cli.mjs +19 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosdev-code/kos-ui-cli",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "bin": {
5
5
  "kosui": "./src/lib/cli.mjs"
6
6
  },
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "kos": {
23
23
  "build": {
24
- "gitHash": "c361188e6e049be5caaf953b41a50d2e6e12786d"
24
+ "gitHash": "72d98dfab1881358c7b2746f3aadfc50fb9843aa"
25
25
  }
26
26
  },
27
27
  "publishConfig": {
package/src/lib/cli.mjs CHANGED
@@ -3,6 +3,7 @@ import chalk from "chalk";
3
3
  import figlet from "figlet";
4
4
  import minimist from "minimist";
5
5
  import nodePlop from "node-plop";
6
+ import { createRequire } from "node:module";
6
7
  import path, { dirname } from "node:path";
7
8
  import { fileURLToPath } from "node:url";
8
9
  import { clearCache } from "./utils/cache.mjs";
@@ -43,11 +44,25 @@ if (hasQuiet) {
43
44
  const __dirname = dirname(fileURLToPath(import.meta.url));
44
45
  const configPath = path.join(__dirname, "plopfile.mjs");
45
46
 
46
- // Point codegen-core's template resolver to the templates bundled with this CLI.
47
- // Required because template-resolver.ts uses __dirname (a CJS global) which is
48
- // undefined when its code is bundled into an ESM generator bundle.
47
+ // Load .env.local from the project the CLI is run in, so developers can set
48
+ // KOS_TEMPLATE_BASE_DIR (and other CLI env) per-project without exporting in the
49
+ // shell. Uses Node's native loader (no dotenv dependency); a real shell env var
50
+ // still takes precedence, and a missing file is a no-op.
51
+ try {
52
+ process.loadEnvFile(path.resolve(process.cwd(), ".env.local"));
53
+ } catch {
54
+ // No .env.local in cwd — nothing to load.
55
+ }
56
+
57
+ // Point codegen-core's template resolver at the installed @kosdev-code/kos-codegen-core
58
+ // package, which is the single source of truth for templates (it publishes them under
59
+ // its own templates/ dir). KOS_TEMPLATE_BASE_DIR is required because template-resolver.ts
60
+ // relies on __dirname, which is undefined once codegen-core is bundled into an ESM bundle.
49
61
  if (!process.env.KOS_TEMPLATE_BASE_DIR) {
50
- process.env.KOS_TEMPLATE_BASE_DIR = path.resolve(__dirname, "../..");
62
+ const require = createRequire(import.meta.url);
63
+ process.env.KOS_TEMPLATE_BASE_DIR = dirname(
64
+ require.resolve("@kosdev-code/kos-codegen-core/package.json")
65
+ );
51
66
  }
52
67
 
53
68
  const showBanner =