forked from audioling/audioling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-server.ts
More file actions
73 lines (52 loc) · 2.34 KB
/
deploy-server.ts
File metadata and controls
73 lines (52 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { $ } from 'bun';
import { execSync } from 'child_process';
import console from 'console';
import fs from 'fs';
async function main() {
const args = process.argv.slice(2);
const targetTripleOverride = args[0];
await Promise.all([$`bun run build:packages`]);
await Promise.all([$`bun run build:server:desktop`]);
await renameSidecar(targetTripleOverride);
}
async function renameSidecar(targetTripleOverride?: string) {
return new Promise((resolve, reject) => {
try {
const cwd = process.cwd();
console.log('cwd :>> ', cwd);
const extension = process.platform === 'win32' ? '.exe' : '';
let targetTriple = targetTripleOverride;
if (!targetTriple) {
const rustInfo = execSync('rustc -vV');
targetTriple = /host: (\S+)/g.exec(rustInfo as any)?.[1];
}
console.log('targetTriple', targetTriple, extension);
if (!targetTriple) {
console.error('Failed to determine platform target triple');
}
const binaryPath = `./apps/server/dist/audioling-server${extension}`;
console.log('binaryPath', binaryPath);
const isBinaryExists = fs.existsSync(binaryPath);
if (!isBinaryExists) {
throw new Error('Binary not found, erroring...');
}
console.log('isBinaryExists', isBinaryExists);
const targetDirectory = `./apps/web/src-tauri/target/external`;
const isTargetDirectoryExists = fs.existsSync(targetDirectory);
if (!isTargetDirectoryExists) {
console.log('Target directory not found, creating...');
fs.mkdirSync(targetDirectory, { recursive: true });
console.log('Target directory created: ', targetDirectory);
}
const binaryName = `audioling-server-${targetTriple}${extension}`;
console.log('isTargetDirectoryExists', isTargetDirectoryExists);
console.log('Moving binary to target directory...');
fs.renameSync(binaryPath, `${targetDirectory}/${binaryName}`);
console.log('Binary moved to target directory: ', `${targetDirectory}/${binaryName}`);
} catch (error) {
reject(error);
}
resolve(null);
});
}
main();