@marineyachtradar/signalk-plugin 0.1.3 → 0.2.1

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,214 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Build script for mayara-server-signalk-plugin
4
- *
5
- * Downloads @marineyachtradar/mayara-gui from npm and copies GUI files to public/
6
- *
7
- * Usage: node build.js [options]
8
- * --local-gui Use local mayara-gui instead of npm (for development)
9
- * --pack Create a .tgz tarball with public/ included (for manual install)
10
- */
11
-
12
- const fs = require('fs')
13
- const path = require('path')
14
- const { execSync } = require('child_process')
15
-
16
- const args = process.argv.slice(2)
17
- const useLocalGui = args.includes('--local-gui')
18
- const createPack = args.includes('--pack')
19
-
20
- // Paths (relative to this script's directory)
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
- // Remove destination if it exists
34
- if (fs.existsSync(dest)) {
35
- fs.rmSync(dest, { recursive: true })
36
- }
37
-
38
- // Create destination directory
39
- fs.mkdirSync(dest, { recursive: true })
40
-
41
- // Copy all files and subdirectories
42
- const entries = fs.readdirSync(src, { withFileTypes: true })
43
- for (const entry of entries) {
44
- const srcPath = path.join(src, entry.name)
45
- const destPath = path.join(dest, entry.name)
46
- if (entry.isDirectory()) {
47
- copyDir(srcPath, destPath)
48
- } else {
49
- fs.copyFileSync(srcPath, destPath)
50
- }
51
- }
52
- }
53
-
54
- /**
55
- * Download GUI from npm and copy to public/
56
- */
57
- function setupGuiFromNpm() {
58
- console.log('Copying GUI from node_modules...\n')
59
-
60
- // Dependencies should already be installed by npm install
61
- // (this script runs as postinstall, so node_modules exists)
62
- const guiSource = path.join(scriptDir, 'node_modules', '@marineyachtradar', 'mayara-gui')
63
-
64
- if (!fs.existsSync(guiSource)) {
65
- console.error('Error: @marineyachtradar/mayara-gui not found in node_modules')
66
- console.error('Make sure it is listed in package.json dependencies')
67
- process.exit(1)
68
- }
69
-
70
- // Remove old public dir
71
- if (fs.existsSync(publicDest)) {
72
- fs.rmSync(publicDest, { recursive: true })
73
- }
74
- fs.mkdirSync(publicDest, { recursive: true })
75
-
76
- // Copy GUI files (exclude package.json, node_modules, etc.)
77
- const guiPatterns = [
78
- { ext: '.html' },
79
- { ext: '.js' },
80
- { ext: '.css' },
81
- { ext: '.ico' },
82
- { ext: '.svg' },
83
- { dir: 'assets' },
84
- { dir: 'proto' },
85
- { dir: 'protobuf' }
86
- ]
87
-
88
- const entries = fs.readdirSync(guiSource, { withFileTypes: true })
89
- for (const entry of entries) {
90
- const srcPath = path.join(guiSource, entry.name)
91
- const destPath = path.join(publicDest, entry.name)
92
-
93
- if (entry.isDirectory()) {
94
- // Copy known directories
95
- if (guiPatterns.some(p => p.dir === entry.name)) {
96
- copyDir(srcPath, destPath)
97
- }
98
- } else {
99
- // Copy files matching extensions
100
- if (guiPatterns.some(p => p.ext && entry.name.endsWith(p.ext))) {
101
- fs.copyFileSync(srcPath, destPath)
102
- }
103
- }
104
- }
105
-
106
- const fileCount = fs.readdirSync(publicDest, { recursive: true }).length
107
- console.log(`Copied ${fileCount} GUI files to public/\n`)
108
- }
109
-
110
- /**
111
- * Copy GUI from local sibling directory (for development)
112
- */
113
- function setupGuiFromLocal() {
114
- const localGuiPath = path.join(scriptDir, '..', 'mayara-gui')
115
- console.log(`Copying GUI from local ${localGuiPath}...\n`)
116
-
117
- // Remove old public dir
118
- if (fs.existsSync(publicDest)) {
119
- fs.rmSync(publicDest, { recursive: true })
120
- }
121
- fs.mkdirSync(publicDest, { recursive: true })
122
-
123
- // Copy GUI files (exclude package.json, node_modules, .git, etc.)
124
- const guiPatterns = [
125
- { ext: '.html' },
126
- { ext: '.js' },
127
- { ext: '.css' },
128
- { ext: '.ico' },
129
- { ext: '.svg' },
130
- { dir: 'assets' },
131
- { dir: 'proto' },
132
- { dir: 'protobuf' }
133
- ]
134
-
135
- const entries = fs.readdirSync(localGuiPath, { withFileTypes: true })
136
- for (const entry of entries) {
137
- const srcPath = path.join(localGuiPath, entry.name)
138
- const destPath = path.join(publicDest, entry.name)
139
-
140
- if (entry.isDirectory()) {
141
- // Copy known directories
142
- if (guiPatterns.some(p => p.dir === entry.name)) {
143
- copyDir(srcPath, destPath)
144
- }
145
- } else {
146
- // Copy files matching extensions
147
- if (guiPatterns.some(p => p.ext && entry.name.endsWith(p.ext))) {
148
- fs.copyFileSync(srcPath, destPath)
149
- }
150
- }
151
- }
152
-
153
- const fileCount = fs.readdirSync(publicDest, { recursive: true }).length
154
- console.log(`Copied ${fileCount} files from local mayara-gui/ to public/\n`)
155
- }
156
-
157
- function main() {
158
- console.log('=== MaYaRa SignalK Plugin Build ===\n')
159
-
160
- // Skip build if public/ already exists with content (installed from --pack tarball)
161
- // This prevents postinstall from failing when mayara-gui isn't in node_modules
162
- if (fs.existsSync(publicDest) && !useLocalGui && !createPack) {
163
- const files = fs.readdirSync(publicDest)
164
- if (files.length > 0) {
165
- console.log(`public/ already exists with ${files.length} files (installed from tarball)`)
166
- console.log('Skipping build.\n')
167
- console.log('=== Build complete ===')
168
- return
169
- }
170
- }
171
-
172
- // Get GUI assets
173
- console.log('Setting up GUI assets...\n')
174
- if (useLocalGui) {
175
- setupGuiFromLocal()
176
- } else {
177
- setupGuiFromNpm()
178
- }
179
-
180
- // Create tarball if --pack flag is set
181
- if (createPack) {
182
- console.log('Creating tarball with public/ included...\n')
183
-
184
- // Temporarily remove public/ from .npmignore
185
- const npmignorePath = path.join(scriptDir, '.npmignore')
186
- const npmignoreContent = fs.readFileSync(npmignorePath, 'utf8')
187
- const npmignoreWithoutPublic = npmignoreContent.replace(/^public\/\n?/m, '')
188
- fs.writeFileSync(npmignorePath, npmignoreWithoutPublic)
189
-
190
- // Also temporarily add public/ to files in package.json
191
- const pkgPath = path.join(scriptDir, 'package.json')
192
- const pkgContent = fs.readFileSync(pkgPath, 'utf8')
193
- const pkg = JSON.parse(pkgContent)
194
- const originalFiles = [...pkg.files]
195
- pkg.files.push('public/**/*')
196
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
197
-
198
- try {
199
- // Run npm pack
200
- execSync('npm pack', { stdio: 'inherit', cwd: scriptDir })
201
- console.log('\nTarball created successfully!')
202
- } finally {
203
- // Restore .npmignore
204
- fs.writeFileSync(npmignorePath, npmignoreContent)
205
- // Restore package.json
206
- pkg.files = originalFiles
207
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
208
- }
209
- }
210
-
211
- console.log('\n=== Build complete ===')
212
- }
213
-
214
- main()