@convert-to-md/cli 0.1.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/bin/convert-to-md.js +21 -0
- package/package.json +20 -0
- package/scripts/install.js +78 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const binaryName = process.platform === 'win32' ? 'convert-to-md.exe' : 'convert-to-md';
|
|
9
|
+
const binaryPath = join(__dirname, '..', '.bin', binaryName);
|
|
10
|
+
|
|
11
|
+
if (!existsSync(binaryPath)) {
|
|
12
|
+
console.error('convert-to-md binary is missing. Run `npm rebuild @convert-to-md/cli` to reinstall it.');
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
17
|
+
if (result.error) {
|
|
18
|
+
console.error(result.error.message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
process.exit(result.status ?? 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@convert-to-md/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cross-platform npm wrapper for the convert-to-md Go CLI",
|
|
5
|
+
"bin": {
|
|
6
|
+
"convert-to-md": "bin/convert-to-md.js"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"scripts"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"postinstall": "node scripts/install.js"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT"
|
|
20
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createWriteStream, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { chmod, rename, unlink } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { get } from 'node:https';
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const packageRoot = join(__dirname, '..');
|
|
10
|
+
const binDir = join(packageRoot, '.bin');
|
|
11
|
+
|
|
12
|
+
const version = process.env.npm_package_version;
|
|
13
|
+
const repo = process.env.CONVERT_TO_MD_RELEASE_REPO || 'convert-to-md/convert-to.md';
|
|
14
|
+
const tagPrefix = process.env.CONVERT_TO_MD_RELEASE_TAG_PREFIX || 'cli-v';
|
|
15
|
+
|
|
16
|
+
const platformMap = {
|
|
17
|
+
linux: 'Linux',
|
|
18
|
+
darwin: 'Darwin',
|
|
19
|
+
win32: 'Windows'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const archMap = {
|
|
23
|
+
x64: 'x86_64',
|
|
24
|
+
arm64: 'arm64'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const platform = platformMap[process.platform];
|
|
28
|
+
const arch = archMap[process.arch];
|
|
29
|
+
|
|
30
|
+
if (!platform || !arch) {
|
|
31
|
+
console.error(`Unsupported platform: ${process.platform}/${process.arch}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
36
|
+
const archiveName = `convert-to-md_${version}_${platform}_${arch}`;
|
|
37
|
+
const fileName = `${archiveName}${ext}`;
|
|
38
|
+
const downloadURL = `https://github.com/${repo}/releases/download/${tagPrefix}${version}/${fileName}`;
|
|
39
|
+
|
|
40
|
+
mkdirSync(binDir, { recursive: true });
|
|
41
|
+
const destFile = join(binDir, `convert-to-md${ext}`);
|
|
42
|
+
|
|
43
|
+
if (existsSync(destFile)) {
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const tempFile = `${destFile}.tmp`;
|
|
48
|
+
const out = createWriteStream(tempFile, { mode: 0o755 });
|
|
49
|
+
|
|
50
|
+
console.log(`Downloading convert-to-md binary from ${downloadURL}`);
|
|
51
|
+
|
|
52
|
+
get(downloadURL, response => {
|
|
53
|
+
if (response.statusCode !== 200) {
|
|
54
|
+
console.error(`Failed to download binary (status ${response.statusCode})`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
response.pipe(out);
|
|
59
|
+
out.on('finish', async () => {
|
|
60
|
+
out.close();
|
|
61
|
+
try {
|
|
62
|
+
if (process.platform !== 'win32') {
|
|
63
|
+
await chmod(tempFile, 0o755);
|
|
64
|
+
}
|
|
65
|
+
await rename(tempFile, destFile);
|
|
66
|
+
console.log('convert-to-md installed');
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error.message);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}).on('error', async error => {
|
|
73
|
+
console.error(`Download failed: ${error.message}`);
|
|
74
|
+
try {
|
|
75
|
+
await unlink(tempFile);
|
|
76
|
+
} catch {}
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|