mick-templates 1.1.4 → 1.1.5

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/bin/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { spawn } from "child_process";
3
3
  import { dirname, join } from "path";
4
4
  import { fileURLToPath } from "url";
5
+ import { getUserAgent } from "package-manager-detector";
5
6
 
6
7
  // Get the directory where this script is located
7
8
  const __filename = fileURLToPath(import.meta.url);
@@ -9,8 +10,25 @@ const binDir = dirname(__filename);
9
10
  const projectRoot = join(binDir, "..");
10
11
  const cliPath = join(projectRoot, "src", "index.tsx");
11
12
 
12
- // Use npx to run tsx (it will find tsx from the package dependencies)
13
- const child = spawn("npx", ["tsx", cliPath, ...process.argv.slice(2)], {
13
+ // Detect the package manager agent
14
+ const agent = getUserAgent() ?? "npm";
15
+
16
+ let command;
17
+ let args;
18
+
19
+ if (agent === "bun") {
20
+ command = "bun";
21
+ args = [cliPath, ...process.argv.slice(2)];
22
+ } else {
23
+ // Use the local tsx from the package's node_modules
24
+ const isWin = process.platform === "win32";
25
+ const tsxBin = join(projectRoot, "node_modules", ".bin", "tsx");
26
+ command = isWin ? `${tsxBin}.cmd` : tsxBin;
27
+ args = [cliPath, ...process.argv.slice(2)];
28
+ }
29
+
30
+ // Spawn the command
31
+ const child = spawn(command, args, {
14
32
  stdio: "inherit",
15
33
  cwd: process.cwd(),
16
34
  env: process.env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mick-templates",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "CLI tool for creating projects from templates",
5
5
  "bin": {
6
6
  "mick-templates": "bin/cli.js"
package/src/lib/pm.ts CHANGED
@@ -6,8 +6,7 @@ import { spawn } from "child_process";
6
6
  * Get the current package manager agent.
7
7
  */
8
8
  export function getAgent(): AgentName {
9
- const ua = getUserAgent();
10
- return ua?.name ?? "npm";
9
+ return getUserAgent() ?? "npm";
11
10
  }
12
11
 
13
12
  /**
@@ -16,7 +15,9 @@ export function getAgent(): AgentName {
16
15
  function run(cmd: string, args: string[], cwd: string): Promise<void> {
17
16
  return new Promise((resolve, reject) => {
18
17
  spawn(cmd, args, { cwd, stdio: "inherit" })
19
- .on("close", (code) => (code === 0 ? resolve() : reject(new Error(`Exit ${code}`))))
18
+ .on("close", (code) =>
19
+ code === 0 ? resolve() : reject(new Error(`Exit ${code}`))
20
+ )
20
21
  .on("error", reject);
21
22
  });
22
23
  }
@@ -28,17 +29,21 @@ export async function install(cwd: string): Promise<void> {
28
29
  const agent = getAgent();
29
30
  const resolved = resolveCommand(agent, "install", []);
30
31
  if (!resolved) throw new Error(`Cannot resolve install command for ${agent}`);
31
-
32
+
32
33
  await run(resolved.command, resolved.args, cwd);
33
34
  }
34
35
 
35
36
  /**
36
37
  * Execute a package binary (npx/bunx/etc).
37
38
  */
38
- export async function execute(cwd: string, pkg: string, args: string[]): Promise<void> {
39
+ export async function execute(
40
+ cwd: string,
41
+ pkg: string,
42
+ args: string[]
43
+ ): Promise<void> {
39
44
  const agent = getAgent();
40
45
  const resolved = resolveCommand(agent, "execute", [pkg, ...args]);
41
46
  if (!resolved) throw new Error(`Cannot resolve execute command for ${agent}`);
42
-
47
+
43
48
  await run(resolved.command, resolved.args, cwd);
44
49
  }