@bagisto-headless/create 1.0.0

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "kiroAgent.configureMCP": "Disabled"
3
+ }
package/index.js ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ import figlet from "figlet";
3
+ import gradient from "gradient-string";
4
+ import chalk from "chalk";
5
+ import { execa } from "execa";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import ora from "ora";
9
+ import readline from "readline";
10
+
11
+ const spinner = ora();
12
+ const bagistoBlue = chalk.hex("#0041FF");
13
+ const bagistoGradient = gradient("#0041FF", "#5A7CFF");
14
+
15
+ async function showBanner() {
16
+ return new Promise((resolve, reject) => {
17
+ figlet.text("Bagisto Headless", { font: "Slant" }, (err, data) => {
18
+ if (err) reject(err);
19
+ console.log("\n" + bagistoGradient.multiline(data));
20
+ resolve();
21
+ });
22
+ });
23
+ }
24
+
25
+ function renderProgress(progress) {
26
+ const width = process.stdout.columns - 20;
27
+ const barLength = Math.max(10, Math.floor(width / 3));
28
+ const filled = Math.floor((progress / 100) * barLength);
29
+ const empty = barLength - filled;
30
+ const bar = "█".repeat(filled) + "░".repeat(empty);
31
+ readline.cursorTo(process.stdout, 0);
32
+ process.stdout.write(bagistoBlue(`[${bar}] ${progress.toFixed(0)}%`));
33
+ }
34
+
35
+ async function installDependencies() {
36
+ console.log("\n");
37
+ console.log(bagistoBlue("Installing dependencies...\n"));
38
+
39
+ const start = Date.now();
40
+ const estimatedTime = 70000; // estimated install time (70s)
41
+ let progress = 0;
42
+
43
+ // Animate progress bar smoothly until process finishes
44
+ const interval = setInterval(() => {
45
+ const elapsed = Date.now() - start;
46
+ const speed = 0.02; // smoothing factor
47
+ const target = Math.min(100, (elapsed / estimatedTime) * 100);
48
+ progress += (target - progress) * speed;
49
+ renderProgress(progress);
50
+ }, 80);
51
+
52
+ // Start npm install
53
+ const child = execa("npm", ["install"], { stdio: "pipe" });
54
+
55
+ // If output detected, slightly speed up progress
56
+ child.stdout.on("data", (chunk) => {
57
+ const str = chunk.toString();
58
+ if (str.includes("added") || str.includes("packages")) {
59
+ progress = Math.min(progress + 3, 95);
60
+ }
61
+ });
62
+
63
+ await child;
64
+ clearInterval(interval);
65
+ renderProgress(100);
66
+ console.log("\n");
67
+ const elapsedSec = ((Date.now() - start) / 1000).toFixed(1);
68
+ console.log(chalk.gray(`⏱ Completed in ${elapsedSec}s\n`));
69
+ }
70
+
71
+ async function promptEnvVariables() {
72
+ const rl = readline.createInterface({
73
+ input: process.stdin,
74
+ output: process.stdout,
75
+ });
76
+
77
+ const questions = [
78
+ { key: "NEXTAUTH_URL", message: "Enter NEXTAUTH_URL:" },
79
+ { key: "IMAGE_DOMAIN", message: "Enter IMAGE_DOMAIN:" },
80
+ { key: "BAGISTO_STORE_DOMAIN", message: "Enter BAGISTO_STORE_DOMAIN:" },
81
+ { key: "BAGISTO_SESSION", message: "Enter BAGISTO_SESSION:" },
82
+ { key: "COMPANY_NAME", message: "Enter COMPANY_NAME:" },
83
+ { key: "SITE_NAME", message: "Enter SITE_NAME:" },
84
+ { key: "TWITTER_CREATOR", message: "Enter TWITTER_CREATOR:" },
85
+ { key: "TWITTER_SITE", message: "Enter TWITTER_SITE:" },
86
+ { key: "REVALIDATION_DURATION", message: "Enter REVALIDATION_DURATION (seconds):" },
87
+ { key: "NEXTAUTH_SECRET", message: "Enter NEXTAUTH_SECRET:" },
88
+ ];
89
+
90
+ const answers = {};
91
+
92
+ for (const q of questions) {
93
+ answers[q.key] = await new Promise((resolve) => {
94
+ rl.question(`${q.message} `, (answer) => resolve(answer.trim()));
95
+ });
96
+ }
97
+
98
+ rl.close();
99
+
100
+ // Write to .env.local
101
+ const envLines = Object.entries(answers).map(([k, v]) => `${k}=${v}`);
102
+ fs.appendFileSync(".env.local", "\n" + envLines.join("\n") + "\n");
103
+
104
+ console.log(chalk.green("\n✅ Environment variables saved to .env.local\n"));
105
+ }
106
+
107
+ async function main() {
108
+ await showBanner();
109
+
110
+ const args = process.argv.slice(2);
111
+ const projectName = args[0];
112
+
113
+ if (!projectName) {
114
+ console.log(chalk.red("❌ Please specify your project name."));
115
+ console.log(chalk.yellow("\nExample usage:"));
116
+ console.log(bagistoBlue(" npx @bagisto-headless/create <your-project-name>\n"));
117
+ process.exit(1);
118
+ }
119
+
120
+ const repo = "https://github.com/bagisto/nextjs-commerce";
121
+ const targetDir = path.resolve(process.cwd(), projectName);
122
+
123
+ console.log(`Creating your ${chalk.bold.hex("#0041FF")(projectName)} storefront with ${bagistoBlue("Bagisto Headless Commerce")}:\n`);
124
+
125
+ spinner.start(bagistoBlue("Cloning repository..."));
126
+ await execa("git", ["clone", "--depth", "1", repo, projectName]);
127
+ spinner.succeed(bagistoBlue("Repository cloned successfully!"));
128
+
129
+ process.chdir(targetDir);
130
+ fs.rmSync(".git", { recursive: true, force: true });
131
+
132
+ const envFile = ".env.local";
133
+ if (!fs.existsSync(envFile)) {
134
+ fs.writeFileSync(envFile, `NEXT_PUBLIC_API_URL=https://demo.bagisto.com/graphql\nNEXT_PUBLIC_SITE_NAME=${projectName}\n`);
135
+ }
136
+
137
+ await installDependencies();
138
+ spinner.succeed(bagistoBlue("Dependencies installed successfully!"));
139
+
140
+ await promptEnvVariables();
141
+
142
+ console.log("\n" + chalk.green("✅ Your project is ready!\n"));
143
+
144
+ console.log(bagistoBlue.bold("Next steps:"));
145
+ console.log(chalk.white(` cd ${projectName}`));
146
+ console.log(chalk.white(" npm run dev\n"));
147
+
148
+ console.log(bagistoBlue.bold("📘 Explore more:"));
149
+ console.log(chalk.white("👉 https://bagisto.com/en/headless-ecommerce/\n"));
150
+
151
+ console.log(bagistoBlue.bold("💻 GitHub:"));
152
+ console.log(chalk.white("👉 https://github.com/bagisto/nextjs-commerce\n"));
153
+
154
+ }
155
+
156
+ main().catch((err) => {
157
+ spinner.fail(chalk.red(`Error: ${err.message}`));
158
+ process.exit(1);
159
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@bagisto-headless/create",
3
+ "version": "1.0.0",
4
+ "description": "Create a new Bagisto Headless Commerce project from the official Next.js template.",
5
+ "keywords": [
6
+ "bagisto",
7
+ "headless",
8
+ "commerce",
9
+ "create-app",
10
+ "nextjs"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Bagisto",
14
+ "type": "module",
15
+ "main": "index.js",
16
+ "bin": {
17
+ "create-bagisto-headless": "index.js"
18
+ },
19
+ "scripts": {
20
+ "test": "echo \"Error: no test specified\" && exit 1"
21
+ },
22
+ "dependencies": {
23
+ "chalk": "^5.6.2",
24
+ "execa": "^8.0.1",
25
+ "figlet": "^1.9.3",
26
+ "gradient-string": "^3.0.0",
27
+ "ora": "^8.2.0",
28
+ "readline": "^1.3.0"
29
+ },
30
+ "devDependencies": {}
31
+ }