Browse Source

elxr pullall and init-gitea

production
Pradeep Bhaskaran 4 years ago
parent
commit
29489c9f0c
1 changed files with 144 additions and 56 deletions
  1. 144
    56
      index.js

+ 144
- 56
index.js View File

@@ -189,6 +189,36 @@ var __runcmd = function(label){
var op = {
'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
, 'undefined' : ()=>{ return op.h(); }
, 'reset' : ()=>{
// Reset NPM packages semver so major versions can be updated.
const fs = require('fs')
const wipeDependencies = (package) => {
const file = fs.readFileSync(package + '/package.json')
const content = JSON.parse(file)
for (var devDep in content.devDependencies) {
if (content.devDependencies[devDep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
content.devDependencies[devDep] = '*';
}
}
for (var dep in content.dependencies) {
if (content.dependencies[dep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
content.dependencies[dep] = '*';
}
}
fs.writeFileSync(package + '/package.json', JSON.stringify(content))
}

var repos = ['client'];
// repos = gitRepos;
repos.forEach(wipeDependencies)
// if (require.main === module) {
// } else {
// module.exports = wipeDependencies
// }

}
, 'upgrade' : ()=>{
console.log('upgrade.......')
var tasks = [
@@ -334,7 +364,11 @@ var __runcmd = function(label){
// git push origin master

var repo = processedArgs._[1];
var defaultRepoServer = '//172.16.0.27/repos'
var defaultRepoServer = reposervers[0]
var reposervers = [
'http://git.bbh'
, '//172.16.0.27/repos'
]

var sequentialTaskShellCommands = [];
if(!existsSync(`Z:/${repo}.git`)){
@@ -354,10 +388,13 @@ var __runcmd = function(label){
, inherit : true, shell: true
, env: process.env
}]
// PB : TODO -- Do this conditionally only...
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd : `${repo}`}, (err)=>{
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.
, ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd : `${repo}`}]
// PB : TODO -- If threre is a gitbubclone origin
// Set the master to pull from the local repo.
]
if(!existsSync(`Z:`)){
sequentialTaskShellCommands.splice(0,0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm,'\\')], {
@@ -384,6 +421,54 @@ var __runcmd = function(label){
any(tasks);

}
, 'is-git-repo' : (dir)=>{
return nodeShellExec('git', ['-C', dir.name, 'rev-parse'], { stdio : 'ignore'})
}
, 'init-gitea' : (user) => {
user = user || processedArgs._[1]
if(!user) throw 'User name required'
var serial_perform_init_gitea = (repo)=>{
var options = { cwd : repo }
// console.log(repo)
return [
['git', ['remote', 'add', 'chess', 'http://git.bbh/chess/elxr.git'], { cwd : repo }]
, ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd : repo }]
, ['git', ['remote', 'set-url', 'origin', `http://git.bbh/${user}/${repo}.git`], { cwd : repo }]
]}
var x = (args)=>{
return ()=>{
// console.log(args)
return nodeShellExec.apply(null, args)
}
// return Promise.resolve(true)
}
var perform_init_gitea = (dir)=>{
op['is-git-repo'](dir).then((code)=>{
// console.log(code)
if(code) {
nodeShellExec('git',['remote', 'get-url', 'chess'], { cwd : dir.name, stdio : 'ignore' }).then(()=>{
console.log('skipped : ' + dir.name + ', reason : Already has remote chess ')
})
.catch((e)=>{
any( serial_perform_init_gitea(dir.name).map(x) )
})
}
// else console.log('Skipped : Not a Git Repo : ' + dir.name)
}).catch((e)=>{
// console.log('Failed : ' + dir.name)
})
}

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)
}
, 'pull' : (label) => {
// Usage :
// elxr pull -- Defaults to run config
@@ -400,20 +485,29 @@ var __runcmd = function(label){
// env: env
// })

var useGitPull = processedArgs.useGitPull || false;
var getPullCmd = (repo)=>{

var pullCmd = ["C:\\Program Files\\Git\\bin\\sh.exe", ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'], { cwd : repo }]
// var pullCmd = ['pullall', [], { cwd : repo }]
if(useGitPull) pullCmd = ['git', ['pull'], {
inherit : true, shell: true,
cwd : repo
// , env: process.env
, runas : processedArgs.runas
, title : `git pull ${repo}`
}]
return pullCmd
}

var performPull = (repo) => {
if(existsSync(repo)) {
console.log('pulling ' + repo)
return nodeShellExec('git', ['pull'], {
inherit : true, shell: true,
cwd : repo
// , env: process.env
, runas : processedArgs.runas
, title : `git pull ${repo}`
}).catch((e)=>{ console.error(e) })
return nodeShellExec.apply(null, getPullCmd(repo)).catch((e)=>{ console.error(e) })
}
else {
console.log('cloning ' + repo)
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', '//172.16.0.27/repos/' + repo + '.git'],
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + '/' + repo + '.git'],
{
inherit : true, shell: true,
env: process.env
@@ -426,10 +520,8 @@ var __runcmd = function(label){
env: process.env
, cwd : repo
, runas : processedArgs.runas
, title : `git core.symlinks --replace-all true for ${'//172.16.0.27/repos/' + repo + '.git'}`
, title : `git core.symlinks --replace-all true for ${defaultRepoServer + '/' + repo + '.git'}`
})


})
}
}
@@ -710,55 +802,51 @@ var __runcmd = function(label){
.then( () => {
// Move test config from dev.
// if(process.env.NODE_ENV === 'test'){
// var devcfgreponame = runconfig.use + '-config' + '-development';
// var testcfgreponame = runconfig.use + '-config' + '-test';
// var devcfgreponame = runconfig.use + '-config' + '-development';
// var testcfgreponame = runconfig.use + '-config' + '-test';
// var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
// var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development)
// var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
// var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development)
// var promises = [];
// promises.push(
// nodeShellExec('git', ['checkout', 'test'], {
// inherit : true, shell: true,
// cwd : testcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout ${testcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// )
// promises.push(
// nodeShellExec('git', ['checkout', 'master'], {
// inherit : true, shell: true,
// cwd : devcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout ${devcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// )
// return Promise.all(promises).then(()=> {
// globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => {
// console.log('File found : ' + devcfgdir + filename)
// fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename);
// return nodeShellExec('git', ['checkout', 'test'], {
// inherit : true, shell: true,
// cwd : devcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout ${devcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// })
// })
// return any([
// ()=>{
// return nodeShellExec('git', ['checkout', 'test'], {
// inherit : true, shell: true,
// cwd : testcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout test for ${testcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// }
// , ()=> {
// return nodeShellExec('git', ['checkout', 'master'], {
// inherit : true, shell: true,
// cwd : devcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout master for ${devcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// }
// , ()=> {
// globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => {
// console.log('File found : ' + devcfgdir + filename)
// fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename);
// })
// return nodeShellExec('git', ['checkout', 'test'], {
// inherit : true, shell: true,
// cwd : devcfgdir
// // , env: process.env
// , runas : processedArgs.runas
// , title : `git checkout test for ${devcfgreponame}`
// }).catch((e)=>{ console.error(e) })
// }
// ])
// }
// else{
// else {
return Promise.resolve(true)
// }
}).then(()=>{
})
.then(()=>{
fs.writeFileSync('run.done', 'success')
}).catch(()=>{
fs.writeFileSync('run.done', 'error')

Loading…
Cancel
Save