First commit
This commit is contained in:
141
framework/node_modules/node-gpp/child.js
generated
vendored
Normal file
141
framework/node_modules/node-gpp/child.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2020, 2023, The Unified Company.
|
||||
|
||||
This code is part of Unify.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the ESA Software Community License - Strong Copyleft,
|
||||
|
||||
https://unifyjs.org
|
||||
|
||||
*/
|
||||
|
||||
|
||||
String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); }
|
||||
|
||||
|
||||
|
||||
var execPromises = new Array();
|
||||
|
||||
|
||||
if( process.platform == "android" ) {
|
||||
|
||||
exports.gpp = class gpp{
|
||||
|
||||
convert( a ) {
|
||||
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var factory = require('./api_example.js');
|
||||
|
||||
var path = require('path');
|
||||
|
||||
const util = require('util');
|
||||
|
||||
const childProcess = require('child_process');
|
||||
|
||||
const { gpp } = require('./gpp.js');
|
||||
|
||||
var spawn = childProcess.spawn;
|
||||
|
||||
var batchSize = 70;
|
||||
|
||||
|
||||
var gppInstance = new gpp();
|
||||
|
||||
|
||||
|
||||
exports.gpp = class gppManager{
|
||||
|
||||
getNumberOfDots( numberOfBatches ) {
|
||||
|
||||
if( numberOfBatches < 100 ){
|
||||
|
||||
return numberOfBatches;
|
||||
|
||||
} else {
|
||||
|
||||
return 100;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logConverter( coreNumber, inputFiles, numberOfBatches ) {
|
||||
|
||||
console.log( "Batches", numberOfBatches );
|
||||
|
||||
console.log( "Processing", inputFiles.length, "files" );
|
||||
|
||||
console.log( "Multicore support: processing batches with ", coreNumber, "cores." );
|
||||
|
||||
//console.log("[");
|
||||
|
||||
//process.stdout.moveCursor( numberOfDots + 2, -1);
|
||||
|
||||
//console.log("]");
|
||||
|
||||
console.log("");
|
||||
|
||||
}
|
||||
|
||||
async convert_files() {
|
||||
|
||||
var filesPath = path.resolve( "./framework/cache/platforms/files.json" );
|
||||
|
||||
var sourceRaw = await fs.readFileSync( filesPath, "utf8" )
|
||||
|
||||
var inputFiles = JSON.parse( sourceRaw );
|
||||
|
||||
var numberOfBatches = Math.floor( inputFiles.length / batchSize );
|
||||
|
||||
var totalFiles = batchSize * numberOfBatches + 1;
|
||||
|
||||
var os = require('os');
|
||||
|
||||
var readline = require('readline');
|
||||
|
||||
const coreNumber = os.cpus().length;
|
||||
|
||||
|
||||
var numberOfDots = this.getNumberOfDots( numberOfBatches );
|
||||
|
||||
|
||||
this.logConverter( coreNumber, inputFiles, numberOfBatches );
|
||||
|
||||
|
||||
if( process.stdout.moveCursor ) {
|
||||
|
||||
for (var i = 0; i < numberOfBatches + 1; i++) {
|
||||
|
||||
gppInstance.convert( inputFiles, i );
|
||||
|
||||
process.stdout.moveCursor( Math.floor( (i * numberOfDots) / numberOfBatches ) , -1 );
|
||||
|
||||
console.log("·");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await Promise.all( gppInstance.execPromises );
|
||||
|
||||
console.log("Done.");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user