@mastrojs/create-mastro 0.0.6 → 0.0.8
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/index.js +28 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,14 +13,17 @@
|
|
|
13
13
|
import { exec } from "node:child_process";
|
|
14
14
|
import { createWriteStream } from "node:fs";
|
|
15
15
|
import fs from "node:fs/promises";
|
|
16
|
+
import { join } from "node:path";
|
|
16
17
|
import { stdin, stdout } from "node:process";
|
|
17
18
|
import { createInterface } from "node:readline/promises";
|
|
18
19
|
import { Readable } from "node:stream";
|
|
19
20
|
|
|
21
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
22
|
+
|
|
20
23
|
const runtime = typeof Deno === "object"
|
|
21
24
|
? "deno"
|
|
22
|
-
//
|
|
23
|
-
: (
|
|
25
|
+
// the usual ways to detect Bun don't appear to work in `bun create`
|
|
26
|
+
: (userAgent?.startsWith("bun/") ? "bun" : "node");
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* @param {string} path
|
|
@@ -84,13 +87,33 @@ if (dir) {
|
|
|
84
87
|
if (unzipSuccess) {
|
|
85
88
|
await fs.rename(outDir, dir);
|
|
86
89
|
|
|
87
|
-
const
|
|
90
|
+
const packageManager = (() => {
|
|
91
|
+
switch (userAgent?.split("/")[0]) {
|
|
92
|
+
case "pnpm": return "pnpm";
|
|
93
|
+
case "yarn": return "yarn";
|
|
94
|
+
case "bun": return "bun";
|
|
95
|
+
default: return "npm";
|
|
96
|
+
}
|
|
97
|
+
})();
|
|
98
|
+
|
|
99
|
+
if (packageManager === "npm") {
|
|
100
|
+
try {
|
|
101
|
+
const path = join(dir, "package.json");
|
|
102
|
+
const packageJson = JSON.parse(await fs.readFile(path, { encoding: "utf8" }));
|
|
103
|
+
packageJson.dependencies["@mastrojs/mastro"] = "npm:@jsr/mastrojs__mastro@^0";
|
|
104
|
+
await fs.writeFile(path, JSON.stringify(packageJson, null, 2));
|
|
105
|
+
await fs.writeFile(join(dir, ".npmrc"), "@jsr:registry=https://npm.jsr.io");
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(`Created folder ${dir} but failed to patch it for npm. Please use pnpm instead.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
88
111
|
const installInstr = runtime === "deno"
|
|
89
112
|
? ""
|
|
90
|
-
: `\n\nThen install dependencies with: ${
|
|
113
|
+
: `\n\nThen install dependencies with: ${packageManager} install\n`;
|
|
91
114
|
const startInstr = runtime === "deno"
|
|
92
115
|
? "deno task start"
|
|
93
|
-
: `${
|
|
116
|
+
: `${packageManager} run start`;
|
|
94
117
|
|
|
95
118
|
const codeStyle = "color: blue";
|
|
96
119
|
console.log(
|