forked from nospaceships/node-os-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: build native module on Windows only (#29)
- Loading branch information
Showing
4 changed files
with
40 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var os = require('os'); | ||
var path = require('path'); | ||
var child = require('child_process'); | ||
|
||
if (os.platform() === 'win32') { | ||
var npmProcess = child.spawn('npm', ['run', 'native_install'], { | ||
input: 'Windows detected. Installing native module.', | ||
stdio: 'inherit', | ||
cwd: path.resolve(__dirname, '..'), | ||
env: process.env, | ||
windowsHide: true, | ||
shell: true | ||
}); | ||
|
||
// Handle child process exit | ||
npmProcess.on('exit', function (code, signal) { | ||
if (code !== null) { | ||
console.log(`Child process exited with code ${code}`); | ||
} else if (signal !== null) { | ||
console.log(`Child process was terminated by signal ${signal}`); | ||
} | ||
}); | ||
|
||
// Handle child process errors | ||
npmProcess.on('error', function (error) { | ||
console.error('Error occurred:', error); | ||
}); | ||
|
||
// Forward parent process signals to the child process | ||
function forwardSignal(signal) { | ||
if (npmProcess.pid) { | ||
npmProcess.kill(signal); | ||
} | ||
} | ||
|
||
process.on('SIGTERM', forwardSignal); | ||
process.on('SIGINT', forwardSignal); | ||
} |