Skip to content

Commit

Permalink
find node module version automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
mimecorg committed Jun 9, 2018
1 parent c42f074 commit 4133833
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tools/build-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ function buildNodeWin32( arch ) {
}

function buildNode() {
const { getNodeModuleVersion } = require( './utils' );

console.log( 'Building node for ' + process.platform + '-' + process.arch );

const nodeVersion = getNodeModuleVersion();

const nodeDir = path.join( __dirname, '../deps/node' );

let result = child_process.spawnSync( './configure', [ '--shared' ], { cwd: nodeDir, stdio: 'inherit' } );
Expand All @@ -50,7 +54,9 @@ function buildNode() {
throw result.error;

if ( process.platform == 'darwin' ) {
result = child_process.spawnSync( 'install_name_tool', [ '-id', '@rpath/libnode.57.dylib', 'out/Release/libnode.57.dylib' ], { cwd: nodeDir, stdio: 'inherit' } );
const args = [ '-id', '@rpath/libnode.' + nodeVersion + '.dylib', 'out/Release/libnode.' + nodeVersion + '.dylib' ];

result = child_process.spawnSync( 'install_name_tool', args, { cwd: nodeDir, stdio: 'inherit' } );

if ( result.error != null )
throw result.error;
Expand Down
12 changes: 10 additions & 2 deletions tools/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ function packageWin32( arch ) {
}

function packageDarwin() {
const { getNodeModuleVersion } = require( './utils' );

console.log( 'Creating package for darwin-' + process.arch );

const nodeVersion = getNodeModuleVersion();

const packagesDir = path.join( __dirname, '../packages' );

if ( !fs.existsSync( packagesDir ) )
Expand All @@ -86,7 +90,7 @@ function packageDarwin() {
const macosDir = contentsDir + 'MacOS/'

archive.file( path.join( __dirname, '../build/launchui' ), { name: macosDir + 'launchui' } );
archive.file( path.join( __dirname, '../deps/node/out/Release/libnode.57.dylib' ), { name: macosDir + 'libnode.57.dylib' } );
archive.file( path.join( __dirname, '../deps/node/out/Release/libnode.' + nodeVersion + '.dylib' ), { name: macosDir + 'libnode.' + nodeVersion + '.dylib' } );
archive.file( path.join( __dirname, '../deps/libui/build/out/libui.A.dylib' ), { name: macosDir + 'libui.A.dylib' } );

const resourcesDir = contentsDir + 'Resources/';
Expand All @@ -99,8 +103,12 @@ function packageDarwin() {
}

function package() {
const { getNodeModuleVersion } = require( './utils' );

console.log( 'Creating package for ' + process.platform + '-' + process.arch );

const nodeVersion = getNodeModuleVersion();

const packagesDir = path.join( __dirname, '../packages' );

if ( !fs.existsSync( packagesDir ) )
Expand All @@ -114,7 +122,7 @@ function package() {
archive.pipe( output );

archive.file( path.join( __dirname, '../build/launchui' ), { name: 'launchui' } );
archive.file( path.join( __dirname, '../deps/node/out/Release/lib.target/libnode.so.57' ), { name: 'libnode.so.57' } );
archive.file( path.join( __dirname, '../deps/node/out/Release/lib.target/libnode.so.' + nodeVersion ), { name: 'libnode.so.' + nodeVersion } );
archive.file( path.join( __dirname, '../deps/libui/build/out/libui.so.0' ), { name: 'libui.so.0' } );

packageCommon( archive, '' );
Expand Down
19 changes: 19 additions & 0 deletions tools/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require( 'path' );
const fs = require( 'fs' );

function getNodeModuleVersion() {
const filePath = path.join( __dirname, '../deps/node/src/node_version.h' );

const body = fs.readFileSync( filePath, 'utf8' );

const matches = /#define NODE_MODULE_VERSION ([0-9]+)/.exec( body );

if ( matches == null )
throw new Error( 'Could not find node module version' );

return matches[ 1 ];
}

module.exports = {
getNodeModuleVersion
};

0 comments on commit 4133833

Please sign in to comment.