Skip to content

Commit

Permalink
🔧 add bundle for multi nodejs versions
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGFx committed Apr 19, 2020
1 parent 74781aa commit 17cbeee
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist
build
!.gitkeep
*.tar.gz
bundle

public/icons/*

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ This project was based on the [TruckSim-Telemetry-Demo](https://github.com/kniff

All development are made under **Windows**. It's not operable under all Linux OS.

The view is optimized for a `5.5"` screen. To develop on you web browser, you can set phone view to `800px * 455px`
The view is optimized for a `5.5"` screen. To develop on you web browser, you can set phone view to `800px * 455px`

## Requirements

- OS: Windows 64Bits
- NodeJS: v10, v12 or v13

All current NodeJS version and LTS are supported. See the [NodeJS Release](https://nodejs.org/en/about/releases/) page to get more informations

## Quick use

Expand Down
Binary file added bin/scsSDKTelemetry.node10
Binary file not shown.
Binary file added bin/scsSDKTelemetry.node12
Binary file not shown.
Binary file added bin/scsSDKTelemetry.node13
Binary file not shown.
101 changes: 80 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ const fs = require( 'fs-extra' );
const tar = require( 'gulp-tar' );
const gzip = require( 'gulp-gzip' );
const path = require( 'path' );
const exec = require( 'child_process' ).execSync;

const pkg = require( './package.json' );
const pkgServer = require( './server/package.json' );

const pkg = require( './package.json' );

// ---------------------------------------------
// --- Variables
// ---------------------------------------------


// --- Font icons
const iconDist = 'resources/dist/';
const iconSvgs = 'resources/icons/svgs/*.svg';
Expand All @@ -25,29 +29,52 @@ const iconDistFontFiles = [
const iconDestFiles = 'public/icons/';

// --- Bundle
const filesToZip = [
const filesToZip = [
'./doc',
'./LICENSE',
'./package.json',
'./README.md',
'./screenshot.png'
];
const bundleFileName = `${ pkg.name }_v${ pkg.version }`;
const archiveName = `${ bundleFileName }.tar`;
const archiveTemp = './build';
const exeServerPathDest = `${ archiveTemp }/${ bundleFileName }`;
const destZip = './';
const sdkTelemetryName = 'scsSDKTelemetry';
const binPath = './bin/';
const bundleFileName = `${ pkg.name }_v${ pkg.version }`;
const archiveTemp = './build';
const destZip = './bundle';
const nodeVersionTargets = pkgServer.pkg.targets;


// ---------------------------------------------
// --- Tasks
// --- Methods
// ---------------------------------------------
const getExeServerTargetNode = () => {
const nodeVersion = process.version.match( /^v(\d{2})/ )[ 1 ];

return `node${ nodeVersion }-win`;


const getExeServerTargetNode = ( nodeTarget ) => {
return `${ nodeTarget }-win`;
};

const getExeServerPathDest = ( nodeTarget ) => {
return `${ archiveTemp }/${ nodeTarget }/${ bundleFileName }`;
};

const getTargetBuildPath = ( nodeTarget, filename ) => {
return path.resolve( archiveTemp, nodeTarget, filename );
};

const getTargetBinPath = ( filename ) => {
return path.resolve( binPath, filename );
};

const getArchiveName = ( nodeTarget ) => {
return `${ bundleFileName }_${ nodeTarget }.tar`;
};


// ---------------------------------------------
// --- Tasks
// ---------------------------------------------


// --- Font icons
gulp.task( 'build:font:init-folder', ( cb ) => {
if ( !fs.existsSync( iconDist ) ) {
Expand All @@ -72,30 +99,62 @@ gulp.task( 'bundle:clean', ( cb ) => {
if ( fs.existsSync( archiveTemp ) ) {
fs.removeSync( archiveTemp );
fs.mkdirSync( archiveTemp );

nodeVersionTargets.forEach( function ( currentTarget ) {
const nvtPath = path.resolve( archiveTemp, currentTarget );

fs.mkdirSync( nvtPath );
} );

console.log( `\t> Clean and empty created ${ archiveTemp }` );
}
cb();
} );
gulp.task( 'bundle:copy', ( cb ) => {
filesToZip.forEach( function ( value ) {
const destPath = path.resolve( archiveTemp, value.replace( '*', '' ) );
console.log( `\t> Coping ${ value } to ${ destPath }` );
nodeVersionTargets.forEach( function ( currentTarget ) {
const scsTelemetryBinFileName = `${ sdkTelemetryName }.${ currentTarget }`;
const scsTelemetryBuildFileName = `${ sdkTelemetryName }.node`;

fs.copySync( value, destPath );
filesToZip.forEach( function ( value ) {
const destPath = getTargetBuildPath( currentTarget, value );
console.log( `\t> Coping ${ value } to ${ destPath }` );

fs.copySync( value, destPath );
} );

fs.copySync( getTargetBinPath( scsTelemetryBinFileName ),
getTargetBuildPath( currentTarget, scsTelemetryBuildFileName ) );
} );


cb();
} );

gulp.task( 'bundle:server', run( `npx pkg ./server -t ${ getExeServerTargetNode() } -o ${ exeServerPathDest }` ) );
gulp.task( 'bundle:server', ( cb ) => {
nodeVersionTargets.forEach( function ( currentTarget ) {
console.log( `\t> Generate *.exe file for ${ currentTarget }` );
exec( `npx pkg ./server -t ${ getExeServerTargetNode( currentTarget ) } -o ${ getExeServerPathDest(
currentTarget ) }` );
} );

console.log( `\t> All *.exe was generated` );
cb();
} );

gulp.task( 'bundle:gzip', () => {
return gulp.src( archiveTemp + '/**' )
.pipe( tar( archiveName ) )
.pipe( gzip() )
.pipe( gulp.dest( destZip ) );
let g = null;

nodeVersionTargets.forEach( function ( currentTarget ) {
g = gulp.src( getTargetBuildPath( currentTarget, './**' ) )
.pipe( tar( getArchiveName( currentTarget ) ) )
.pipe( gzip() )
.pipe( gulp.dest( destZip ) );
} );

return g;
} );

// --- Build full package
gulp.task( 'build', gulp.series( 'build:font', 'build:dashboard', 'build:server' ) );
gulp.task( 'bundle', gulp.series( 'bundle:clean', 'bundle:copy', 'bundle:server', 'bundle:gzip' ) );
gulp.task( 'bAndB', gulp.series( 'build', 'bundle' ) );
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
"homepage" : "https://jagfx.github.io/ets2-dashboard-skin/",
"private" : false,
"main" : "index.js",
"scripts" : {
"scripts" : {
"server:build" : "cd server && npx gulp",
"server:start" : "cd server && node ./dist/index.js",
"dashboard:dev" : "vue-cli-service serve",
"dashboard:build" : "vue-cli-service build",
"dashboard:start" : "http-server dist/",
"font:build" : "npx gulp build:font",
"build" : "npx gulp build",
"bundle" : "npx gulp bundle"
"bundle" : "npx gulp bundle",
"bAndB" : "npx gulp bAndB"
},
"dependencies" : {
"animate.css" : "^3.7.2",
Expand Down
7 changes: 4 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'path';
import http from 'http';
import express from 'express';
import http from 'http';
import path from 'path';
import socketio from 'socket.io';
import truckSimTelemetry from 'trucksim-telemetry';
import pkgDash from '../package.json';

const app = express();
const server = http.createServer( app );
Expand Down Expand Up @@ -74,5 +75,5 @@ io.on( 'connection', function ( socket ) {
} );

server.listen( 3000, function () {
console.log( 'TruckSim-Telemetry Demo is running at http://localhost:3000/' );
console.log( `${ pkgDash.description } is running at http://localhost:3000/` );
} );
2 changes: 1 addition & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"../dist/"
],
"targets" : [
"node10",
"node12",
"node13"
]
}
Expand Down

0 comments on commit 17cbeee

Please sign in to comment.