@bagisto-headless/create 1.0.0 → 1.0.2
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 +62 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ const bagistoGradient = gradient("#0041FF", "#5A7CFF");
|
|
|
14
14
|
|
|
15
15
|
async function showBanner() {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
-
figlet.text("Bagisto Headless", { font: "Slant" }, (err, data) => {
|
|
17
|
+
figlet.text("Bagisto Headless eCommerce", { font: "Slant" }, (err, data) => {
|
|
18
18
|
if (err) reject(err);
|
|
19
19
|
console.log("\n" + bagistoGradient.multiline(data));
|
|
20
20
|
resolve();
|
|
@@ -37,44 +37,79 @@ async function installDependencies() {
|
|
|
37
37
|
console.log(bagistoBlue("Installing dependencies...\n"));
|
|
38
38
|
|
|
39
39
|
const start = Date.now();
|
|
40
|
-
const estimatedTime = 70000; // estimated install time (70s)
|
|
41
40
|
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);
|
|
41
|
+
let completed = false;
|
|
51
42
|
|
|
52
43
|
// Start npm install
|
|
53
|
-
const child = execa("npm", ["install"], {
|
|
44
|
+
const child = execa("npm", ["install"], {
|
|
45
|
+
stdio: "pipe",
|
|
46
|
+
env: { ...process.env, NODE_ENV: "production" }
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Track progress based on npm output
|
|
50
|
+
let packageCount = 0;
|
|
51
|
+
let totalPackages = 0;
|
|
52
|
+
|
|
53
|
+
child.stderr.on("data", (chunk) => {
|
|
54
|
+
const str = chunk.toString();
|
|
55
|
+
|
|
56
|
+
// npm outputs progress to stderr
|
|
57
|
+
if (str.includes("packages in")) {
|
|
58
|
+
progress = 95;
|
|
59
|
+
} else if (str.match(/\d+\/\d+/)) {
|
|
60
|
+
// Extract current/total from patterns like "123/456"
|
|
61
|
+
const match = str.match(/(\d+)\/(\d+)/);
|
|
62
|
+
if (match) {
|
|
63
|
+
packageCount = parseInt(match[1]);
|
|
64
|
+
totalPackages = parseInt(match[2]);
|
|
65
|
+
progress = Math.min(90, (packageCount / totalPackages) * 90);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
renderProgress(progress);
|
|
69
|
+
});
|
|
54
70
|
|
|
55
|
-
// If output detected, slightly speed up progress
|
|
56
71
|
child.stdout.on("data", (chunk) => {
|
|
57
72
|
const str = chunk.toString();
|
|
73
|
+
|
|
58
74
|
if (str.includes("added") || str.includes("packages")) {
|
|
59
|
-
progress =
|
|
75
|
+
progress = 95;
|
|
76
|
+
} else if (str.includes("up to date")) {
|
|
77
|
+
progress = 95;
|
|
60
78
|
}
|
|
79
|
+
renderProgress(progress);
|
|
61
80
|
});
|
|
62
81
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
// Smooth animation while waiting
|
|
83
|
+
const interval = setInterval(() => {
|
|
84
|
+
if (!completed && progress < 90) {
|
|
85
|
+
progress = Math.min(progress + 0.5, 85);
|
|
86
|
+
renderProgress(progress);
|
|
87
|
+
}
|
|
88
|
+
}, 200);
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await child;
|
|
92
|
+
completed = true;
|
|
93
|
+
clearInterval(interval);
|
|
94
|
+
renderProgress(100);
|
|
95
|
+
console.log("\n");
|
|
96
|
+
const elapsedSec = ((Date.now() - start) / 1000).toFixed(1);
|
|
97
|
+
console.log(chalk.gray(`⏱ Completed in ${elapsedSec}s\n`));
|
|
98
|
+
} catch (error) {
|
|
99
|
+
clearInterval(interval);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
69
102
|
}
|
|
70
103
|
|
|
71
|
-
async function promptEnvVariables() {
|
|
104
|
+
async function promptEnvVariables(projectName) {
|
|
72
105
|
const rl = readline.createInterface({
|
|
73
106
|
input: process.stdin,
|
|
74
107
|
output: process.stdout,
|
|
75
108
|
});
|
|
76
109
|
|
|
77
110
|
const questions = [
|
|
111
|
+
{ key: "NEXT_PUBLIC_API_URL", message: "Enter NEXT_PUBLIC_API_URL:" },
|
|
112
|
+
{ key: "NEXT_PUBLIC_SITE_NAME", message: "Enter NEXT_PUBLIC_SITE_NAME:", default: projectName },
|
|
78
113
|
{ key: "NEXTAUTH_URL", message: "Enter NEXTAUTH_URL:" },
|
|
79
114
|
{ key: "IMAGE_DOMAIN", message: "Enter IMAGE_DOMAIN:" },
|
|
80
115
|
{ key: "BAGISTO_STORE_DOMAIN", message: "Enter BAGISTO_STORE_DOMAIN:" },
|
|
@@ -90,16 +125,18 @@ async function promptEnvVariables() {
|
|
|
90
125
|
const answers = {};
|
|
91
126
|
|
|
92
127
|
for (const q of questions) {
|
|
93
|
-
|
|
94
|
-
|
|
128
|
+
const prompt = q.default ? `${q.message} (default: ${q.default}) ` : `${q.message} `;
|
|
129
|
+
const answer = await new Promise((resolve) => {
|
|
130
|
+
rl.question(prompt, (input) => resolve(input.trim()));
|
|
95
131
|
});
|
|
132
|
+
answers[q.key] = answer || q.default || "";
|
|
96
133
|
}
|
|
97
134
|
|
|
98
135
|
rl.close();
|
|
99
136
|
|
|
100
137
|
// Write to .env.local
|
|
101
138
|
const envLines = Object.entries(answers).map(([k, v]) => `${k}=${v}`);
|
|
102
|
-
fs.
|
|
139
|
+
fs.writeFileSync(".env.local", envLines.join("\n") + "\n");
|
|
103
140
|
|
|
104
141
|
console.log(chalk.green("\n✅ Environment variables saved to .env.local\n"));
|
|
105
142
|
}
|
|
@@ -129,15 +166,10 @@ async function main() {
|
|
|
129
166
|
process.chdir(targetDir);
|
|
130
167
|
fs.rmSync(".git", { recursive: true, force: true });
|
|
131
168
|
|
|
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
169
|
await installDependencies();
|
|
138
170
|
spinner.succeed(bagistoBlue("Dependencies installed successfully!"));
|
|
139
171
|
|
|
140
|
-
await promptEnvVariables();
|
|
172
|
+
await promptEnvVariables(projectName);
|
|
141
173
|
|
|
142
174
|
console.log("\n" + chalk.green("✅ Your project is ready!\n"));
|
|
143
175
|
|