@bagisto-headless/create 1.0.3 → 1.0.5
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 +45 -46
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -22,81 +22,79 @@ async function showBanner() {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function renderProgress(progress) {
|
|
26
|
-
const width =
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
25
|
+
function renderProgress(progress, status = "Installing") {
|
|
26
|
+
const width = 40;
|
|
27
|
+
const filledChar = "█";
|
|
28
|
+
const emptyChar = "░";
|
|
29
|
+
|
|
30
|
+
const filled = Math.floor((progress / 100) * width);
|
|
31
|
+
const empty = width - filled;
|
|
32
|
+
|
|
33
|
+
const bar = bagistoBlue(filledChar.repeat(filled)) + chalk.gray(emptyChar.repeat(empty));
|
|
34
|
+
|
|
31
35
|
readline.cursorTo(process.stdout, 0);
|
|
32
|
-
|
|
36
|
+
const percentage = chalk.bold(progress.toFixed(0).padStart(3) + "%");
|
|
37
|
+
process.stdout.write(` ${bagistoBlue(status.padEnd(12))} [${bar}] ${percentage} `);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
async function installDependencies() {
|
|
36
41
|
console.log("\n");
|
|
37
|
-
console.log(bagistoBlue("Installing dependencies...\n"));
|
|
38
42
|
|
|
39
|
-
const start = Date.now();
|
|
40
43
|
let progress = 0;
|
|
41
44
|
let completed = false;
|
|
45
|
+
let currentStatus = "Initializing";
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
const child = execa("npm", ["install"], {
|
|
47
|
+
const child = execa("npm", ["install", "--legacy-peer-deps", "--no-audit", "--no-fund"], {
|
|
45
48
|
stdio: "pipe",
|
|
46
|
-
env: { ...process.env
|
|
49
|
+
env: { ...process.env }
|
|
47
50
|
});
|
|
48
51
|
|
|
49
|
-
//
|
|
50
|
-
let packageCount = 0;
|
|
51
|
-
let totalPackages = 0;
|
|
52
|
-
|
|
52
|
+
// Event based progress updates
|
|
53
53
|
child.stderr.on("data", (chunk) => {
|
|
54
|
-
const str = chunk.toString();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
totalPackages = parseInt(match[2]);
|
|
65
|
-
progress = Math.min(90, (packageCount / totalPackages) * 90);
|
|
66
|
-
}
|
|
54
|
+
const str = chunk.toString().toLowerCase();
|
|
55
|
+
if (str.includes("resolving")) {
|
|
56
|
+
currentStatus = "Resolving";
|
|
57
|
+
progress = Math.max(progress, 15);
|
|
58
|
+
} else if (str.includes("extract")) {
|
|
59
|
+
currentStatus = "Extracting";
|
|
60
|
+
progress = Math.max(progress, 45);
|
|
61
|
+
} else if (str.includes("linking")) {
|
|
62
|
+
currentStatus = "Linking";
|
|
63
|
+
progress = Math.max(progress, 75);
|
|
67
64
|
}
|
|
68
|
-
renderProgress(progress);
|
|
65
|
+
renderProgress(progress, currentStatus);
|
|
69
66
|
});
|
|
70
67
|
|
|
71
68
|
child.stdout.on("data", (chunk) => {
|
|
72
69
|
const str = chunk.toString();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
progress = 95;
|
|
76
|
-
} else if (str.includes("up to date")) {
|
|
77
|
-
progress = 95;
|
|
78
|
-
}
|
|
79
|
-
renderProgress(progress);
|
|
70
|
+
if (str.includes("packages")) progress = 95;
|
|
71
|
+
renderProgress(progress, currentStatus);
|
|
80
72
|
});
|
|
81
73
|
|
|
82
|
-
// Smooth
|
|
74
|
+
// Smooth background progress
|
|
83
75
|
const interval = setInterval(() => {
|
|
84
|
-
if (!completed
|
|
85
|
-
progress
|
|
86
|
-
|
|
76
|
+
if (!completed) {
|
|
77
|
+
if (progress < 30) progress += 0.8;
|
|
78
|
+
else if (progress < 60) progress += 0.4;
|
|
79
|
+
else if (progress < 90) progress += 0.1;
|
|
80
|
+
|
|
81
|
+
renderProgress(progress, currentStatus);
|
|
87
82
|
}
|
|
88
|
-
},
|
|
83
|
+
}, 150);
|
|
89
84
|
|
|
90
85
|
try {
|
|
91
86
|
await child;
|
|
92
87
|
completed = true;
|
|
93
88
|
clearInterval(interval);
|
|
94
|
-
renderProgress(100);
|
|
89
|
+
renderProgress(100, "Done");
|
|
90
|
+
console.log("\n");
|
|
91
|
+
renderProgress(100, "Success");
|
|
95
92
|
console.log("\n");
|
|
96
|
-
const elapsedSec = ((Date.now() - start) / 1000).toFixed(1);
|
|
97
|
-
console.log(chalk.gray(`⏱ Completed in ${elapsedSec}s\n`));
|
|
98
93
|
} catch (error) {
|
|
94
|
+
completed = true;
|
|
99
95
|
clearInterval(interval);
|
|
96
|
+
renderProgress(progress, "Failed");
|
|
97
|
+
console.log("\n");
|
|
100
98
|
throw error;
|
|
101
99
|
}
|
|
102
100
|
}
|
|
@@ -108,10 +106,11 @@ async function promptEnvVariables(projectName) {
|
|
|
108
106
|
});
|
|
109
107
|
|
|
110
108
|
const questions = [
|
|
111
|
-
{ key: "NEXT_PUBLIC_BAGISTO_ENDPOINT", message: "Enter Your
|
|
109
|
+
{ key: "NEXT_PUBLIC_BAGISTO_ENDPOINT", message: "Enter Your Bagisto API URL:" },
|
|
112
110
|
{ key: "NEXT_PUBLIC_APP_URL", message: "Enter Your app URL:" },
|
|
113
111
|
{ key: "NEXT_PUBLIC_NEXT_AUTH_URL", message: "Enter Your auth URL:" },
|
|
114
112
|
{ key: "NEXT_PUBLIC_NEXT_AUTH_SECRET", message: "Enter Your auth secret:" },
|
|
113
|
+
{ key: "NEXT_PUBLIC_BAGISTO_STOREFRONT_KEY", message: "Enter Your Bagisto Storefront Key:" },
|
|
115
114
|
{ key: "COMPANY_NAME", message: "Enter Your company name:", default: "Webkul Software (Registered in India)" },
|
|
116
115
|
];
|
|
117
116
|
|