create-message-kit 1.1.7-beta.22 → 1.1.7-beta.24
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +29 -33
- package/package.json +1 -1
package/index.js
CHANGED
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
5
5
|
import { log, outro, text, select } from "@clack/prompts";
|
6
6
|
import { default as fs } from "fs-extra";
|
7
7
|
import { isCancel } from "@clack/prompts";
|
8
|
+
import { detect } from "detect-package-manager";
|
8
9
|
import pc from "picocolors";
|
9
10
|
|
10
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
@@ -15,9 +16,16 @@ const packageJson = JSON.parse(
|
|
15
16
|
);
|
16
17
|
const version = packageJson.version;
|
17
18
|
program
|
18
|
-
.name("
|
19
|
+
.name("message-kit")
|
19
20
|
.description("CLI to initialize projects")
|
20
21
|
.action(async () => {
|
22
|
+
// Add Yarn 4 check at the start of the action
|
23
|
+
const pkgManager = detectPackageManager();
|
24
|
+
if (pkgManager.startsWith("yarn@4")) {
|
25
|
+
log.error("Yarn 4 is not supported. Please use bun, npm, or yarn v1");
|
26
|
+
process.exit(1);
|
27
|
+
}
|
28
|
+
|
21
29
|
log.info(pc.cyan(`Welcome to MessageKit CLI v${version}!`));
|
22
30
|
const coolLogo = `
|
23
31
|
███╗ ███╗███████╗███████╗███████╗ █████╗ ██████╗ ███████╗██╗ ██╗██╗████████╗
|
@@ -32,11 +40,6 @@ Powered by XMTP`;
|
|
32
40
|
|
33
41
|
const { templateType, displayName, destDir } = await gatherProjectInfo();
|
34
42
|
|
35
|
-
console.log("detected package manager", detectPackageManager());
|
36
|
-
|
37
|
-
// Add package.json
|
38
|
-
addPackagejson(destDir, displayName);
|
39
|
-
|
40
43
|
// Create .gitignore
|
41
44
|
createGitignore(destDir);
|
42
45
|
|
@@ -49,7 +52,8 @@ Powered by XMTP`;
|
|
49
52
|
// Wrap up
|
50
53
|
log.success(`Project launched in ${pc.red(destDir)}!`);
|
51
54
|
|
52
|
-
|
55
|
+
// Add package.json
|
56
|
+
addPackagejson(destDir, displayName, pkgManager);
|
53
57
|
|
54
58
|
// Create README.md file
|
55
59
|
createReadme(destDir, templateType, displayName, pkgManager);
|
@@ -62,7 +66,7 @@ Powered by XMTP`;
|
|
62
66
|
|
63
67
|
program.parse(process.argv);
|
64
68
|
|
65
|
-
async function addPackagejson(destDir, name) {
|
69
|
+
async function addPackagejson(destDir, name, pkgManager) {
|
66
70
|
// Create package.json based on the template
|
67
71
|
let packageTemplate = {
|
68
72
|
name: name,
|
@@ -77,12 +81,14 @@ async function addPackagejson(destDir, name) {
|
|
77
81
|
dependencies: {
|
78
82
|
"@xmtp/message-kit": "latest",
|
79
83
|
},
|
84
|
+
devDependencies: {
|
85
|
+
typescript: "^5.4.5",
|
86
|
+
},
|
80
87
|
engines: {
|
81
88
|
node: ">=20",
|
82
89
|
},
|
83
90
|
};
|
84
|
-
|
85
|
-
const pkgManager = detectPackageManager();
|
91
|
+
|
86
92
|
if (pkgManager.startsWith("yarn")) {
|
87
93
|
packageTemplate.packageManager = pkgManager;
|
88
94
|
}
|
@@ -196,31 +202,21 @@ yarn-error.log*
|
|
196
202
|
fs.writeFileSync(resolve(destDir, ".gitignore"), gitignoreContent.trim());
|
197
203
|
}
|
198
204
|
|
199
|
-
function detectPackageManager() {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
npm: "npm",
|
209
|
-
};
|
210
|
-
|
211
|
-
for (const [manager, value] of Object.entries(managers)) {
|
212
|
-
if (userAgent.includes(manager)) {
|
213
|
-
// Extract version for yarn
|
214
|
-
if (manager === "yarn") {
|
215
|
-
const version =
|
216
|
-
userAgent.match(/yarn\/(\d+\.\d+\.\d+)/)?.[1] || "4.5.1";
|
217
|
-
return `${value}@${version}`;
|
218
|
-
}
|
219
|
-
return value;
|
205
|
+
async function detectPackageManager() {
|
206
|
+
try {
|
207
|
+
const pkgManager = await detect();
|
208
|
+
// Still maintain the Yarn 4 check if needed
|
209
|
+
if (
|
210
|
+
pkgManager === "yarn" &&
|
211
|
+
process.env.npm_config_user_agent?.includes("yarn/4")
|
212
|
+
) {
|
213
|
+
return "yarn@4";
|
220
214
|
}
|
215
|
+
return pkgManager;
|
216
|
+
} catch (error) {
|
217
|
+
// Fallback to npm if detection fails
|
218
|
+
return "npm";
|
221
219
|
}
|
222
|
-
|
223
|
-
return "npm";
|
224
220
|
}
|
225
221
|
|
226
222
|
function kebabcase(str) {
|