catylst 1.0.9 → 1.0.11
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/package.json +1 -1
- package/postinstall.js +46 -24
package/package.json
CHANGED
package/postinstall.js
CHANGED
|
@@ -35,6 +35,21 @@ const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
|
35
35
|
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
36
36
|
const purple = (s) => `\x1b[35m${s}\x1b[0m`;
|
|
37
37
|
|
|
38
|
+
// npm v7+ pipes ALL stdout/stderr from postinstall — nothing reaches the terminal.
|
|
39
|
+
// Writing to /dev/tty bypasses the pipe and goes directly to the user's terminal.
|
|
40
|
+
// Falls back to stderr if /dev/tty is unavailable (CI, Windows, non-TTY shells).
|
|
41
|
+
let tty = process.stderr;
|
|
42
|
+
try {
|
|
43
|
+
// accessSync throws on CI/Windows where /dev/tty doesn't exist or isn't writable.
|
|
44
|
+
// Only open the stream if the device is confirmed accessible.
|
|
45
|
+
fs.accessSync("/dev/tty", fs.constants.W_OK);
|
|
46
|
+
const t = fs.createWriteStream("/dev/tty");
|
|
47
|
+
t.on("error", () => {}); // suppress errors — fallback already set above
|
|
48
|
+
tty = t;
|
|
49
|
+
} catch (_) {}
|
|
50
|
+
const print = (s) => tty.write(s + "\n");
|
|
51
|
+
const printRaw = (s) => tty.write(s);
|
|
52
|
+
|
|
38
53
|
// ── Tips & jokes shown while cloning / downloading ───────────────────────────
|
|
39
54
|
|
|
40
55
|
const MESSAGES = [
|
|
@@ -70,7 +85,7 @@ function startTips() {
|
|
|
70
85
|
const msg = msgs[tipIndex % msgs.length];
|
|
71
86
|
const kind = msg.startsWith("joke") ? purple("joke ") : cyan("tip ");
|
|
72
87
|
const text = msg.replace(/^(tip|joke)\s+/, "");
|
|
73
|
-
|
|
88
|
+
printRaw(`\r ${kind} ${dim(text)}${" ".repeat(10)}`);
|
|
74
89
|
tipIndex++;
|
|
75
90
|
tipTimer = setTimeout(showNext, 3000);
|
|
76
91
|
}
|
|
@@ -80,15 +95,15 @@ function startTips() {
|
|
|
80
95
|
|
|
81
96
|
function stopTips(finalLine) {
|
|
82
97
|
if (tipTimer) { clearTimeout(tipTimer); tipTimer = null; }
|
|
83
|
-
|
|
98
|
+
printRaw(`\r${finalLine}${" ".repeat(30)}\n`);
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
// ── Header ───────────────────────────────────────────────────────────────────
|
|
87
102
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
103
|
+
print("");
|
|
104
|
+
print(bold(" Catylst KMP Project Generator"));
|
|
105
|
+
print(dim(" ────────────────────────────────────────"));
|
|
106
|
+
print("");
|
|
92
107
|
|
|
93
108
|
// ── 1. Check Java ────────────────────────────────────────────────────────────
|
|
94
109
|
|
|
@@ -97,17 +112,17 @@ function checkJava() {
|
|
|
97
112
|
const output = result.stderr || result.stdout || "";
|
|
98
113
|
const match = output.match(/version "(\d+)/);
|
|
99
114
|
if (!match) {
|
|
100
|
-
|
|
115
|
+
print(yellow(" ✗ Java not found. Install JDK 17+ from https://adoptium.net"));
|
|
101
116
|
process.exit(1);
|
|
102
117
|
}
|
|
103
118
|
const major = parseInt(match[1], 10);
|
|
104
119
|
if (major < 17) {
|
|
105
|
-
|
|
120
|
+
print(
|
|
106
121
|
yellow(` ✗ JDK 17+ required (found ${major}). Install from https://adoptium.net`)
|
|
107
122
|
);
|
|
108
123
|
process.exit(1);
|
|
109
124
|
}
|
|
110
|
-
|
|
125
|
+
print(green(` ✓ Java ${major}`));
|
|
111
126
|
}
|
|
112
127
|
|
|
113
128
|
// ── 2. Clone / update template ───────────────────────────────────────────────
|
|
@@ -129,7 +144,7 @@ function setupTemplate() {
|
|
|
129
144
|
stopTips(yellow(" ⚠ Could not update template (offline?). Using existing."));
|
|
130
145
|
}
|
|
131
146
|
} else {
|
|
132
|
-
|
|
147
|
+
printRaw(dim(" ↓ Cloning template — hang tight...\n"));
|
|
133
148
|
startTips();
|
|
134
149
|
fs.rmSync(TEMPLATE_DIR, { recursive: true, force: true });
|
|
135
150
|
const result = spawnSync(
|
|
@@ -140,8 +155,8 @@ function setupTemplate() {
|
|
|
140
155
|
if (result.status !== 0) {
|
|
141
156
|
stopTips("");
|
|
142
157
|
const msg = result.stderr ? result.stderr.toString().trim() : "unknown error";
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
print(yellow(" ✗ Failed to clone template. Is git installed?"));
|
|
159
|
+
print(dim(` ${msg}`));
|
|
145
160
|
process.exit(1);
|
|
146
161
|
}
|
|
147
162
|
stopTips(green(" ✓ Template ready"));
|
|
@@ -170,12 +185,12 @@ function downloadJar() {
|
|
|
170
185
|
);
|
|
171
186
|
if (fs.existsSync(localJar)) {
|
|
172
187
|
fs.copyFileSync(localJar, JAR_PATH);
|
|
173
|
-
|
|
188
|
+
print(green(" ✓ Using local build"));
|
|
174
189
|
return Promise.resolve();
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
return new Promise((resolve, reject) => {
|
|
178
|
-
|
|
193
|
+
printRaw(dim(" ↓ Downloading CLI — almost there...\n"));
|
|
179
194
|
startTips();
|
|
180
195
|
|
|
181
196
|
// Write to a temp file first — atomic rename prevents race conditions
|
|
@@ -220,7 +235,7 @@ function downloadJar() {
|
|
|
220
235
|
|
|
221
236
|
const digest = hash.digest("hex");
|
|
222
237
|
stopTips(green(" ✓ CLI ready"));
|
|
223
|
-
|
|
238
|
+
print(dim(` SHA-256: ${digest}`));
|
|
224
239
|
resolve();
|
|
225
240
|
});
|
|
226
241
|
});
|
|
@@ -249,13 +264,20 @@ function downloadJar() {
|
|
|
249
264
|
setupTemplate();
|
|
250
265
|
await downloadJar();
|
|
251
266
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
print("");
|
|
268
|
+
print(dim(" ────────────────────────────────────────"));
|
|
269
|
+
print(" " + green(bold("All done!")) + " Start your project:");
|
|
270
|
+
print("");
|
|
271
|
+
print(" " + cyan("catylst --interactive"));
|
|
272
|
+
print("");
|
|
273
|
+
print(" " + dim("Or non-interactive:"));
|
|
274
|
+
print(" " + dim("catylst --package com.example.app --name MyApp"));
|
|
275
|
+
print("");
|
|
276
|
+
|
|
277
|
+
// The /dev/tty WriteStream holds the event loop open after all output is
|
|
278
|
+
// written, making the process appear to hang. Close it so the process exits
|
|
279
|
+
// on its own without npm having to send SIGINT.
|
|
280
|
+
if (tty !== process.stderr) {
|
|
281
|
+
tty.end(() => process.exit(0));
|
|
282
|
+
}
|
|
261
283
|
})();
|