const { spawn } = require("node:child_process"); const fs = require( "node:fs/promises" ); const path = require( "path" ); const { loadJSON } = require( "./library.js" ); let from = "rokojori-action-library"; let to = "godot/modules/rokojori_action_library" async function main() { console.log( "Copying C++ source" ); await deleteOldDirectory(); await copyToModules(); // await runBuild(); console.log( "Copying C++ source" ); } async function deleteOldDirectory() { let stats = await fs.stat( to ); if ( stats ) { console.log( `deleting previous directory: "${to}"` ); await fs.rm( to, { recursive: true } ); } return Promise.resolve(); } async function copyToModules() { console.log( "copying:", `"${from}" >> "${to}"` ); await fs.cp( from, to, { recursive : true } ); return Promise.resolve(); } async function runBuild() { let { exec } = require( "child_process"); let settingsFileName = "build-settings.json"; let settings = await loadJSON( "build-settings.json" ); if ( ! settings ) { console.error( `Build Settings missing... Add a json-file '${settingsFileName}' with a member 'sconsPath'` ) return Promise.reject(); } let command = `${settings.sconsPath}/scons platform=windows module_mono_enabled=yes`; let executionDirectory = path.join( __dirname, "godot" ); let options = { cwd: executionDirectory }; console.log( "Starting build:", command, "Options:", JSON.stringify( options ) ); let process = exec( command, options ); process.stdout.on( "data", ( data ) => { console.log( `${data}` ); } ); process.stderr.on( "data", ( data ) => { console.error( `${data}` ); } ); process.on( "close", ( code ) => { console.log( `child process exited with code ${code} `); } ); } main();