forked from papyrus-mc/papyrusjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
48 lines (35 loc) · 2.24 KB
/
build.js
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
const json_package = require( './package.json' );
const { exec } = require( 'pkg' )
const colors = require( 'colors' );
const path = require( 'path' );
const fs = require('fs-extra');
(async function() {
var destinationDir = ( __dirname + '/dist/release/' ),
copyDir = '';
console.log( 'Building ' + colors.bold( json_package.name.charAt( 0 ) + json_package.name.slice( 1, json_package.name.length - 2 ) + '.' + json_package.name.slice( json_package.name.length - 2 ) + ' v' + json_package.version + '-' + json_package.version_stage ) );
console.log( 'Patching modules...' );
var patchContent = fs.readFileSync( './node_modules/mapnik/lib/mapnik.js' ).toString();
patchContent = patchContent.replace( "var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));", "var binding_path = binary.find(path.resolve(path.join('./node_modules/mapnik/package.json')));" );
fs.writeFileSync( './node_modules/mapnik/lib/mapnik.js', patchContent );
console.log( 'Packing application using pkg...' );
await exec( [ 'app.js','--target=node10-linux-x64','--output='+destinationDir+'/papyrus' ] );
console.log( 'Copying native modules to destination directory...' );
fs.mkdirSync( destinationDir + '/node_modules/' );
var currentModule;
currentModule = 'leveldb-mcpe';
console.log( 'Module:\t' + currentModule );
copyDir = '/node_modules/' + currentModule + '/build/Release/node_leveldb_mcpe_native.node';
fs.copySync( __dirname + copyDir, destinationDir + copyDir );
currentModule = 'mapnik';
console.log( 'Module:\t' + currentModule );
fs.mkdirSync( destinationDir + '/node_modules/' + currentModule );
copyDir = '/node_modules/' + currentModule + '/package.json';
fs.copyFileSync( __dirname + copyDir, destinationDir + copyDir );
copyDir = '/node_modules/' + currentModule + '/LICENSE.txt';
fs.copyFileSync( __dirname + copyDir, destinationDir + copyDir );
copyDir = '/node_modules/' + currentModule + '/lib/binding/';
fs.copySync( __dirname + copyDir, destinationDir + copyDir );
fs.removeSync( destinationDir + copyDir + 'share' )
fs.removeSync( destinationDir + copyDir + 'lib/mapnik' );
console.log( 'Done. Ready for deployment!' );
}());