fop-cli 3.9.8 → 3.9.9

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/install.js +47 -23
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -7,35 +7,16 @@ const path = require('path');
7
7
  const { execSync } = require('child_process');
8
8
 
9
9
  // Configuration - UPDATE THESE FOR YOUR RELEASE
10
- const VERSION = '3.9.8';
10
+ const VERSION = '3.9.9';
11
11
  const GITHUB_REPO = 'ryanbr/fop-rs'; // Change to your repo
12
12
  const BINARY_NAME = 'fop';
13
13
 
14
14
  // Platform mapping
15
15
  const PLATFORMS = {
16
- 'darwin-x64': `-macos-x86_64`,
17
- 'darwin-arm64': `-macos-arm64`,
18
16
  'linux-x64': `-linux-x86_64`,
19
- 'linux-arm64': `-linux-arm64`,
20
17
  'win32-x64': `-windows-x86_64.exe`,
21
- 'win32-arm64': `-windows-arm64.exe`,
22
18
  };
23
19
 
24
- function getPlatformBinary() {
25
- const platform = process.platform;
26
- const arch = process.arch;
27
- const key = `${platform}-${arch}`;
28
-
29
- const suffix = PLATFORMS[key];
30
- if (!suffix) {
31
- console.error(`Unsupported platform: ${platform}-${arch}`);
32
- console.error('Supported platforms:', Object.keys(PLATFORMS).join(', '));
33
- process.exit(1);
34
- }
35
-
36
- return `fop-${VERSION}${suffix}`;
37
- }
38
-
39
20
  function getDownloadUrl(binaryName) {
40
21
  // GitHub releases URL pattern
41
22
  return `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${binaryName}`;
@@ -81,6 +62,35 @@ function download(url, dest) {
81
62
  });
82
63
  }
83
64
 
65
+ function buildFromSource(binaryPath) {
66
+ console.log('Building from source...');
67
+ console.log('This requires Rust to be installed (https://rustup.rs)');
68
+
69
+ try {
70
+ execSync('cargo --version', { stdio: 'ignore' });
71
+ } catch (e) {
72
+ console.error('Error: Rust/Cargo not found.');
73
+ console.error('Please install Rust from https://rustup.rs and try again.');
74
+ process.exit(1);
75
+ }
76
+
77
+ try {
78
+ const tempDir = path.join(__dirname, 'build-temp');
79
+ execSync(`git clone --depth 1 https://github.com/${GITHUB_REPO}.git "${tempDir}"`, { stdio: 'inherit' });
80
+ execSync('cargo build --release', { cwd: tempDir, stdio: 'inherit' });
81
+
82
+ const builtBinary = path.join(tempDir, 'target', 'release', process.platform === 'win32' ? 'fop.exe' : 'fop');
83
+ fs.copyFileSync(builtBinary, binaryPath);
84
+ fs.rmSync(tempDir, { recursive: true, force: true });
85
+
86
+ console.log('Build completed successfully!');
87
+ return true;
88
+ } catch (e) {
89
+ console.error('Build failed:', e.message);
90
+ return false;
91
+ }
92
+ }
93
+
84
94
  async function install() {
85
95
  const binDir = path.join(__dirname, 'bin');
86
96
  const binaryPath = path.join(binDir, 'fop-binary');
@@ -96,10 +106,24 @@ async function install() {
96
106
  return;
97
107
  }
98
108
 
99
- const platformBinary = getPlatformBinary();
100
- const url = getDownloadUrl(platformBinary);
109
+ const platform = process.platform;
110
+ const arch = process.arch;
111
+ const key = `${platform}-${arch}`;
112
+ const suffix = PLATFORMS[key];
101
113
 
102
- console.log(`Installing FOP v${VERSION} for ${process.platform}-${process.arch}...`);
114
+ console.log(`Installing FOP v${VERSION} for ${platform}-${arch}...`);
115
+
116
+ if (!suffix) {
117
+ console.log(`No pre-built binary for ${platform}-${arch}, building from source...`);
118
+ if (buildFromSource(binaryPath)) {
119
+ fs.chmodSync(binaryPath, 0o755);
120
+ }
121
+ return;
122
+ }
123
+
124
+ const platformBinary = `fop-${VERSION}${suffix}`;
125
+ const url = getDownloadUrl(platformBinary);
126
+
103
127
 
104
128
  try {
105
129
  await download(url, binaryPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fop-cli",
3
- "version": "3.9.8",
3
+ "version": "3.9.9",
4
4
  "description": "Filter Orderer and Preener - A tool for sorting and cleaning ad-blocking filter lists",
5
5
  "keywords": [
6
6
  "adblock",