console2svg 0.2.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.
- package/README.md +21 -0
- package/cli/console2svg.js +21 -0
- package/cli/install.js +123 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# console2svg (npm wrapper)
|
|
2
|
+
|
|
3
|
+
This package installs the prebuilt console2svg binary from GitHub Releases.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g console2svg
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
console2svg --help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Notes
|
|
18
|
+
|
|
19
|
+
* Supported platforms: Linux x64, macOS x64, Windows x64.
|
|
20
|
+
* The binary is downloaded from GitHub Releases that match this npm package version.
|
|
21
|
+
* Proxy environment variables are supported (`HTTPS_PROXY`, `HTTP_PROXY`, `NO_PROXY`).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const isWin = process.platform === 'win32';
|
|
9
|
+
const ext = isWin ? '.exe' : '';
|
|
10
|
+
const binPath = path.join(__dirname, '..', 'dist', `console2svg${ext}`);
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(binPath)) {
|
|
13
|
+
console.error('console2svg: binary not found.');
|
|
14
|
+
console.error('Reinstall the package or use the .NET tool.');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const child = spawn(binPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
19
|
+
child.on('exit', (code) => {
|
|
20
|
+
process.exit(code == null ? 1 : code);
|
|
21
|
+
});
|
package/cli/install.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const https = require('https');
|
|
7
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
8
|
+
const { getProxyForUrl } = require('proxy-from-env');
|
|
9
|
+
|
|
10
|
+
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
11
|
+
const version = pkg.version;
|
|
12
|
+
|
|
13
|
+
const platform = process.platform;
|
|
14
|
+
const arch = process.arch;
|
|
15
|
+
|
|
16
|
+
if (arch !== 'x64') {
|
|
17
|
+
console.error(`console2svg: unsupported architecture: ${arch}`);
|
|
18
|
+
console.error('Use the .NET tool or build from source for this platform.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let rid;
|
|
23
|
+
if (platform === 'win32') {
|
|
24
|
+
rid = 'win-x64';
|
|
25
|
+
} else if (platform === 'linux') {
|
|
26
|
+
rid = 'linux-x64';
|
|
27
|
+
} else if (platform === 'darwin') {
|
|
28
|
+
rid = 'osx-x64';
|
|
29
|
+
} else {
|
|
30
|
+
console.error(`console2svg: unsupported platform: ${platform}`);
|
|
31
|
+
console.error('Use the .NET tool or build from source for this platform.');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isWin = platform === 'win32';
|
|
36
|
+
const ext = isWin ? '.exe' : '';
|
|
37
|
+
const fileName = `console2svg-${rid}${ext}`;
|
|
38
|
+
const url = `https://github.com/arika0093/console2svg/releases/download/v${version}/${fileName}`;
|
|
39
|
+
|
|
40
|
+
const distDir = path.join(__dirname, '..', 'dist');
|
|
41
|
+
const destPath = path.join(distDir, `console2svg${ext}`);
|
|
42
|
+
const tempPath = `${destPath}.tmp`;
|
|
43
|
+
|
|
44
|
+
if (fs.existsSync(destPath)) {
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fs.mkdirSync(distDir, { recursive: true });
|
|
49
|
+
|
|
50
|
+
function fail(message, err) {
|
|
51
|
+
if (err) {
|
|
52
|
+
console.error(message, err.message || err);
|
|
53
|
+
} else {
|
|
54
|
+
console.error(message);
|
|
55
|
+
}
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function download(downloadUrl, redirects) {
|
|
60
|
+
if (redirects > 5) {
|
|
61
|
+
fail('console2svg: too many redirects while downloading.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const proxy = getProxyForUrl(downloadUrl);
|
|
65
|
+
const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
66
|
+
const url = new URL(downloadUrl);
|
|
67
|
+
|
|
68
|
+
const request = https.get(
|
|
69
|
+
{
|
|
70
|
+
hostname: url.hostname,
|
|
71
|
+
path: url.pathname + url.search,
|
|
72
|
+
protocol: url.protocol,
|
|
73
|
+
port: url.port,
|
|
74
|
+
agent,
|
|
75
|
+
headers: {
|
|
76
|
+
'User-Agent': 'console2svg-npm-wrapper',
|
|
77
|
+
Accept: 'application/octet-stream'
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
(res) => {
|
|
81
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
82
|
+
res.resume();
|
|
83
|
+
download(res.headers.location, redirects + 1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (res.statusCode !== 200) {
|
|
88
|
+
res.resume();
|
|
89
|
+
fail(`console2svg: download failed (${res.statusCode}) from ${downloadUrl}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const file = fs.createWriteStream(tempPath);
|
|
93
|
+
res.pipe(file);
|
|
94
|
+
file.on('finish', () => {
|
|
95
|
+
file.close(() => {
|
|
96
|
+
try {
|
|
97
|
+
fs.renameSync(tempPath, destPath);
|
|
98
|
+
if (!isWin) {
|
|
99
|
+
fs.chmodSync(destPath, 0o755);
|
|
100
|
+
}
|
|
101
|
+
process.exit(0);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
fail('console2svg: failed to finalize download.', err);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
file.on('error', (err) => {
|
|
108
|
+
try {
|
|
109
|
+
fs.unlinkSync(tempPath);
|
|
110
|
+
} catch {
|
|
111
|
+
// ignore
|
|
112
|
+
}
|
|
113
|
+
fail('console2svg: write failed.', err);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
request.on('error', (err) => {
|
|
119
|
+
fail('console2svg: request failed.', err);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
download(url, 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "console2svg",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Convert terminal output into SVG images",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/arika0093/console2svg.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/arika0093/console2svg#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/arika0093/console2svg/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"console2svg": "cli/console2svg.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"cli",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"postinstall": "node cli/install.js"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"https-proxy-agent": "^7.0.4",
|
|
26
|
+
"proxy-from-env": "^1.1.0"
|
|
27
|
+
},
|
|
28
|
+
"os": [
|
|
29
|
+
"darwin",
|
|
30
|
+
"linux",
|
|
31
|
+
"win32"
|
|
32
|
+
],
|
|
33
|
+
"cpu": [
|
|
34
|
+
"x64"
|
|
35
|
+
],
|
|
36
|
+
"preferGlobal": true
|
|
37
|
+
}
|