|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ENV = Object.assign({}, process.env); // Shallow clone it. |
|
|
var ENV = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
|
|
|
|
|
|
|
|
const { readdir } = require("fs").promises |
|
|
|
|
|
|
|
|
|
|
|
// Directory shallow walk and do perform on each dir. |
|
|
|
|
|
const dirs = async (perform, path) => { |
|
|
|
|
|
for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) { |
|
|
|
|
|
if (dir.isDirectory()) perform(dir) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var getShellTask = (command, args, options) => { |
|
|
var getShellTask = (command, args, options) => { |
|
|
return () => { |
|
|
return () => { |
|
|
var p = nodeShellExec.apply(null, [command, args, Object.assign({ |
|
|
var p = nodeShellExec.apply(null, [command, args, Object.assign({ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var pullCmd = [gitInstallDir |
|
|
var pullCmd = [gitInstallDir |
|
|
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
, { cwd: repo, title: 'pull all origins for ' + repo }] |
|
|
|
|
|
|
|
|
, { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }] |
|
|
// var pullCmd = ['pullall', [], { cwd : repo }] |
|
|
// var pullCmd = ['pullall', [], { cwd : repo }] |
|
|
if (useGitPull) pullCmd = ['git', ['pull'], { |
|
|
if (useGitPull) pullCmd = ['git', ['pull'], { |
|
|
inherit: true, shell: true, |
|
|
inherit: true, shell: true, |
|
|
|
|
|
|
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'], |
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'], |
|
|
{ |
|
|
{ |
|
|
inherit: true, shell: true, |
|
|
inherit: true, shell: true, |
|
|
env: process.env |
|
|
|
|
|
|
|
|
env: process.env |
|
|
|
|
|
, cwd : instanceroot |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
throw e; |
|
|
throw e; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
inherit: true, shell: true, |
|
|
inherit: true, shell: true, |
|
|
env: process.env |
|
|
env: process.env |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
, title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}` |
|
|
, title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}` |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// elxr cli operations |
|
|
// elxr cli operations |
|
|
var op = { |
|
|
var op = { |
|
|
'h': () => { console.log(elxr.info()); return '-h' } |
|
|
|
|
|
|
|
|
'h': () => { console.log(elxr.help()); return '-h' } |
|
|
|
|
|
, 'clean' : () => { |
|
|
|
|
|
// delete all node_module folders and links. |
|
|
|
|
|
var tasklist = []; |
|
|
|
|
|
dirs( (repodir)=> tasklist.push(getShellTask('rm',['-rf', 'node_modules'], { cwd : instanceroot + '/' + repodir.name })()), instanceroot ) |
|
|
|
|
|
return Promise.all(tasklist) |
|
|
|
|
|
} |
|
|
, 'undefined': () => { return op.h(); } |
|
|
, 'undefined': () => { return op.h(); } |
|
|
, 'reset': () => { |
|
|
, 'reset': () => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, env: process.env |
|
|
, env: process.env |
|
|
}] |
|
|
}] |
|
|
// PB : TODO -- Do this conditionally only... |
|
|
// PB : TODO -- Do this conditionally only... |
|
|
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${repo}` }, (err) => { |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${instanceroot + '/' + repo}` }, (err) => { |
|
|
console.log('Ignoring origin rename error : ' + err); return true; //return true to continue. |
|
|
console.log('Ignoring origin rename error : ' + err); return true; //return true to continue. |
|
|
}] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure. |
|
|
}] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure. |
|
|
, ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd: `${repo}` }] |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd: `${instanceroot + '/' + repo}` }] |
|
|
// PB : TODO -- If threre is a gitbubclone origin |
|
|
// PB : TODO -- If threre is a gitbubclone origin |
|
|
// Set the master to pull from the local repo. |
|
|
// Set the master to pull from the local repo. |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${repo}` }]) |
|
|
|
|
|
|
|
|
sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${instanceroot + '/' + repo}` }]) |
|
|
// console.dir(sequentialTaskShellCommands); |
|
|
// console.dir(sequentialTaskShellCommands); |
|
|
|
|
|
|
|
|
var tasks = []; |
|
|
var tasks = []; |
|
|
|
|
|
|
|
|
remotename = remotename || processedArgs._[1] |
|
|
remotename = remotename || processedArgs._[1] |
|
|
url = url || processedArgs._[2] |
|
|
url = url || processedArgs._[2] |
|
|
var serial_perform_git_seturl = (repo) => { |
|
|
var serial_perform_git_seturl = (repo) => { |
|
|
var options = { cwd: repo } |
|
|
|
|
|
|
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
if (pushable) { |
|
|
if (pushable) { |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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_seturl) |
|
|
dirs(perform_git_seturl) |
|
|
} |
|
|
} |
|
|
, 'add': (remotename, url, branch) => { |
|
|
, 'add': (remotename, url, branch) => { |
|
|
|
|
|
|
|
|
url = url || processedArgs._[2] |
|
|
url = url || processedArgs._[2] |
|
|
branch = branch || processedArgs._[3] |
|
|
branch = branch || processedArgs._[3] |
|
|
var serial_perform_git_add = (repo) => { |
|
|
var serial_perform_git_add = (repo) => { |
|
|
var options = { cwd: repo } |
|
|
|
|
|
|
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
if (pushable) { |
|
|
if (pushable) { |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: repo }] |
|
|
|
|
|
, ['git', ['pull', remotename, branch], { cwd: repo }] |
|
|
|
|
|
, ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: repo }] |
|
|
|
|
|
, ['git', ['remote', `set-url`, '--push', remotename, 'no-pushing'], { cwd: repo }] |
|
|
|
|
|
, ['git', ['pull', remotename, branch], { cwd: repo }] |
|
|
|
|
|
, ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['remote', `set-url`, '--push', remotename, 'no-pushing'], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, 'remove': (remotename) => { |
|
|
, 'remove': (remotename) => { |
|
|
remotename = remotename || processedArgs._[1] |
|
|
remotename = remotename || processedArgs._[1] |
|
|
var serial_perform_git_remove = (repo) => { |
|
|
var serial_perform_git_remove = (repo) => { |
|
|
var options = { cwd: repo } |
|
|
|
|
|
|
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'remove', remotename], { cwd: repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
var x = (args) => { |
|
|
|
|
|
|
|
|
user = user || processedArgs._[1] |
|
|
user = user || processedArgs._[1] |
|
|
if (!user) throw 'User name required' |
|
|
if (!user) throw 'User name required' |
|
|
var serial_perform_init_gitea = (repo) => { |
|
|
var serial_perform_init_gitea = (repo) => { |
|
|
var options = { cwd: repo } |
|
|
|
|
|
|
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: repo }] |
|
|
|
|
|
, ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: repo }] |
|
|
|
|
|
, ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
, ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
var x = (args) => { |
|
|
|
|
|
|
|
|
tasks.push(() => { |
|
|
tasks.push(() => { |
|
|
return nodeShellExec('npm', ['i --force'], { |
|
|
return nodeShellExec('npm', ['i --force'], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, title: `npm i for ${repo}` |
|
|
, title: `npm i for ${repo}` |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
|
|
|
|
|
|
console.log(`--------------------npm run build for ${repo}--------------------`) |
|
|
console.log(`--------------------npm run build for ${repo}--------------------`) |
|
|
return nodeShellExec('npm', ['run build'], { |
|
|
return nodeShellExec('npm', ['run build'], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, title: `npm run build for ${repo}` |
|
|
, title: `npm run build for ${repo}` |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
|
|
|
|
|
|
console.log(`--------------------rm package-lock.json for ${repo}--------------------`) |
|
|
console.log(`--------------------rm package-lock.json for ${repo}--------------------`) |
|
|
return nodeShellExec('rm', ['package-lock.json'], { |
|
|
return nodeShellExec('rm', ['package-lock.json'], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, title: `rm 'package-lock.json' for ${repo}` |
|
|
, title: `rm 'package-lock.json' for ${repo}` |
|
|
}).catch((e) => { console.error(e) }) |
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
|
|
|
|
|
console.log(`--------------------npm i for ${repo}--------------------`) |
|
|
console.log(`--------------------npm i for ${repo}--------------------`) |
|
|
var p = nodeShellExec('npm', ['i --force'], { |
|
|
var p = nodeShellExec('npm', ['i --force'], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, title: `npm i for ${repo}` |
|
|
, title: `npm i for ${repo}` |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
|
|
|
|
|
|
repotasks.push(() => { |
|
|
repotasks.push(() => { |
|
|
var p = nodeShellExec('bower', ['install'], { |
|
|
var p = nodeShellExec('bower', ['install'], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd: repo |
|
|
|
|
|
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, title: `bower i for ${repo}` |
|
|
, title: `bower i for ${repo}` |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
}).then(Tasq.then).catch(Tasq.catch) |
|
|
|
|
|
|
|
|
shell: true, |
|
|
shell: true, |
|
|
detached: true, |
|
|
detached: true, |
|
|
stdio: 'ignore', |
|
|
stdio: 'ignore', |
|
|
cwd: 'elixir-server' |
|
|
|
|
|
|
|
|
cwd: instanceroot + '/' + 'elixir-server' |
|
|
, env: env |
|
|
, env: env |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shell: true, |
|
|
shell: true, |
|
|
detached: true, |
|
|
detached: true, |
|
|
stdio: 'ignore', |
|
|
stdio: 'ignore', |
|
|
cwd: 'client' |
|
|
|
|
|
|
|
|
cwd: instanceroot + '/' + 'client' |
|
|
, env: env |
|
|
, env: env |
|
|
}) |
|
|
}) |
|
|
// .catch(e=>console.error(e)) |
|
|
// .catch(e=>console.error(e)) |
|
|
|
|
|
|
|
|
return nodeShellExec('git', ['checkout', branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
return nodeShellExec('git', ['checkout', branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
// inherit : true, shell: true, |
|
|
// inherit : true, shell: true, |
|
|
cwd: repo |
|
|
|
|
|
|
|
|
cwd: repoinstanceroot + '/' + repo |
|
|
// , stdio : ignore // Use when we want to silcence output completely. |
|
|
// , stdio : ignore // Use when we want to silcence output completely. |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
, title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}` |
|
|
, title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}` |
|
|
|
|
|
|
|
|
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
return nodeShellExec('git', ['pull', '--all'], { |
|
|
return nodeShellExec('git', ['pull', '--all'], { |
|
|
// inherit : true, shell: true, |
|
|
// inherit : true, shell: true, |
|
|
cwd: repo |
|
|
|
|
|
|
|
|
cwd: instanceroot + '/' + repo |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}` |
|
|
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}` |
|
|
}).catch((e) => { console.error(e); return { error: true, message: repo } }) |
|
|
}).catch((e) => { console.error(e); return { error: true, message: repo } }) |
|
|
|
|
|
|
|
|
if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
return nodeShellExec('git', ['merge', mergeSource], { |
|
|
return nodeShellExec('git', ['merge', mergeSource], { |
|
|
inherit: true, shell: true, |
|
|
inherit: true, shell: true, |
|
|
cwd: repo |
|
|
|
|
|
|
|
|
cwd: instanceroot + '/' + repo |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
}).catch((e) => { console.error(e) }) |
|
|
}).catch((e) => { console.error(e) }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// It could be a standalone elxr build which may or maynot be in the proper location. |
|
|
// It could be a standalone elxr build which may or maynot be in the proper location. |
|
|
if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) { |
|
|
if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) { |
|
|
// Unbuilt therefore we are in the elxr directory. |
|
|
// Unbuilt therefore we are in the elxr directory. |
|
|
root = path.normalize(launchpath + '../'); |
|
|
|
|
|
|
|
|
root = path.normalize(launchpath + '/..'); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// Built version. |
|
|
// Built version. |
|
|
// check if we have a elxr subfolder. |
|
|
// check if we have a elxr subfolder. |
|
|
if (fs.existsSync(launchpath + '/..' + path.normalize('/elxr'))) { |
|
|
if (fs.existsSync(launchpath + '/..' + path.normalize('/elxr'))) { |
|
|
// Probably in the right place. |
|
|
|
|
|
|
|
|
// Probably in the right place. |
|
|
root = path.normalize(launchpath + '/..'); |
|
|
root = path.normalize(launchpath + '/..'); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
catch (e) { |
|
|
catch (e) { |
|
|
console.error(e) |
|
|
console.error(e) |
|
|
console.error('No local instances found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('We will create a new one with the instance and environment chosen...') |
|
|
|
|
|
|
|
|
console.error('No local instances config found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('A config will be createed with the instance and environment chosen...') |
|
|
} |
|
|
} |
|
|
finally { |
|
|
finally { |
|
|
|
|
|
|