UNPKG

odaseva-cli

Version:

Odaseva CLI

71 lines (55 loc) 2.1 kB
#!/usr/bin/env node /** Need to rename the platform specific executable to a generic odaseva executable. On windows, should odaseva.exe. Need to remove the 'odaseva' placeholder file. ON Linux/MacOS, need to set the permission. */ const fs = require('fs'); const path = require('path'); const PLATFORM_EXE_BASE_NAME = 'oda_cli'; const TARGET_EXE_BASE_NAME = 'odaseva'; console.log("Pre-Installing odaseva-cli"); var platform = process.platform; var arch = process.arch; console.log("platform:" + platform + " - arch:" + arch); var platformExeName = PLATFORM_EXE_BASE_NAME + "_" + platform + '_' + arch; var targetExeName = TARGET_EXE_BASE_NAME; if (platform == 'win32') { platformExeName += '.exe'; targetExeName += '.exe'; } var exePath = path.join( __dirname, '..', 'bin'); var fullPlaceholderPath = path.join(exePath, TARGET_EXE_BASE_NAME); var fullPlatformExePath = path.join(exePath, platformExeName); var fullTargetExePath = path.join(exePath, targetExeName); // Check source// should check file is executable... if (!fs.existsSync(fullPlatformExePath)) { var err = fullPlatformExePath + ' is not a valid file. ' + platformExeName + ' cannot be found.'; console.log(err); return new Error(err); } // Remove placeholder if (fs.existsSync(fullPlaceholderPath)) { console.log('Removing placeholder file '+ fullPlaceholderPath); fs.unlink(fullPlaceholderPath, function(err) { if(err) { console.log(err); return new Error(err); } console.log('File deleted successfully'); }); } // Copy console.log("Copying " + fullPlatformExePath + " to " + fullTargetExePath); fs.copyFileSync(fullPlatformExePath, fullTargetExePath); // should check file is executable... if (!fs.existsSync(fullTargetExePath)) { var err = "Copy failed."; console.log(err); return new Error(err); } else if (platform != 'win32') { console.log('Setting exec permissions on '+ fullTargetExePath); fs.chmodSync(fullTargetExePath, '755'); } console.log("Done pre-installing odaseva-cli");