node-sword-interface 1.0.46 → 1.0.48

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/binding.gyp CHANGED
@@ -44,7 +44,7 @@
44
44
  'message': 'Downloading sword-build-win32 artifacts from GitHub ...',
45
45
  'inputs': [],
46
46
  'outputs': ['sword-build-win32'],
47
- 'action': ['PowerShell.exe', '-ExecutionPolicy', 'Bypass', '-File', '<(module_root_dir)/scripts/get_sword_build_win32.ps1'],
47
+ 'action': ['node', '<(module_root_dir)/scripts/get_sword_build_win32.js'],
48
48
  }
49
49
  ]
50
50
  }]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env node
2
+ /* This file is part of node-sword-interface.
3
+
4
+ Copyright (C) 2019 - 2025 Tobias Klein <contact@tklein.info>
5
+
6
+ node-sword-interface is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 2 of the License, or
9
+ (at your option) any later version.
10
+
11
+ node-sword-interface is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+ See the GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with node-sword-interface. See the file COPYING.
18
+ If not, see <http://www.gnu.org/licenses/>. */
19
+
20
+ const https = require('https');
21
+ const fs = require('fs');
22
+ const path = require('path');
23
+ const { execFileSync } = require('child_process');
24
+
25
+ const RELEASE_TAG = 'v1.8.900-2022-11-06';
26
+ const API_URL = `https://api.github.com/repos/ezra-bible-app/sword-build-win32/releases/tags/${RELEASE_TAG}`;
27
+
28
+ function fetchJson(url, headers = {}) {
29
+ return new Promise((resolve, reject) => {
30
+ const req = https.get(url, {
31
+ headers: {
32
+ 'User-Agent': 'node-sword-interface',
33
+ 'Accept': 'application/vnd.github+json',
34
+ ...headers,
35
+ }
36
+ }, res => {
37
+ let data = '';
38
+ res.on('data', chunk => data += chunk);
39
+ res.on('end', () => {
40
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
41
+ try {
42
+ resolve(JSON.parse(data));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ } else {
47
+ reject(new Error(`Request failed: ${res.statusCode} ${data}`));
48
+ }
49
+ });
50
+ });
51
+ req.on('error', reject);
52
+ });
53
+ }
54
+
55
+ function downloadFile(url, outPath, headers = {}, maxRedirects = 5) {
56
+ return new Promise((resolve, reject) => {
57
+ let redirects = 0;
58
+
59
+ const doRequest = (reqUrl) => {
60
+ const file = fs.createWriteStream(outPath);
61
+ const req = https.get(reqUrl, {
62
+ headers: {
63
+ 'User-Agent': 'node-sword-interface',
64
+ 'Accept': 'application/octet-stream',
65
+ ...headers,
66
+ }
67
+ }, res => {
68
+ // Handle redirects
69
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
70
+ file.close(); // ensure stream closed before re-request
71
+ fs.unlink(outPath, () => {
72
+ if (redirects >= maxRedirects) {
73
+ reject(new Error(`Too many redirects downloading: ${reqUrl}`));
74
+ return;
75
+ }
76
+ redirects++;
77
+ const nextUrl = res.headers.location.startsWith('http')
78
+ ? res.headers.location
79
+ : new URL(res.headers.location, reqUrl).toString();
80
+ doRequest(nextUrl);
81
+ });
82
+ return;
83
+ }
84
+
85
+ if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
86
+ file.close();
87
+ fs.unlink(outPath, () => reject(new Error(`Download failed: ${res.statusCode}`)));
88
+ return;
89
+ }
90
+
91
+ res.pipe(file);
92
+ file.on('finish', () => file.close(resolve));
93
+ });
94
+
95
+ req.on('error', err => {
96
+ file.close();
97
+ fs.unlink(outPath, () => reject(err));
98
+ });
99
+ };
100
+
101
+ doRequest(url);
102
+ });
103
+ }
104
+
105
+ async function main() {
106
+ try {
107
+ const isCI = process.env.CI === 'true';
108
+ const githubToken = process.env.GITHUB_TOKEN;
109
+ const authHeader = (isCI && githubToken) ? { Authorization: `Bearer ${githubToken}` } : {};
110
+
111
+ if (isCI) {
112
+ console.log('GitHub actions build ... using GITHUB_TOKEN for authentication!');
113
+ }
114
+
115
+ const release = await fetchJson(API_URL, authHeader);
116
+ if (!release.assets || !release.assets.length) {
117
+ throw new Error('No assets found in release.');
118
+ }
119
+
120
+ const asset = release.assets[0];
121
+ const zipName = asset.name;
122
+ const zipUrl = asset.browser_download_url;
123
+
124
+ const cwd = process.cwd();
125
+
126
+ // Remove existing folder if present
127
+ const existingDir = path.join(cwd, 'sword-build-win32');
128
+ if (fs.existsSync(existingDir)) {
129
+ fs.rmSync(existingDir, { recursive: true, force: true });
130
+ }
131
+
132
+ const zipPath = path.join(cwd, zipName);
133
+ console.log(`Downloading ${zipUrl} -> ${zipPath}`);
134
+ await downloadFile(zipUrl, zipPath, authHeader);
135
+
136
+ // Extract ZIP file
137
+ const extractedDirName = zipName.replace(/\.zip$/i, '');
138
+ try {
139
+ if (process.platform === 'win32') {
140
+ execFileSync('powershell', ['-NoProfile', '-Command', `Expand-Archive -Path '${zipPath}' -DestinationPath '.' -Force`], { stdio: 'inherit' });
141
+ } else {
142
+ // Prefer system unzip if available
143
+ try {
144
+ execFileSync('unzip', ['-o', zipPath], { stdio: 'inherit' });
145
+ } catch (unzipErr) {
146
+ // Fallback to 7z if unzip is not present
147
+ execFileSync('7z', ['x', zipPath], { stdio: 'inherit' });
148
+ }
149
+ }
150
+ } catch (e) {
151
+ throw new Error(`Extraction failed: ${e.message}`);
152
+ }
153
+
154
+ // Remove zip file
155
+ fs.unlinkSync(zipPath);
156
+
157
+ // Rename extracted folder
158
+ if (!fs.existsSync(path.join(cwd, extractedDirName))) {
159
+ throw new Error(`Expected extracted directory '${extractedDirName}' not found.`);
160
+ }
161
+ fs.renameSync(path.join(cwd, extractedDirName), existingDir);
162
+
163
+ console.log('Download of Windows library artifacts completed!');
164
+ } catch (err) {
165
+ console.error('Error:', err.message);
166
+ process.exit(1);
167
+ }
168
+ }
169
+
170
+ if (require.main === module) {
171
+ main();
172
+ }
@@ -1,74 +0,0 @@
1
- # This file is part of node-sword-interface.
2
- #
3
- # Copyright (C) 2019 - 2025 Tobias Klein <contact@tklein.info>
4
- #
5
- # node-sword-interface is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # node-sword-interface is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
- # See the GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with node-sword-interface. See the file COPYING.
17
- # If not, see <http://www.gnu.org/licenses/>.
18
-
19
- # see https://www.helloitscraig.co.uk/2016/02/download-the-latest-repo.html
20
- # see https://www.saotn.org/unzip-file-powershell/
21
-
22
- Add-Type -AssemblyName System.IO.Compression.FileSystem
23
- function unzip {
24
- param( [string]$ziparchive, [string]$extractpath )
25
- [System.IO.Compression.ZipFile]::ExtractToDirectory( $ziparchive, $extractpath )
26
- }
27
-
28
- # --- Only allow TLS1.1 and TLS1.2
29
- $AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12'
30
- [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
31
-
32
- $headers = @{}
33
-
34
- $github_token = $env:GITHUB_TOKEN
35
-
36
- # --- Set the uri for the release
37
- $URI = "https://api.github.com/repos/ezra-bible-app/sword-build-win32/releases/tags/v1.8.900-2022-11-06"
38
-
39
- if ($Env:CI -eq "true") {
40
- Write-Host "GitHub actions build ... using GITHUB_TOKEN for authentication!"
41
-
42
- $headers = @{
43
- Authorization="Bearer $github_token"
44
- ContentType='application/json'
45
- }
46
- }
47
-
48
- # --- Query the API to get the url of the zip
49
- $Response = Invoke-RestMethod -Method Get -Uri $URI -Headers $headers
50
-
51
- $ZipName = $Response.assets[0].name
52
- $ZipUrl = $Response.assets[0].browser_download_url
53
-
54
- # --- Remove the existing folder
55
- if (Test-Path sword-build-win32) {
56
- Remove-Item -Recurse -Force sword-build-win32
57
- }
58
-
59
- # --- Download the file to the current location
60
- $OutputPath = Join-Path -Path (Get-Location).Path -ChildPath $ZipName
61
- Invoke-RestMethod -Method Get -Uri $ZipUrl -OutFile $OutputPath -Headers $headers
62
-
63
- Write-Host "OutputPath: $OutputPath"
64
- Write-Host "ZipUrl: $ZipUrl"
65
-
66
- # --- Unzip the zip file and remove it afterwards
67
- unzip $OutputPath $((Get-Location).Path)
68
- Remove-Item $OutputPath
69
-
70
- # --- Rename the extracted folder to a standard name
71
- $LibDirName = $ZipName.Replace(".zip", "")
72
- Rename-Item -Path $LibDirName -NewName sword-build-win32
73
-
74
- Write-Host "Download of Windows library artifacts completed!"