@mastrojs/create-mastro 0.0.7 → 0.0.9

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 (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +39 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@ Create a new [Mastro](https://mastrojs.github.io/) project. Usage:
2
2
 
3
3
  Deno:
4
4
 
5
- deno run -A npm:@mastrojs/create-mastro@latest
5
+ deno run --reload -A npm:@mastrojs/create-mastro
6
6
 
7
7
  Node.js
8
8
 
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  //@ts-check
4
3
 
5
4
  /**
@@ -13,13 +12,26 @@
13
12
  import { exec } from "node:child_process";
14
13
  import { createWriteStream } from "node:fs";
15
14
  import fs from "node:fs/promises";
15
+ import { join } from "node:path";
16
16
  import { stdin, stdout } from "node:process";
17
17
  import { createInterface } from "node:readline/promises";
18
18
  import { Readable } from "node:stream";
19
19
 
20
- const runtime = typeof Deno === "object"
21
- ? "deno"
22
- : (process.env.npm_config_user_agent?.startsWith("bun") ? "bun" : "node");
20
+ const userAgent = process.env.npm_config_user_agent;
21
+
22
+ const runtime = (() => {
23
+ if (typeof Deno === "object") {
24
+ return "deno"
25
+ } else if (userAgent?.startsWith("bun/")) {
26
+ // the usual ways to detect Bun don't appear to work in `bun create`
27
+ return "bun";
28
+ } else if (process.argv[2] === "--cloudflare") {
29
+ return "cloudflare";
30
+ } else {
31
+ return "node";
32
+ }
33
+ })();
34
+
23
35
 
24
36
  /**
25
37
  * @param {string} path
@@ -83,13 +95,33 @@ if (dir) {
83
95
  if (unzipSuccess) {
84
96
  await fs.rename(outDir, dir);
85
97
 
86
- const bunOrPnpm = runtime === "bun" ? "bun" : "pnpm";
98
+ const packageManager = (() => {
99
+ switch (userAgent?.split("/")[0]) {
100
+ case "pnpm": return "pnpm";
101
+ case "yarn": return "yarn";
102
+ case "bun": return "bun";
103
+ default: return "npm";
104
+ }
105
+ })();
106
+
107
+ if (packageManager === "npm") {
108
+ try {
109
+ const path = join(dir, "package.json");
110
+ const packageJson = JSON.parse(await fs.readFile(path, { encoding: "utf8" }));
111
+ packageJson.dependencies["@mastrojs/mastro"] = "npm:@jsr/mastrojs__mastro@^0";
112
+ await fs.writeFile(path, JSON.stringify(packageJson, null, 2));
113
+ await fs.writeFile(join(dir, ".npmrc"), "@jsr:registry=https://npm.jsr.io");
114
+ } catch (e) {
115
+ console.error(`Created folder ${dir} but failed to patch it for npm. Please use pnpm instead.`);
116
+ }
117
+ }
118
+
87
119
  const installInstr = runtime === "deno"
88
120
  ? ""
89
- : `\n\nThen install dependencies with: ${bunOrPnpm} install\n`;
121
+ : `\n\nThen install dependencies with: ${packageManager} install\n`;
90
122
  const startInstr = runtime === "deno"
91
123
  ? "deno task start"
92
- : `${bunOrPnpm} run start`;
124
+ : `${packageManager} run start`;
93
125
 
94
126
  const codeStyle = "color: blue";
95
127
  console.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastrojs/create-mastro",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "npm-publish": "deno check && npm publish --access public"