node-bible-sync 0.0.0-stage → 0.3.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/.github/workflows/build.yml +39 -0
- package/API.md +81 -0
- package/COPYING +339 -0
- package/README.md +113 -2
- package/biblesync.js +234 -0
- package/binding.gyp +62 -0
- package/examples/biblesync.js +53 -0
- package/index.js +31 -0
- package/package.json +26 -4
- package/scripts/fetch_biblesync.js +80 -0
- package/scripts/ios_framework_postbuild.sh +85 -0
- package/scripts/prepare_biblesync.js +189 -0
- package/src/biblesync_compat/biblesync-version.hh +29 -0
- package/src/biblesync_compat/libintl.h +24 -0
- package/src/biblesync_compat/unistd.h +29 -0
- package/src/biblesync_compat/uuid/uuid.h +61 -0
- package/src/napi_module/biblesync_session.cpp +433 -0
- package/src/napi_module/biblesync_session.hpp +90 -0
- package/src/napi_module/binding.cpp +26 -0
- package/test/biblesync.test.js +142 -0
- package/test/biblesync_example.test.js +59 -0
- package/test/biblesync_fetch.test.js +86 -0
- package/test/biblesync_integration.test.js +267 -0
- package/test/biblesync_native.test.js +162 -0
- package/test/biblesync_prepare.test.js +81 -0
- package/test/fixtures/biblesync_fail_send.c +61 -0
- package/test/fixtures/biblesync_peer.js +53 -0
- package/test/fixtures/biblesync_system_peer.cpp +62 -0
package/biblesync.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync 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-bible-sync 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-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
/* Originally developed for node-sword-interface. */
|
|
20
|
+
const { EventEmitter } = require('events');
|
|
21
|
+
|
|
22
|
+
function field(name, value, allowEmpty = false) {
|
|
23
|
+
if (typeof value !== 'string' || (!allowEmpty && !value) || /[\x00-\x1f\x7f]/.test(value)) {
|
|
24
|
+
throw new TypeError(`${name} must be ${allowEmpty ? 'a' : 'a non-empty'} string without control characters`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates the public BibleSync class around the native addon.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
function createBibleSyncClass(NativeSession) {
|
|
34
|
+
/**
|
|
35
|
+
* A local-network BibleSync session. Constructing a session does not use the network.
|
|
36
|
+
* Attach an `error` listener before starting.
|
|
37
|
+
* @class BibleSync
|
|
38
|
+
* @extends EventEmitter
|
|
39
|
+
* @param {Object} options - Identification and conversation options.
|
|
40
|
+
* @param {String} options.application - Application name.
|
|
41
|
+
* @param {String} options.version - Application version.
|
|
42
|
+
* @param {String} options.user - User's display name.
|
|
43
|
+
* @param {String} [options.passphrase=BibleSync] - Conversation discriminator, not a secret.
|
|
44
|
+
*/
|
|
45
|
+
return class BibleSync extends EventEmitter {
|
|
46
|
+
/**
|
|
47
|
+
* @param {Object} options - Identification and conversation options.
|
|
48
|
+
* @param {String} options.application - Application name.
|
|
49
|
+
* @param {String} options.version - Application version.
|
|
50
|
+
* @param {String} options.user - User's display name.
|
|
51
|
+
* @param {String} [options.passphrase=BibleSync] - Conversation discriminator, not a secret.
|
|
52
|
+
*/
|
|
53
|
+
constructor(options) {
|
|
54
|
+
super();
|
|
55
|
+
if (!options || typeof options !== 'object') throw new TypeError('BibleSync options are required');
|
|
56
|
+
const settings = {
|
|
57
|
+
application: field('application', options.application),
|
|
58
|
+
version: field('version', options.version),
|
|
59
|
+
user: field('user', options.user),
|
|
60
|
+
passphrase: field('passphrase', options.passphrase === undefined ? 'BibleSync' : options.passphrase)
|
|
61
|
+
};
|
|
62
|
+
this._state = 'stopped';
|
|
63
|
+
this._nextId = 0;
|
|
64
|
+
this._pending = new Map();
|
|
65
|
+
this._speakers = new Map();
|
|
66
|
+
this._dispatch = message => this._handleMessage(message);
|
|
67
|
+
this._native = new NativeSession(settings, this._dispatch);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_command(type, args = {}) {
|
|
71
|
+
const id = String(++this._nextId);
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
this._pending.set(id, { resolve, reject });
|
|
74
|
+
try {
|
|
75
|
+
if (type === 'start') this._native.start(id, args.mode);
|
|
76
|
+
else this._native.enqueue(id, type, args);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
this._pending.delete(id);
|
|
79
|
+
reject(error);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_handleMessage(message) {
|
|
85
|
+
if (message.type === 'result') {
|
|
86
|
+
const pending = this._pending.get(message.id);
|
|
87
|
+
if (pending) {
|
|
88
|
+
this._pending.delete(message.id);
|
|
89
|
+
if (message.error) pending.reject(new Error(message.error));
|
|
90
|
+
else pending.resolve();
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (message.type === 'fatal') {
|
|
95
|
+
this._state = 'stopped';
|
|
96
|
+
this._speakers.clear();
|
|
97
|
+
const error = new Error(message.error);
|
|
98
|
+
for (const pending of this._pending.values()) pending.reject(error);
|
|
99
|
+
this._pending.clear();
|
|
100
|
+
this.emit('error', error);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (this._state === 'stopping' || this._state === 'stopped') return;
|
|
104
|
+
const { speakerId } = message;
|
|
105
|
+
if (message.type === 'speaker') {
|
|
106
|
+
const speaker = {
|
|
107
|
+
speakerId, user: message.user, address: message.address,
|
|
108
|
+
application: message.application, device: message.device, listening: false
|
|
109
|
+
};
|
|
110
|
+
this._speakers.set(speakerId, speaker);
|
|
111
|
+
this.emit('speaker', { ...speaker });
|
|
112
|
+
} else if (message.type === 'speakerRemoved') {
|
|
113
|
+
this._speakers.delete(speakerId);
|
|
114
|
+
this.emit('speakerRemoved', { speakerId });
|
|
115
|
+
} else if (message.type === 'navigation') {
|
|
116
|
+
this.emit('navigation', {
|
|
117
|
+
speakerId, bible: message.bible, reference: message.reference,
|
|
118
|
+
alternateReference: message.alternateReference, group: message.group, domain: message.domain
|
|
119
|
+
});
|
|
120
|
+
} else if (message.type === 'presence') {
|
|
121
|
+
this.emit('presence', {
|
|
122
|
+
speakerId, user: message.user, address: message.address,
|
|
123
|
+
application: message.application, device: message.device
|
|
124
|
+
});
|
|
125
|
+
} else if (message.type === 'error') {
|
|
126
|
+
this.emit('error', new Error(message.error));
|
|
127
|
+
} else if (message.type === 'diagnostic') {
|
|
128
|
+
this.emit('diagnostic', { speakerId, message: message.error });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Starts the session in `personal`, `speaker`, or `audience` mode.
|
|
134
|
+
* Only one BibleSync session can be active in a process.
|
|
135
|
+
* @memberof BibleSync
|
|
136
|
+
* @instance
|
|
137
|
+
* @param {String} mode - Desired BibleSync mode.
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*/
|
|
140
|
+
async start(mode) {
|
|
141
|
+
if (!['personal', 'speaker', 'audience'].includes(mode)) throw new TypeError('Invalid BibleSync mode');
|
|
142
|
+
if (this._state !== 'stopped') throw new Error('BibleSync session is already active or starting');
|
|
143
|
+
this._state = 'starting';
|
|
144
|
+
this._startPromise = this._command('start', { mode });
|
|
145
|
+
try {
|
|
146
|
+
await this._startPromise;
|
|
147
|
+
if (this._state === 'starting') this._state = 'running';
|
|
148
|
+
} catch (error) {
|
|
149
|
+
this._state = 'stopped';
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Stops networking and polling. No session events are delivered after this resolves.
|
|
156
|
+
* @memberof BibleSync
|
|
157
|
+
* @instance
|
|
158
|
+
* @returns {Promise<void>}
|
|
159
|
+
*/
|
|
160
|
+
async stop() {
|
|
161
|
+
if (this._state === 'starting') {
|
|
162
|
+
try { await this._startPromise; } catch (_) { return; }
|
|
163
|
+
}
|
|
164
|
+
if (this._state === 'stopped') return;
|
|
165
|
+
if (this._state === 'stopping') return this._stopPromise;
|
|
166
|
+
this._state = 'stopping';
|
|
167
|
+
this._stopPromise = this._command('stop');
|
|
168
|
+
try {
|
|
169
|
+
await this._stopPromise;
|
|
170
|
+
this._state = 'stopped';
|
|
171
|
+
this._speakers.clear();
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (this._state === 'stopping') this._state = 'running';
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Sends a navigation message. Do not send a navigation received from another peer.
|
|
180
|
+
* @memberof BibleSync
|
|
181
|
+
* @instance
|
|
182
|
+
* @param {Object} navigation - Navigation data.
|
|
183
|
+
* @param {String} navigation.bible - Bible abbreviation.
|
|
184
|
+
* @param {String} navigation.reference - Standards-compliant OSIS or BibleRef reference.
|
|
185
|
+
* @param {String} [navigation.alternateReference] - Optional alternate reference.
|
|
186
|
+
* @param {String} [navigation.group=1] - Synchronization group from 1 to 9.
|
|
187
|
+
* @param {String} [navigation.domain=BIBLE-VERSE] - Synchronization domain.
|
|
188
|
+
* @returns {Promise<void>}
|
|
189
|
+
*/
|
|
190
|
+
async sendNavigation(navigation) {
|
|
191
|
+
if (this._state !== 'running') throw new Error('BibleSync session is not running');
|
|
192
|
+
if (!navigation || typeof navigation !== 'object') throw new TypeError('Navigation is required');
|
|
193
|
+
const data = {
|
|
194
|
+
bible: field('bible', navigation.bible),
|
|
195
|
+
reference: field('reference', navigation.reference),
|
|
196
|
+
alternateReference: field('alternateReference', navigation.alternateReference === undefined ? '' : navigation.alternateReference, true),
|
|
197
|
+
group: field('group', navigation.group === undefined ? '1' : navigation.group),
|
|
198
|
+
domain: field('domain', navigation.domain === undefined ? 'BIBLE-VERSE' : navigation.domain)
|
|
199
|
+
};
|
|
200
|
+
if (!/^[1-9]$/.test(data.group)) throw new TypeError('group must be a digit from 1 to 9');
|
|
201
|
+
if (data.domain !== 'BIBLE-VERSE') throw new TypeError('domain must be BIBLE-VERSE');
|
|
202
|
+
return this._command('send', data);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Explicitly enables or disables listening to a discovered speaker.
|
|
207
|
+
* @memberof BibleSync
|
|
208
|
+
* @instance
|
|
209
|
+
* @param {String} speakerId - Discovered speaker UUID.
|
|
210
|
+
* @param {Boolean} listening - Whether navigation from the speaker is accepted.
|
|
211
|
+
* @returns {Promise<void>}
|
|
212
|
+
*/
|
|
213
|
+
async setSpeakerListening(speakerId, listening) {
|
|
214
|
+
if (this._state !== 'running') throw new Error('BibleSync session is not running');
|
|
215
|
+
field('speakerId', speakerId);
|
|
216
|
+
if (typeof listening !== 'boolean') throw new TypeError('listening must be a boolean');
|
|
217
|
+
await this._command('listen', { speakerId, listening });
|
|
218
|
+
const speaker = this._speakers.get(speakerId);
|
|
219
|
+
if (speaker) speaker.listening = listening;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returns a snapshot of discovered speakers and their selected listening status.
|
|
224
|
+
* @memberof BibleSync
|
|
225
|
+
* @instance
|
|
226
|
+
* @returns {Object[]}
|
|
227
|
+
*/
|
|
228
|
+
getSpeakers() {
|
|
229
|
+
return Array.from(this._speakers.values(), speaker => ({ ...speaker }));
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = createBibleSyncClass;
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"variables": {
|
|
3
|
+
"is_ios%": "<!(node -e \"console.log(process.env.SDKROOT?.includes('iPhone') || process.env.PLATFORM === 'ios' ? 1 : 0)\")",
|
|
4
|
+
"ios_ver%": "<!(node -e \"console.log(process.env.IPHONEOS_DEPLOYMENT_TARGET || '13.0')\")",
|
|
5
|
+
"ios_sdk": "<!(node -e \"console.log(process.env.SDKROOT?.includes('iPhoneSimulator') ? 'iphonesimulator' : 'iphoneos')\")"
|
|
6
|
+
},
|
|
7
|
+
"targets": [
|
|
8
|
+
{
|
|
9
|
+
"target_name": "node_bible_sync",
|
|
10
|
+
"actions": [{
|
|
11
|
+
"action_name": "prepare_biblesync",
|
|
12
|
+
"inputs": ["scripts/fetch_biblesync.js", "scripts/prepare_biblesync.js"],
|
|
13
|
+
"outputs": ["<(SHARED_INTERMEDIATE_DIR)/biblesync.cc", "<(SHARED_INTERMEDIATE_DIR)/biblesync.hh"],
|
|
14
|
+
"action": ["node", "<(module_root_dir)/scripts/prepare_biblesync.js", "<(SHARED_INTERMEDIATE_DIR)/biblesync.cc"]
|
|
15
|
+
}],
|
|
16
|
+
"sources": [
|
|
17
|
+
"<(SHARED_INTERMEDIATE_DIR)/biblesync.cc",
|
|
18
|
+
"src/napi_module/biblesync_session.cpp",
|
|
19
|
+
"src/napi_module/binding.cpp"
|
|
20
|
+
],
|
|
21
|
+
"include_dirs": [
|
|
22
|
+
"<(module_root_dir)/src/biblesync_compat",
|
|
23
|
+
"<(SHARED_INTERMEDIATE_DIR)",
|
|
24
|
+
"<(module_root_dir)/biblesync/include",
|
|
25
|
+
"<!@(node -p \"require('node-addon-api').include\")"
|
|
26
|
+
],
|
|
27
|
+
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
|
28
|
+
"conditions": [
|
|
29
|
+
["OS=='win'", {
|
|
30
|
+
"defines": ["WIN32", "_WINSOCK_DEPRECATED_NO_WARNINGS"],
|
|
31
|
+
"libraries": ["-lWs2_32.lib", "-lRpcrt4.lib"]
|
|
32
|
+
}],
|
|
33
|
+
["OS=='android'", {
|
|
34
|
+
"ldflags": ["-Wl,-z,max-page-size=16384"]
|
|
35
|
+
}],
|
|
36
|
+
["is_ios==1", {
|
|
37
|
+
"type": "shared_library",
|
|
38
|
+
"xcode_settings": {
|
|
39
|
+
"SDKROOT": "<(ios_sdk)",
|
|
40
|
+
"IPHONEOS_DEPLOYMENT_TARGET": "<(ios_ver)",
|
|
41
|
+
"ONLY_ACTIVE_ARCH": "YES"
|
|
42
|
+
}
|
|
43
|
+
}]
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"target_name": "node_bible_sync.framework",
|
|
48
|
+
"type": "none",
|
|
49
|
+
"dependencies": ["node_bible_sync"],
|
|
50
|
+
"conditions": [
|
|
51
|
+
["is_ios==1", {
|
|
52
|
+
"actions": [{
|
|
53
|
+
"action_name": "create_framework",
|
|
54
|
+
"inputs": [],
|
|
55
|
+
"outputs": ["<(PRODUCT_DIR)/node_bible_sync.framework"],
|
|
56
|
+
"action": ["sh", "scripts/ios_framework_postbuild.sh", "<(PRODUCT_DIR)", "node_bible_sync"]
|
|
57
|
+
}]
|
|
58
|
+
}]
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync 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-bible-sync 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-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
const BibleSync = require('..');
|
|
20
|
+
|
|
21
|
+
const sync = new BibleSync({
|
|
22
|
+
application: 'node-bible-sync example',
|
|
23
|
+
version: '1',
|
|
24
|
+
user: 'Example'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
let startPromise;
|
|
28
|
+
|
|
29
|
+
sync.on('error', error => console.error('BibleSync error:', error.message));
|
|
30
|
+
sync.on('speaker', async speaker => {
|
|
31
|
+
console.log(`Discovered ${speaker.user} (${speaker.speakerId})`);
|
|
32
|
+
try {
|
|
33
|
+
await startPromise;
|
|
34
|
+
await sync.setSpeakerListening(speaker.speakerId, true);
|
|
35
|
+
console.log(`Following ${speaker.user} (${speaker.speakerId})`);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(`Could not follow ${speaker.user} (${speaker.speakerId}):`, error.message);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
sync.on('navigation', navigation => console.log('Navigation:', navigation));
|
|
41
|
+
|
|
42
|
+
async function main() {
|
|
43
|
+
startPromise = sync.start('audience');
|
|
44
|
+
await startPromise;
|
|
45
|
+
console.log('Listening for speakers for 30 seconds.');
|
|
46
|
+
await new Promise(resolve => setTimeout(resolve, 30000));
|
|
47
|
+
await sync.stop();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main().catch(error => {
|
|
51
|
+
console.error(error);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync 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-bible-sync 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-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
let addon;
|
|
22
|
+
if (process.platform === 'ios') {
|
|
23
|
+
const modulePath = path.join(__dirname, '../../../../Frameworks/node_bible_sync.framework/node_bible_sync');
|
|
24
|
+
const module = { exports: {} };
|
|
25
|
+
process.dlopen(module, modulePath);
|
|
26
|
+
addon = module.exports;
|
|
27
|
+
} else {
|
|
28
|
+
addon = require('./build/Release/node_bible_sync.node');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = require('./biblesync')(addon.BibleSyncSession);
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-bible-sync",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Node.js wrapper of biblesync, a multicast shared co-navigation library for Bible programs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"gypfile": true,
|
|
7
|
+
"license": "GPL-2.0+",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ezra-bible-app/node-bible-sync.git"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "node-gyp rebuild",
|
|
14
|
+
"clean": "node-gyp clean",
|
|
15
|
+
"release": "npm version minor --tag-version-prefix=",
|
|
16
|
+
"stage": "rm -rf build node_modules biblesync && npm stage publish ./",
|
|
17
|
+
"doc": "jsdoc2md biblesync.js > API.md",
|
|
18
|
+
"test": "jest"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"node-addon-api": "^8.2.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"jest": "^30.0.5",
|
|
25
|
+
"jsdoc-to-markdown": "^9.1.1",
|
|
26
|
+
"node-gyp": "^12.1.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* This file is part of node-bible-sync.
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
6
|
+
|
|
7
|
+
node-bible-sync is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 2 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
node-bible-sync is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
See the GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with node-bible-sync. See the file COPYING.
|
|
19
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
20
|
+
|
|
21
|
+
/* Fetch the same BibleSync revision for every platform without modifying an
|
|
22
|
+
* existing checkout. The build may be retried after an interrupted download.
|
|
23
|
+
*/
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const { spawnSync } = require('child_process');
|
|
27
|
+
|
|
28
|
+
const REPOSITORY = 'https://github.com/karlkleinpaste/biblesync.git';
|
|
29
|
+
const REVISION = 'f388207c3ddc8c9cd28265dc3255ec0b79d6fbd9'; // 2.2.0
|
|
30
|
+
const destination = path.resolve(__dirname, '..', 'biblesync');
|
|
31
|
+
|
|
32
|
+
function git(args) {
|
|
33
|
+
const result = spawnSync('git', args, { encoding: 'utf8' });
|
|
34
|
+
if (result.error) {
|
|
35
|
+
throw result.error;
|
|
36
|
+
}
|
|
37
|
+
if (result.status !== 0) {
|
|
38
|
+
throw new Error(`git ${args[0]} failed: ${(result.stderr || '').trim()}`);
|
|
39
|
+
}
|
|
40
|
+
return result.stdout.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function verifyCheckout(dir) {
|
|
44
|
+
const revision = git(['-C', dir, 'rev-parse', 'HEAD']);
|
|
45
|
+
if (revision !== REVISION) {
|
|
46
|
+
throw new Error(`BibleSync checkout at ${dir} is ${revision}, expected ${REVISION}; it was not modified`);
|
|
47
|
+
}
|
|
48
|
+
if (git(['-C', dir, 'status', '--porcelain', '--untracked-files=all'])) {
|
|
49
|
+
throw new Error(`BibleSync checkout at ${dir} has local changes; it was not modified`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function fetchBibleSync() {
|
|
54
|
+
if (fs.existsSync(destination)) {
|
|
55
|
+
verifyCheckout(destination);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const temporary = fs.mkdtempSync(path.join(path.dirname(destination), '.biblesync-fetch-'));
|
|
60
|
+
const checkout = path.join(temporary, 'source');
|
|
61
|
+
try {
|
|
62
|
+
git(['clone', '--no-checkout', '--', REPOSITORY, checkout]);
|
|
63
|
+
git(['-C', checkout, 'checkout', '--detach', REVISION]);
|
|
64
|
+
verifyCheckout(checkout);
|
|
65
|
+
fs.renameSync(checkout, destination);
|
|
66
|
+
} finally {
|
|
67
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (require.main === module) {
|
|
72
|
+
try {
|
|
73
|
+
fetchBibleSync();
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(`Unable to fetch BibleSync: ${error.message}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = { fetchBibleSync };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# This file is part of node-bible-sync.
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
6
|
+
#
|
|
7
|
+
# node-bible-sync is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
#
|
|
12
|
+
# node-bible-sync is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
# See the GNU General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU General Public License
|
|
18
|
+
# along with node-bible-sync. See the file COPYING.
|
|
19
|
+
# If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
|
|
21
|
+
# Originally developed for node-sword-interface; adapted for node-bible-sync.
|
|
22
|
+
|
|
23
|
+
set -e
|
|
24
|
+
|
|
25
|
+
# Accept arguments from GYP, or fallback to Xcode env vars
|
|
26
|
+
# Arg 1: Build Directory (where the binary is)
|
|
27
|
+
# Arg 2: Executable Name
|
|
28
|
+
BUILD_DIR="${1:-$BUILT_PRODUCTS_DIR}"
|
|
29
|
+
EXECUTABLE_NAME="${2:-$EXECUTABLE_PATH}"
|
|
30
|
+
|
|
31
|
+
# Fallback for executable name if not provided or in env
|
|
32
|
+
if [ -z "$EXECUTABLE_NAME" ]; then
|
|
33
|
+
EXECUTABLE_NAME="node_bible_sync"
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
FRAMEWORK_NAME="node_bible_sync"
|
|
37
|
+
FRAMEWORK_DIR="${BUILD_DIR}/${FRAMEWORK_NAME}.framework"
|
|
38
|
+
BINARY_SOURCE="${BUILD_DIR}/${EXECUTABLE_NAME}.dylib"
|
|
39
|
+
|
|
40
|
+
echo "Creating iOS Framework structure at ${FRAMEWORK_DIR}"
|
|
41
|
+
echo "Using binary: ${BINARY_SOURCE}"
|
|
42
|
+
|
|
43
|
+
# Ensure the framework directory exists
|
|
44
|
+
mkdir -p "${FRAMEWORK_DIR}"
|
|
45
|
+
|
|
46
|
+
# Copy the binary
|
|
47
|
+
cp "${BINARY_SOURCE}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
|
|
48
|
+
|
|
49
|
+
# Create Info.plist
|
|
50
|
+
cat > "${FRAMEWORK_DIR}/Info.plist" <<PLIST_EOF
|
|
51
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
52
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
53
|
+
<plist version="1.0">
|
|
54
|
+
<dict>
|
|
55
|
+
<key>CFBundleExecutable</key>
|
|
56
|
+
<string>${FRAMEWORK_NAME}</string>
|
|
57
|
+
<key>CFBundleIdentifier</key>
|
|
58
|
+
<string>net.ezrabibleapp.node-bible-sync</string>
|
|
59
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
60
|
+
<string>6.0</string>
|
|
61
|
+
<key>CFBundleName</key>
|
|
62
|
+
<string>${FRAMEWORK_NAME}</string>
|
|
63
|
+
<key>CFBundlePackageType</key>
|
|
64
|
+
<string>FMWK</string>
|
|
65
|
+
<key>CFBundleShortVersionString</key>
|
|
66
|
+
<string>1.0</string>
|
|
67
|
+
<key>CFBundleVersion</key>
|
|
68
|
+
<string>1</string>
|
|
69
|
+
<key>MinimumOSVersion</key>
|
|
70
|
+
<string>${IPHONEOS_DEPLOYMENT_TARGET}</string>
|
|
71
|
+
<key>CFBundleSupportedPlatforms</key>
|
|
72
|
+
<array>
|
|
73
|
+
<string>iPhoneOS</string>
|
|
74
|
+
</array>
|
|
75
|
+
</dict>
|
|
76
|
+
</plist>
|
|
77
|
+
PLIST_EOF
|
|
78
|
+
|
|
79
|
+
# Sign the framework (ad-hoc)
|
|
80
|
+
/usr/bin/codesign --force --sign - --timestamp=none "${FRAMEWORK_DIR}"
|
|
81
|
+
|
|
82
|
+
# Remove the source binary
|
|
83
|
+
rm "${BINARY_SOURCE}"
|
|
84
|
+
|
|
85
|
+
echo "Framework created successfully."
|