| @@ -11,6 +11,7 @@ var chalk = require('chalk') | |||
| const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; | |||
| const runtimestamp = (new Date()).getTime(); | |||
| function getVersion() { return BUILD_VERSION; } | |||
| console.log(getVersion()) | |||
| @@ -402,7 +403,7 @@ var op = { | |||
| console.log('result : ' + JSON.stringify(r)) | |||
| Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }) | |||
| // PB : TODO -- Convert all the cli args back to string. | |||
| var args = [__dirname + '/.run/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | |||
| var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | |||
| args.push('--nodepath=' + r[r.length - 1]) | |||
| if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) | |||
| if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. | |||
| @@ -588,12 +589,6 @@ var op = { | |||
| const { readdir } = require("fs").promises | |||
| const dirs = async (perform, path) => { | |||
| for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) { | |||
| if (dir.isDirectory()) perform(dir) | |||
| } | |||
| } | |||
| dirs(perform_git_add) | |||
| } | |||
| , 'remove': (remotename) => { | |||
| @@ -631,12 +626,6 @@ var op = { | |||
| const { readdir } = require("fs").promises | |||
| const dirs = async (perform, path) => { | |||
| for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) { | |||
| if (dir.isDirectory()) perform(dir) | |||
| } | |||
| } | |||
| dirs(perform_git_remove) | |||
| } | |||
| , 'init-gitea': (user) => { | |||
| @@ -677,12 +666,6 @@ var op = { | |||
| const { readdir } = require("fs").promises | |||
| const dirs = async (perform, path) => { | |||
| for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) { | |||
| if (dir.isDirectory()) perform(dir) | |||
| } | |||
| } | |||
| dirs(perform_init_gitea) | |||
| } | |||
| , 'syncmaster': (label) => { | |||
| @@ -1652,7 +1635,7 @@ var prerequisites = [ | |||
| var steps = [ | |||
| () => { | |||
| if (!existsSync(downloadsdir + '/' + this.installer)) { | |||
| return nodeShellExec('.run/download.bat', [this.url, downloadsdir + '/' + this.installer]) | |||
| return nodeShellExec(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`, [this.url, downloadsdir + '/' + this.installer]) | |||
| } | |||
| else return Promise.resolve(true) | |||
| } | |||
| @@ -1762,10 +1745,8 @@ function ensureDirectoryExistence(filePath) { | |||
| var mainTasks = []; | |||
| function verifyAndInstallPrerequisites() { | |||
| fs.writeFileSync(ensureDirectoryExistence(path.normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`) | |||
| // PB : TODO -- Keep only the last n runs... | |||
| ensureDirectoryExistence('.run/download.bat') | |||
| fs.writeFileSync(ensureDirectoryExistence(path.normalize(`${selectedinstance.root}/${downloadsdir}/readme.txt`)), `${getVersion()} Your local downloads for this instance`) | |||
| // PB : TODO include and build from files... using rollup.. | |||
| var downloadbatch = | |||
| `::************************************************************************** | |||
| @@ -1776,7 +1757,7 @@ function verifyAndInstallPrerequisites() { | |||
| (New-Object System.Net.WebClient).DownloadFile('%1','%2') | |||
| exit /b | |||
| ::**************************************************************************` | |||
| fs.writeFileSync('.run/download.bat', downloadbatch) | |||
| fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`, downloadbatch) | |||
| var windowselevate = | |||
| @@ -1855,10 +1836,8 @@ function verifyAndInstallPrerequisites() { | |||
| </html> | |||
| ` | |||
| fs.writeFileSync('.run/windowselevate.hta', windowselevate) | |||
| fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`, windowselevate) | |||
| var downloadtasks = []; | |||
| var installtasks = []; | |||
| prerequisites.forEach(preq => { | |||
| @@ -1924,6 +1903,11 @@ acquireElevationState().then(() => { | |||
| }) | |||
| } | |||
| const retaincount = 2 | |||
| var min = runtimestamp; | |||
| var collect = [] | |||
| return detectInstance().then((detectedInstance)=>{ | |||
| processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null; | |||
| @@ -1977,7 +1961,39 @@ acquireElevationState().then(() => { | |||
| } | |||
| return todo | |||
| }).then(()=>{ | |||
| }) | |||
| .then(()=>{ | |||
| if(!__isElevated) { | |||
| ensureDirectoryExistence(`${selectedinstance.root}/.elxr/readme.txt`) | |||
| // collect garbage | |||
| return dirs( (dir)=>{ | |||
| var matches = /run-(.*)/gm.exec(dir.name) | |||
| if(matches) { | |||
| if(+(matches[1]) < min) { | |||
| min = matches[1] | |||
| collect.splice( 0, 0, matches[1] ) | |||
| } | |||
| else collect.push(matches[1]) | |||
| } | |||
| }, `${selectedinstance.root}/.elxr` ).then(()=>{ | |||
| // delete garbage | |||
| if(collect.length > retaincount) { | |||
| var asyncs = []; | |||
| while((collect.length - asyncs.length) > retaincount) asyncs.push(getShellTask('rm',['-rf', `run-${collect[0]}`], { cwd : `${selectedinstance.root}/.elxr` })()); | |||
| return Promise.all(asyncs) | |||
| } | |||
| else return true | |||
| }) | |||
| } | |||
| else return true; | |||
| }) | |||
| .then(()=>{ | |||
| // PB : TODO -- Keep only the last n runs... | |||
| ensureDirectoryExistence(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`) | |||
| if (!skipprerequisites && !__isElevated) mainTasks.push(verifyAndInstallPrerequisites); | |||
| mainTasks.push(maintask) | |||
| return any(mainTasks); | |||