MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / buildWithWSL

Function buildWithWSL

scripts/build-linux-appimage.js:67–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66// Build using WSL
67function buildWithWSL() {
68 console.log('Using WSL for Linux build...\n');
69
70 const wslProjectRoot = toWSLPath(projectRoot);
71 const wslDistDir = toWSLPath(distDir);
72
73 // Check if Node.js is installed in WSL
74 try {
75 execSync('wsl which node', { stdio: 'ignore' });
76 } catch (error) {
77 console.error('ERROR: Node.js not found in WSL.');
78 console.error('Please install Node.js in your WSL distribution:');
79 console.error(getWslInstallHint());
80 console.error('\nTip: Podman Machine\'s WSL VM is not a dev environment. Prefer container build:');
81 console.error(' Ensure Podman/Docker is available (Podman Desktop adds podman to PATH), or use a Ubuntu WSL distro.');
82 process.exit(1);
83 }
84
85 // Always install/rebuild dependencies in WSL to ensure native modules are built for Linux
86 // Windows node_modules won't work for Linux builds (especially better-sqlite3)
87 console.log('Installing/rebuilding dependencies in WSL (native modules need Linux build)...');
88 try {
89 execSync(`wsl bash -c "cd '${wslProjectRoot}' && npm install"`, { stdio: 'inherit' });
90 } catch (error) {
91 console.error('Failed to install dependencies in WSL');
92 process.exit(1);
93 }
94
95 // Clean any existing native module builds to ensure fresh rebuild
96 console.log('Cleaning existing native module builds...');
97 try {
98 execSync(`wsl bash -c "cd '${wslProjectRoot}' && rm -rf node_modules/better-sqlite3/build"`, { stdio: 'inherit' });
99 } catch (error) {
100 // Ignore errors if directory doesn't exist
101 }
102
103 // Explicitly rebuild native modules for Electron on Linux
104 // Use @electron/rebuild which is more reliable than electron-builder install-app-deps
105 console.log('Rebuilding native modules for Electron on Linux...');
106 try {
107 execSync(`wsl bash -c "cd '${wslProjectRoot}' && npx @electron/rebuild --version=\$(node -p 'require(\\\"electron/package.json\\\").version')"`, { stdio: 'inherit' });
108 } catch (error) {
109 console.error('Failed to rebuild native modules for Electron');
110 console.error('Trying alternative method...');
111 // Fallback to electron-builder install-app-deps
112 try {
113 execSync(`wsl bash -c "cd '${wslProjectRoot}' && npx electron-builder install-app-deps"`, { stdio: 'inherit' });
114 } catch (fallbackError) {
115 console.error('Both rebuild methods failed. Please ensure build tools are installed in WSL:');
116 console.error(' wsl sudo apt-get update');
117 console.error(' wsl sudo apt-get install -y build-essential python3');
118 process.exit(1);
119 }
120 }
121
122 // Verify the native module was built correctly
123 console.log('Verifying native module build...');
124 try {

Callers 1

mainFunction · 0.85

Calls 2

toWSLPathFunction · 0.85
getWslInstallHintFunction · 0.85

Tested by

no test coverage detected