@marineyachtradar/signalk-playback-plugin 0.1.1 → 0.2.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/build.js DELETED
@@ -1,248 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Build script for mayara-server-signalk-playbackrecordings-plugin
4
- *
5
- * Copies @marineyachtradar/mayara-gui from npm to public/
6
- * The plugin adds its own playback.html for file upload/control.
7
- *
8
- * Usage: node build.js [options]
9
- * --local-gui Use local mayara-gui instead of npm (for development)
10
- * --pack Create a .tgz tarball with public/ included (for manual install)
11
- */
12
-
13
- const fs = require('fs')
14
- const path = require('path')
15
- const { execSync } = require('child_process')
16
-
17
- const args = process.argv.slice(2)
18
- const useLocalGui = args.includes('--local-gui')
19
- const createPack = args.includes('--pack')
20
-
21
- const scriptDir = __dirname
22
- const publicDest = path.join(scriptDir, 'public')
23
-
24
- /**
25
- * Recursively copy directory contents
26
- */
27
- function copyDir(src, dest) {
28
- if (!fs.existsSync(src)) {
29
- console.error(`Source directory not found: ${src}`)
30
- process.exit(1)
31
- }
32
-
33
- if (fs.existsSync(dest)) {
34
- fs.rmSync(dest, { recursive: true })
35
- }
36
-
37
- fs.mkdirSync(dest, { recursive: true })
38
-
39
- const entries = fs.readdirSync(src, { withFileTypes: true })
40
- for (const entry of entries) {
41
- const srcPath = path.join(src, entry.name)
42
- const destPath = path.join(dest, entry.name)
43
- if (entry.isDirectory()) {
44
- copyDir(srcPath, destPath)
45
- } else {
46
- fs.copyFileSync(srcPath, destPath)
47
- }
48
- }
49
- }
50
-
51
- /**
52
- * Copy GUI from npm package
53
- */
54
- function setupGuiFromNpm() {
55
- console.log('Copying GUI from node_modules...\n')
56
-
57
- const guiSource = path.join(scriptDir, 'node_modules', '@marineyachtradar', 'mayara-gui')
58
-
59
- if (!fs.existsSync(guiSource)) {
60
- console.error('Error: @marineyachtradar/mayara-gui not found in node_modules')
61
- console.error('Make sure it is listed in package.json dependencies')
62
- process.exit(1)
63
- }
64
-
65
- if (fs.existsSync(publicDest)) {
66
- fs.rmSync(publicDest, { recursive: true })
67
- }
68
- fs.mkdirSync(publicDest, { recursive: true })
69
-
70
- // Copy GUI files (exclude package.json, node_modules, etc.)
71
- const guiPatterns = [
72
- { ext: '.html' },
73
- { ext: '.js' },
74
- { ext: '.css' },
75
- { ext: '.ico' },
76
- { ext: '.svg' },
77
- { dir: 'assets' },
78
- { dir: 'proto' },
79
- { dir: 'protobuf' }
80
- ]
81
-
82
- // Exclude recordings.html since we have our own playback UI
83
- const excludeFiles = ['recordings.html', 'recordings.js', 'recordings.css']
84
-
85
- const entries = fs.readdirSync(guiSource, { withFileTypes: true })
86
- for (const entry of entries) {
87
- if (excludeFiles.includes(entry.name)) continue
88
-
89
- const srcPath = path.join(guiSource, entry.name)
90
- const destPath = path.join(publicDest, entry.name)
91
-
92
- if (entry.isDirectory()) {
93
- if (guiPatterns.some(p => p.dir === entry.name)) {
94
- copyDir(srcPath, destPath)
95
- }
96
- } else {
97
- if (guiPatterns.some(p => p.ext && entry.name.endsWith(p.ext))) {
98
- fs.copyFileSync(srcPath, destPath)
99
- }
100
- }
101
- }
102
-
103
- // Copy our custom files from plugin/public/ (overrides GUI files)
104
- const pluginPublic = path.join(scriptDir, 'plugin', 'public')
105
- if (fs.existsSync(pluginPublic)) {
106
- const customEntries = fs.readdirSync(pluginPublic, { withFileTypes: true })
107
- let customCount = 0
108
- for (const entry of customEntries) {
109
- const srcPath = path.join(pluginPublic, entry.name)
110
- const destPath = path.join(publicDest, entry.name)
111
- if (entry.isDirectory()) {
112
- copyDir(srcPath, destPath)
113
- customCount++
114
- } else {
115
- fs.copyFileSync(srcPath, destPath)
116
- customCount++
117
- }
118
- }
119
- console.log(`Added ${customCount} custom files from plugin/public/`)
120
- }
121
-
122
- const fileCount = fs.readdirSync(publicDest, { recursive: true }).length
123
- console.log(`Copied ${fileCount} GUI files to public/\n`)
124
- }
125
-
126
- /**
127
- * Copy GUI from local sibling directory (for development)
128
- */
129
- function setupGuiFromLocal() {
130
- const localGuiPath = path.join(scriptDir, '..', 'mayara-gui')
131
- console.log(`Copying GUI from local ${localGuiPath}...\n`)
132
-
133
- if (fs.existsSync(publicDest)) {
134
- fs.rmSync(publicDest, { recursive: true })
135
- }
136
- fs.mkdirSync(publicDest, { recursive: true })
137
-
138
- const guiPatterns = [
139
- { ext: '.html' },
140
- { ext: '.js' },
141
- { ext: '.css' },
142
- { ext: '.ico' },
143
- { ext: '.svg' },
144
- { dir: 'assets' },
145
- { dir: 'proto' },
146
- { dir: 'protobuf' }
147
- ]
148
-
149
- // Exclude recordings files since we have our own playback UI
150
- const excludeFiles = ['recordings.html', 'recordings.js', 'recordings.css']
151
-
152
- const entries = fs.readdirSync(localGuiPath, { withFileTypes: true })
153
- for (const entry of entries) {
154
- if (excludeFiles.includes(entry.name)) continue
155
-
156
- const srcPath = path.join(localGuiPath, entry.name)
157
- const destPath = path.join(publicDest, entry.name)
158
-
159
- if (entry.isDirectory()) {
160
- if (guiPatterns.some(p => p.dir === entry.name)) {
161
- copyDir(srcPath, destPath)
162
- }
163
- } else {
164
- if (guiPatterns.some(p => p.ext && entry.name.endsWith(p.ext))) {
165
- fs.copyFileSync(srcPath, destPath)
166
- }
167
- }
168
- }
169
-
170
- // Copy our custom files from plugin/public/ (overrides GUI files)
171
- const pluginPublic = path.join(scriptDir, 'plugin', 'public')
172
- if (fs.existsSync(pluginPublic)) {
173
- const customEntries = fs.readdirSync(pluginPublic, { withFileTypes: true })
174
- let customCount = 0
175
- for (const entry of customEntries) {
176
- const srcPath = path.join(pluginPublic, entry.name)
177
- const destPath = path.join(publicDest, entry.name)
178
- if (entry.isDirectory()) {
179
- copyDir(srcPath, destPath)
180
- customCount++
181
- } else {
182
- fs.copyFileSync(srcPath, destPath)
183
- customCount++
184
- }
185
- }
186
- console.log(`Added ${customCount} custom files from plugin/public/`)
187
- }
188
-
189
- const fileCount = fs.readdirSync(publicDest, { recursive: true }).length
190
- console.log(`Copied ${fileCount} files from local mayara-gui/ to public/\n`)
191
- }
192
-
193
- function main() {
194
- console.log('=== MaYaRa SignalK Playback Plugin Build ===\n')
195
-
196
- // Skip build if public/ already exists with content (installed from --pack tarball)
197
- // This prevents postinstall from failing when mayara-gui isn't in node_modules
198
- if (fs.existsSync(publicDest) && !useLocalGui && !createPack) {
199
- const files = fs.readdirSync(publicDest)
200
- if (files.length > 0) {
201
- console.log(`public/ already exists with ${files.length} files (installed from tarball)`)
202
- console.log('Skipping build.\n')
203
- console.log('=== Build complete ===')
204
- return
205
- }
206
- }
207
-
208
- if (useLocalGui) {
209
- setupGuiFromLocal()
210
- } else {
211
- setupGuiFromNpm()
212
- }
213
-
214
- // Create tarball if --pack flag is set
215
- if (createPack) {
216
- console.log('Creating tarball with public/ included...\n')
217
-
218
- // Temporarily remove public/ from .npmignore
219
- const npmignorePath = path.join(scriptDir, '.npmignore')
220
- const npmignoreContent = fs.readFileSync(npmignorePath, 'utf8')
221
- const npmignoreWithoutPublic = npmignoreContent.replace(/^public\/\n?/m, '')
222
- fs.writeFileSync(npmignorePath, npmignoreWithoutPublic)
223
-
224
- // Also temporarily add public/ to files in package.json
225
- const pkgPath = path.join(scriptDir, 'package.json')
226
- const pkgContent = fs.readFileSync(pkgPath, 'utf8')
227
- const pkg = JSON.parse(pkgContent)
228
- const originalFiles = [...pkg.files]
229
- pkg.files.push('public/**/*')
230
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
231
-
232
- try {
233
- // Run npm pack
234
- execSync('npm pack', { stdio: 'inherit', cwd: scriptDir })
235
- console.log('\nTarball created successfully!')
236
- } finally {
237
- // Restore .npmignore
238
- fs.writeFileSync(npmignorePath, npmignoreContent)
239
- // Restore package.json
240
- pkg.files = originalFiles
241
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
242
- }
243
- }
244
-
245
- console.log('\n=== Build complete ===')
246
- }
247
-
248
- main()