docsguard 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.
Files changed (3) hide show
  1. package/install.js +80 -0
  2. package/package.json +28 -0
  3. package/run.js +22 -0
package/install.js ADDED
@@ -0,0 +1,80 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+ const tar = require('tar');
5
+ const AdmZip = require('adm-zip');
6
+
7
+ const packageJson = require('./package.json');
8
+ const version = packageJson.version;
9
+
10
+ const platform = process.platform;
11
+ const arch = process.arch;
12
+
13
+ let target = '';
14
+ let extension = 'tar.gz';
15
+ let binaryName = 'docsguard';
16
+
17
+ if (platform === 'linux' && arch === 'x64') {
18
+ target = 'x86_64-unknown-linux-gnu';
19
+ } else if (platform === 'darwin' && arch === 'x64') {
20
+ target = 'x86_64-apple-darwin';
21
+ } else if (platform === 'darwin' && arch === 'arm64') {
22
+ target = 'aarch64-apple-darwin';
23
+ } else if (platform === 'win32' && arch === 'x64') {
24
+ target = 'x86_64-pc-windows-msvc';
25
+ extension = 'zip';
26
+ binaryName = 'docsguard.exe';
27
+ } else {
28
+ console.error(`Unsupported platform: ${platform}-${arch}`);
29
+ process.exit(1);
30
+ }
31
+
32
+ const url = `https://github.com/jandro/docsguard/releases/download/v${version}/docsguard-${target}.${extension}`;
33
+ const binDir = path.join(__dirname, 'bin');
34
+ const outputPath = path.join(binDir, `docsguard-${target}.${extension}`);
35
+
36
+ if (!fs.existsSync(binDir)) {
37
+ fs.mkdirSync(binDir);
38
+ }
39
+
40
+ console.log(`Downloading DocsGuard v${version} for ${target}...`);
41
+
42
+ axios({
43
+ method: 'get',
44
+ url: url,
45
+ responseType: 'arraybuffer'
46
+ }).then(async response => {
47
+ fs.writeFileSync(outputPath, response.data);
48
+ console.log('Download complete using axios');
49
+
50
+ console.log('Extracting...');
51
+ if (extension === 'tar.gz') {
52
+ await tar.x({
53
+ file: outputPath,
54
+ cwd: binDir
55
+ });
56
+ } else if (extension === 'zip') {
57
+ const zip = new AdmZip(outputPath);
58
+ zip.extractAllTo(binDir, true);
59
+ }
60
+
61
+ // Cleanup archive
62
+ fs.unlinkSync(outputPath);
63
+
64
+ // Verify binary exists
65
+ const binaryPath = path.join(binDir, binaryName);
66
+ if (fs.existsSync(binaryPath)) {
67
+ console.log(`Successfully installed to ${binaryPath}`);
68
+ // Ensure executable permissions on Unix
69
+ if (platform !== 'win32') {
70
+ fs.chmodSync(binaryPath, '755');
71
+ }
72
+ } else {
73
+ console.error('Extraction failed: Binary not found');
74
+ process.exit(1);
75
+ }
76
+
77
+ }).catch(err => {
78
+ console.error('Error downloading or extracting:', err.message);
79
+ process.exit(1);
80
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "docsguard",
3
+ "version": "0.1.0",
4
+ "description": "Documentation Integrity Engine",
5
+ "bin": {
6
+ "docsguard": "run.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/jandro/docsguard.git"
14
+ },
15
+ "keywords": [
16
+ "documentation",
17
+ "integrity",
18
+ "drift",
19
+ "validation"
20
+ ],
21
+ "author": "Jandro",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "axios": "^1.6.0",
25
+ "tar": "^6.2.0",
26
+ "adm-zip": "^0.5.10"
27
+ }
28
+ }
package/run.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const binaryName = process.platform === 'win32' ? 'docsguard.exe' : 'docsguard';
8
+ const binPath = path.join(__dirname, 'bin', binaryName);
9
+
10
+ if (!fs.existsSync(binPath)) {
11
+ console.error(`DocsGuard binary not found at ${binPath}`);
12
+ console.error('Please try reinstalling the package: npm install -g docsguard');
13
+ process.exit(1);
14
+ }
15
+
16
+ const child = spawn(binPath, process.argv.slice(2), {
17
+ stdio: 'inherit'
18
+ });
19
+
20
+ child.on('exit', (code) => {
21
+ process.exit(code);
22
+ });