Browse Source

runtime stamped run folders under .elxr

production
chess 3 years ago
parent
commit
c7d699ea41
1 changed files with 45 additions and 29 deletions
  1. 45
    29
      index.js

+ 45
- 29
index.js View File





const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
const runtimestamp = (new Date()).getTime();
function getVersion() { return BUILD_VERSION; } function getVersion() { return BUILD_VERSION; }
console.log(getVersion()) console.log(getVersion())


console.log('result : ' + JSON.stringify(r)) console.log('result : ' + JSON.stringify(r))
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }) Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; })
// PB : TODO -- Convert all the cli args back to string. // 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]) args.push('--nodepath=' + r[r.length - 1])
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV)
if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..


const { readdir } = require("fs").promises 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) dirs(perform_git_add)
} }
, 'remove': (remotename) => { , 'remove': (remotename) => {


const { readdir } = require("fs").promises 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) dirs(perform_git_remove)
} }
, 'init-gitea': (user) => { , 'init-gitea': (user) => {


const { readdir } = require("fs").promises 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) dirs(perform_init_gitea)
} }
, 'syncmaster': (label) => { , 'syncmaster': (label) => {
var steps = [ var steps = [
() => { () => {
if (!existsSync(downloadsdir + '/' + this.installer)) { 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) else return Promise.resolve(true)
} }


var mainTasks = []; var mainTasks = [];
function verifyAndInstallPrerequisites() { 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.. // PB : TODO include and build from files... using rollup..
var downloadbatch = var downloadbatch =
`::************************************************************************** `::**************************************************************************
(New-Object System.Net.WebClient).DownloadFile('%1','%2') (New-Object System.Net.WebClient).DownloadFile('%1','%2')
exit /b exit /b
::**************************************************************************` ::**************************************************************************`
fs.writeFileSync('.run/download.bat', downloadbatch)
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`, downloadbatch)


var windowselevate = var windowselevate =
</html> </html>
` `
fs.writeFileSync('.run/windowselevate.hta', windowselevate)
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`, windowselevate)


var downloadtasks = []; var downloadtasks = [];
var installtasks = []; var installtasks = [];
prerequisites.forEach(preq => { prerequisites.forEach(preq => {
}) })
} }


const retaincount = 2
var min = runtimestamp;
var collect = []

return detectInstance().then((detectedInstance)=>{ return detectInstance().then((detectedInstance)=>{


processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null; processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
} }


return todo 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); if (!skipprerequisites && !__isElevated) mainTasks.push(verifyAndInstallPrerequisites);
mainTasks.push(maintask) mainTasks.push(maintask)
return any(mainTasks); return any(mainTasks);

Loading…
Cancel
Save