create-puzzmo 1.0.10 → 1.0.12
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/package.json +1 -1
- package/src/index.js +23 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawnSync } from "node:child_process"
|
|
4
|
-
|
|
4
|
+
import { get } from "node:https"
|
|
5
5
|
// Forward all args to `puzzmo game create`
|
|
6
6
|
const args = process.argv.slice(2)
|
|
7
7
|
|
|
8
8
|
// Detect the package manager that invoked this script
|
|
9
9
|
const pm = detectPackageManager()
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
// Resolve the actual latest version from the registry to avoid npm cache staleness
|
|
12
|
+
const version = await fetchLatestVersion("@puzzmo/cli")
|
|
13
|
+
console.log(`Running @puzzmo/cli@${version}...`)
|
|
14
14
|
|
|
15
15
|
// Pass --pm so the CLI knows which package manager to use in generated files
|
|
16
16
|
const extraArgs = args.includes("--pm") ? [] : ["--pm", pm]
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Use npx with the exact version to avoid stale global installs
|
|
19
|
+
const result = spawnSync("npx", [`@puzzmo/cli@${version}`, "game", "create", ...args, ...extraArgs], {
|
|
19
20
|
stdio: "inherit",
|
|
20
21
|
env: process.env,
|
|
21
22
|
})
|
|
@@ -28,3 +29,20 @@ function detectPackageManager() {
|
|
|
28
29
|
if (ua.startsWith("pnpm")) return "pnpm"
|
|
29
30
|
return "npm"
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
/** Fetches the latest version from the npm registry, falls back to "latest" tag */
|
|
34
|
+
function fetchLatestVersion(pkg) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
get(`https://registry.npmjs.org/${pkg}/latest`, (res) => {
|
|
37
|
+
let data = ""
|
|
38
|
+
res.on("data", (chunk) => (data += chunk))
|
|
39
|
+
res.on("end", () => {
|
|
40
|
+
try {
|
|
41
|
+
resolve(JSON.parse(data).version)
|
|
42
|
+
} catch {
|
|
43
|
+
resolve("latest")
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}).on("error", () => resolve("latest"))
|
|
47
|
+
})
|
|
48
|
+
}
|