console2svg 0.6.4 → 0.7.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.
Files changed (2) hide show
  1. package/cli/install.js +61 -24
  2. package/package.json +1 -1
package/cli/install.js CHANGED
@@ -4,6 +4,7 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const https = require('https');
7
+ const { spawnSync } = require('child_process');
7
8
  const { HttpsProxyAgent } = require('https-proxy-agent');
8
9
  const { getProxyForUrl } = require('proxy-from-env');
9
10
 
@@ -38,13 +39,8 @@ if (platform === 'win32') {
38
39
  }
39
40
 
40
41
  const isWin = platform === 'win32';
41
- const ext = isWin ? '.exe' : '';
42
- const fileName = `console2svg-${rid}${ext}`;
43
- const url = `https://github.com/arika0093/console2svg/releases/download/v${version}/${fileName}`;
44
-
45
42
  const distDir = path.join(__dirname, '..', 'dist');
46
- const destPath = path.join(distDir, `console2svg${ext}`);
47
- const tempPath = `${destPath}.tmp`;
43
+ const destPath = path.join(distDir, `console2svg${isWin ? '.exe' : ''}`);
48
44
 
49
45
  if (fs.existsSync(destPath)) {
50
46
  process.exit(0);
@@ -61,21 +57,23 @@ function fail(message, err) {
61
57
  process.exit(1);
62
58
  }
63
59
 
64
- function download(downloadUrl, redirects) {
60
+ function download(downloadUrl, redirects, onFinish) {
65
61
  if (redirects > 5) {
66
62
  fail('console2svg: too many redirects while downloading.');
67
63
  }
68
64
 
69
65
  const proxy = getProxyForUrl(downloadUrl);
70
66
  const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
71
- const url = new URL(downloadUrl);
67
+ const urlObj = new URL(downloadUrl);
68
+
69
+ const tempPath = `${destPath}.tmp`;
72
70
 
73
71
  const request = https.get(
74
72
  {
75
- hostname: url.hostname,
76
- path: url.pathname + url.search,
77
- protocol: url.protocol,
78
- port: url.port,
73
+ hostname: urlObj.hostname,
74
+ path: urlObj.pathname + urlObj.search,
75
+ protocol: urlObj.protocol,
76
+ port: urlObj.port,
79
77
  agent,
80
78
  headers: {
81
79
  'User-Agent': 'console2svg-npm-wrapper',
@@ -85,7 +83,7 @@ function download(downloadUrl, redirects) {
85
83
  (res) => {
86
84
  if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
87
85
  res.resume();
88
- download(res.headers.location, redirects + 1);
86
+ download(res.headers.location, redirects + 1, onFinish);
89
87
  return;
90
88
  }
91
89
 
@@ -99,11 +97,7 @@ function download(downloadUrl, redirects) {
99
97
  file.on('finish', () => {
100
98
  file.close(() => {
101
99
  try {
102
- fs.renameSync(tempPath, destPath);
103
- if (!isWin) {
104
- fs.chmodSync(destPath, 0o755);
105
- }
106
- process.exit(0);
100
+ onFinish(tempPath);
107
101
  } catch (err) {
108
102
  fail('console2svg: failed to finalize download.', err);
109
103
  }
@@ -111,11 +105,11 @@ function download(downloadUrl, redirects) {
111
105
  });
112
106
  file.on('error', (err) => {
113
107
  try {
114
- fs.unlinkSync(tempPath);
115
- } catch {
116
- // ignore
117
- }
118
- fail('console2svg: write failed.', err);
108
+ fs.unlinkSync(tempPath);
109
+ } catch {
110
+ // ignore
111
+ }
112
+ fail('console2svg: write failed.', err);
119
113
  });
120
114
  }
121
115
  );
@@ -125,4 +119,47 @@ function download(downloadUrl, redirects) {
125
119
  });
126
120
  }
127
121
 
128
- download(url, 0);
122
+ if (isWin) {
123
+ // On Windows: download the ffmpeg bundle zip (console2svg.exe + ffmpeg.exe + DLLs)
124
+ const zipFileName = `console2svg-${rid}-ffmpeg.zip`;
125
+ const zipUrl = `https://github.com/arika0093/console2svg/releases/download/v${version}/${zipFileName}`;
126
+
127
+ download(zipUrl, 0, (tempZipPath) => {
128
+ // Escape single quotes in paths for PowerShell single-quoted string literals.
129
+ const psEscape = (p) => p.replace(/'/g, "''");
130
+ // Extract the zip into distDir using PowerShell
131
+ const result = spawnSync(
132
+ 'powershell',
133
+ [
134
+ '-NoProfile',
135
+ '-NonInteractive',
136
+ '-Command',
137
+ `Expand-Archive -LiteralPath '${psEscape(tempZipPath)}' -DestinationPath '${psEscape(distDir)}' -Force`
138
+ ],
139
+ { stdio: 'inherit' }
140
+ );
141
+
142
+ try { fs.unlinkSync(tempZipPath); } catch { /* ignore */ }
143
+
144
+ if (result.status !== 0) {
145
+ fail('console2svg: failed to extract zip bundle.');
146
+ }
147
+
148
+ if (!fs.existsSync(destPath)) {
149
+ fail('console2svg: console2svg.exe not found after extraction.');
150
+ }
151
+
152
+ process.exit(0);
153
+ });
154
+ } else {
155
+ // On Linux/macOS: download the single binary
156
+ const fileName = `console2svg-${rid}`;
157
+ const url = `https://github.com/arika0093/console2svg/releases/download/v${version}/${fileName}`;
158
+
159
+ download(url, 0, (tempPath) => {
160
+ fs.renameSync(tempPath, destPath);
161
+ fs.chmodSync(destPath, 0o755);
162
+ process.exit(0);
163
+ });
164
+ }
165
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "console2svg",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "description": "Convert terminal output into SVG images",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {