tthr 0.0.8 → 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.
- package/dist/index.js +73 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -368,6 +368,14 @@ async function getLatestVersion(packageName) {
|
|
|
368
368
|
return "latest";
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
+
function isPackageManagerInstalled(pm) {
|
|
372
|
+
try {
|
|
373
|
+
execSync(`${pm} --version`, { stdio: "pipe" });
|
|
374
|
+
return true;
|
|
375
|
+
} catch {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
371
379
|
async function initCommand(name, options) {
|
|
372
380
|
const credentials = await requireAuth();
|
|
373
381
|
console.log(chalk3.bold("\n\u26A1 Create a new Tether project\n"));
|
|
@@ -385,6 +393,26 @@ async function initCommand(name, options) {
|
|
|
385
393
|
process.exit(1);
|
|
386
394
|
}
|
|
387
395
|
}
|
|
396
|
+
const pmResponse = await prompts({
|
|
397
|
+
type: "select",
|
|
398
|
+
name: "packageManager",
|
|
399
|
+
message: "Select a package manager:",
|
|
400
|
+
choices: [
|
|
401
|
+
{ title: "npm", value: "npm", description: "Node Package Manager (default)" },
|
|
402
|
+
{ title: "pnpm", value: "pnpm", description: "Fast, disk space efficient package manager" },
|
|
403
|
+
{ title: "yarn", value: "yarn", description: "Fast, reliable, and secure dependency management" },
|
|
404
|
+
{ title: "bun", value: "bun", description: "All-in-one JavaScript runtime and toolkit" }
|
|
405
|
+
],
|
|
406
|
+
initial: 0
|
|
407
|
+
});
|
|
408
|
+
const packageManager = pmResponse.packageManager || "npm";
|
|
409
|
+
if (!isPackageManagerInstalled(packageManager)) {
|
|
410
|
+
console.log(chalk3.red(`
|
|
411
|
+
${packageManager} is not installed on your system.`));
|
|
412
|
+
console.log(chalk3.dim(`Please install ${packageManager} and try again.
|
|
413
|
+
`));
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
388
416
|
let template = options.template;
|
|
389
417
|
if (options.template === "vue") {
|
|
390
418
|
const response = await prompts({
|
|
@@ -436,11 +464,11 @@ async function initCommand(name, options) {
|
|
|
436
464
|
apiKey = data.apiKey;
|
|
437
465
|
spinner.text = `Scaffolding ${template} project...`;
|
|
438
466
|
if (template === "nuxt") {
|
|
439
|
-
await scaffoldNuxtProject(projectName, projectPath, spinner);
|
|
467
|
+
await scaffoldNuxtProject(projectName, projectPath, spinner, packageManager);
|
|
440
468
|
} else if (template === "next") {
|
|
441
|
-
await scaffoldNextProject(projectName, projectPath, spinner);
|
|
469
|
+
await scaffoldNextProject(projectName, projectPath, spinner, packageManager);
|
|
442
470
|
} else if (template === "sveltekit") {
|
|
443
|
-
await scaffoldSvelteKitProject(projectName, projectPath, spinner);
|
|
471
|
+
await scaffoldSvelteKitProject(projectName, projectPath, spinner, packageManager);
|
|
444
472
|
} else {
|
|
445
473
|
await scaffoldVanillaProject(projectName, projectPath, spinner);
|
|
446
474
|
}
|
|
@@ -449,7 +477,7 @@ async function initCommand(name, options) {
|
|
|
449
477
|
spinner.text = "Configuring framework integration...";
|
|
450
478
|
await configureFramework(projectPath, template);
|
|
451
479
|
spinner.text = "Installing Tether packages...";
|
|
452
|
-
await installTetherPackages(projectPath, template);
|
|
480
|
+
await installTetherPackages(projectPath, template, packageManager);
|
|
453
481
|
spinner.text = "Creating demo page...";
|
|
454
482
|
await createDemoPage(projectPath, template);
|
|
455
483
|
spinner.succeed("Project created successfully!");
|
|
@@ -465,9 +493,9 @@ async function initCommand(name, options) {
|
|
|
465
493
|
console.log("Next steps:\n");
|
|
466
494
|
console.log(chalk3.cyan(` cd ${projectName}`));
|
|
467
495
|
if (template === "vanilla") {
|
|
468
|
-
console.log(chalk3.cyan(
|
|
496
|
+
console.log(chalk3.cyan(` ${packageManager} install`));
|
|
469
497
|
}
|
|
470
|
-
console.log(chalk3.cyan(
|
|
498
|
+
console.log(chalk3.cyan(` ${packageManager} run dev`));
|
|
471
499
|
console.log("\n" + chalk3.dim("For more information, visit https://tthr.io/docs\n"));
|
|
472
500
|
} catch (error) {
|
|
473
501
|
spinner.fail("Failed to create project");
|
|
@@ -475,12 +503,25 @@ async function initCommand(name, options) {
|
|
|
475
503
|
process.exit(1);
|
|
476
504
|
}
|
|
477
505
|
}
|
|
478
|
-
|
|
506
|
+
function getPackageRunnerCommand(pm) {
|
|
507
|
+
switch (pm) {
|
|
508
|
+
case "pnpm":
|
|
509
|
+
return "pnpm dlx";
|
|
510
|
+
case "yarn":
|
|
511
|
+
return "yarn dlx";
|
|
512
|
+
case "bun":
|
|
513
|
+
return "bunx";
|
|
514
|
+
default:
|
|
515
|
+
return "npx";
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async function scaffoldNuxtProject(projectName, projectPath, spinner, packageManager) {
|
|
479
519
|
const parentDir = path3.dirname(projectPath);
|
|
520
|
+
const runner = getPackageRunnerCommand(packageManager);
|
|
480
521
|
spinner.stop();
|
|
481
522
|
console.log(chalk3.dim("\nRunning nuxi init...\n"));
|
|
482
523
|
try {
|
|
483
|
-
execSync(
|
|
524
|
+
execSync(`${runner} nuxi@latest init ${projectName} --packageManager ${packageManager} --gitInit false`, {
|
|
484
525
|
cwd: parentDir,
|
|
485
526
|
stdio: "inherit"
|
|
486
527
|
});
|
|
@@ -493,15 +534,17 @@ async function scaffoldNuxtProject(projectName, projectPath, spinner) {
|
|
|
493
534
|
if (error instanceof Error && error.message.includes("package.json missing")) {
|
|
494
535
|
throw error;
|
|
495
536
|
}
|
|
496
|
-
throw new Error(
|
|
537
|
+
throw new Error(`Failed to create Nuxt project. Make sure you have ${packageManager} installed.`);
|
|
497
538
|
}
|
|
498
539
|
}
|
|
499
|
-
async function scaffoldNextProject(projectName, projectPath, spinner) {
|
|
540
|
+
async function scaffoldNextProject(projectName, projectPath, spinner, packageManager) {
|
|
500
541
|
const parentDir = path3.dirname(projectPath);
|
|
542
|
+
const runner = getPackageRunnerCommand(packageManager);
|
|
543
|
+
const pmFlag = packageManager === "npm" ? "--use-npm" : packageManager === "pnpm" ? "--use-pnpm" : packageManager === "yarn" ? "--use-yarn" : "--use-bun";
|
|
501
544
|
spinner.stop();
|
|
502
545
|
console.log(chalk3.dim("\nRunning create-next-app...\n"));
|
|
503
546
|
try {
|
|
504
|
-
execSync(
|
|
547
|
+
execSync(`${runner} create-next-app@latest ${projectName} --typescript --eslint --tailwind --src-dir --app --import-alias "@/*" ${pmFlag}`, {
|
|
505
548
|
cwd: parentDir,
|
|
506
549
|
stdio: "inherit"
|
|
507
550
|
});
|
|
@@ -514,15 +557,16 @@ async function scaffoldNextProject(projectName, projectPath, spinner) {
|
|
|
514
557
|
if (error instanceof Error && error.message.includes("package.json missing")) {
|
|
515
558
|
throw error;
|
|
516
559
|
}
|
|
517
|
-
throw new Error(
|
|
560
|
+
throw new Error(`Failed to create Next.js project. Make sure you have ${packageManager} installed.`);
|
|
518
561
|
}
|
|
519
562
|
}
|
|
520
|
-
async function scaffoldSvelteKitProject(projectName, projectPath, spinner) {
|
|
563
|
+
async function scaffoldSvelteKitProject(projectName, projectPath, spinner, packageManager) {
|
|
521
564
|
const parentDir = path3.dirname(projectPath);
|
|
565
|
+
const runner = getPackageRunnerCommand(packageManager);
|
|
522
566
|
spinner.stop();
|
|
523
567
|
console.log(chalk3.dim("\nRunning sv create...\n"));
|
|
524
568
|
try {
|
|
525
|
-
execSync(
|
|
569
|
+
execSync(`${runner} sv create ${projectName} --template minimal --types ts --no-add-ons --no-install`, {
|
|
526
570
|
cwd: parentDir,
|
|
527
571
|
stdio: "inherit"
|
|
528
572
|
});
|
|
@@ -530,12 +574,17 @@ async function scaffoldSvelteKitProject(projectName, projectPath, spinner) {
|
|
|
530
574
|
throw new Error("SvelteKit project was not created successfully - package.json missing");
|
|
531
575
|
}
|
|
532
576
|
spinner.start();
|
|
577
|
+
spinner.text = "Installing dependencies...";
|
|
578
|
+
execSync(`${packageManager} install`, {
|
|
579
|
+
cwd: projectPath,
|
|
580
|
+
stdio: "pipe"
|
|
581
|
+
});
|
|
533
582
|
} catch (error) {
|
|
534
583
|
spinner.start();
|
|
535
584
|
if (error instanceof Error && error.message.includes("package.json missing")) {
|
|
536
585
|
throw error;
|
|
537
586
|
}
|
|
538
|
-
throw new Error(
|
|
587
|
+
throw new Error(`Failed to create SvelteKit project. Make sure you have ${packageManager} installed.`);
|
|
539
588
|
}
|
|
540
589
|
}
|
|
541
590
|
async function scaffoldVanillaProject(projectName, projectPath, spinner) {
|
|
@@ -980,7 +1029,11 @@ PUBLIC_TETHER_URL=\${TETHER_URL}
|
|
|
980
1029
|
}
|
|
981
1030
|
}
|
|
982
1031
|
}
|
|
983
|
-
|
|
1032
|
+
function getInstallCommand(pm, isDev4 = false) {
|
|
1033
|
+
const devFlag = isDev4 ? pm === "npm" ? "-D" : pm === "yarn" ? "-D" : pm === "pnpm" ? "-D" : "-d" : "";
|
|
1034
|
+
return `${pm} ${pm === "npm" ? "install" : "add"} ${devFlag}`.trim();
|
|
1035
|
+
}
|
|
1036
|
+
async function installTetherPackages(projectPath, template, packageManager) {
|
|
984
1037
|
const [
|
|
985
1038
|
tthrClientVersion,
|
|
986
1039
|
tthrSchemaVersion,
|
|
@@ -1011,11 +1064,13 @@ async function installTetherPackages(projectPath, template) {
|
|
|
1011
1064
|
packages.push(`@tthr/svelte@${tthrSvelteVersion}`);
|
|
1012
1065
|
}
|
|
1013
1066
|
try {
|
|
1014
|
-
|
|
1067
|
+
const installCmd = getInstallCommand(packageManager);
|
|
1068
|
+
const devInstallCmd = getInstallCommand(packageManager, true);
|
|
1069
|
+
execSync(`${installCmd} ${packages.join(" ")}`, {
|
|
1015
1070
|
cwd: projectPath,
|
|
1016
1071
|
stdio: "pipe"
|
|
1017
1072
|
});
|
|
1018
|
-
execSync(
|
|
1073
|
+
execSync(`${devInstallCmd} ${devPackages.join(" ")}`, {
|
|
1019
1074
|
cwd: projectPath,
|
|
1020
1075
|
stdio: "pipe"
|
|
1021
1076
|
});
|