catylst 1.0.9 → 1.0.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +39 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catylst",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Generate customized Kotlin Multiplatform projects with an interactive wizard",
5
5
  "keywords": [
6
6
  "kotlin",
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
- process.stderr.write(`\r ${kind} ${dim(text)}${" ".repeat(10)}`);
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
- process.stderr.write(`\r${finalLine}${" ".repeat(30)}\n`);
98
+ printRaw(`\r${finalLine}${" ".repeat(30)}\n`);
84
99
  }
85
100
 
86
101
  // ── Header ───────────────────────────────────────────────────────────────────
87
102
 
88
- process.stderr.write("" + "\n");
89
- process.stderr.write(bold(" Catylst KMP Project Generator") + "\n");
90
- process.stderr.write(dim(" ────────────────────────────────────────") + "\n");
91
- process.stderr.write("" + "\n");
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
- console.error(yellow(" ✗ Java not found. Install JDK 17+ from https://adoptium.net"));
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
- console.error(
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
- process.stderr.write(green(` ✓ Java ${major}`) + "\n");
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
- process.stderr.write(dim(" ↓ Cloning template — hang tight...\n"));
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
- console.error(yellow(" ✗ Failed to clone template. Is git installed?"));
144
- console.error(dim(` ${msg}`));
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
- process.stderr.write(green(" ✓ Using local build") + "\n");
188
+ print(green(" ✓ Using local build"));
174
189
  return Promise.resolve();
175
190
  }
176
191
 
177
192
  return new Promise((resolve, reject) => {
178
- process.stderr.write(dim(" ↓ Downloading CLI — almost there...\n"));
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
- process.stderr.write(dim(` SHA-256: ${digest}`) + "\n");
238
+ print(dim(` SHA-256: ${digest}`));
224
239
  resolve();
225
240
  });
226
241
  });
@@ -249,13 +264,13 @@ function downloadJar() {
249
264
  setupTemplate();
250
265
  await downloadJar();
251
266
 
252
- process.stderr.write("" + "\n");
253
- process.stderr.write(dim(" ────────────────────────────────────────") + "\n");
254
- process.stderr.write(" " + green(bold("All done!")) + " Start your project:" + "\n");
255
- process.stderr.write("" + "\n");
256
- process.stderr.write(" " + cyan("catylst --interactive") + "\n");
257
- process.stderr.write("" + "\n");
258
- process.stderr.write(" " + dim("Or non-interactive:") + "\n");
259
- process.stderr.write(" " + dim("catylst --package com.example.app --name MyApp") + "\n");
260
- process.stderr.write("" + "\n");
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("");
261
276
  })();