소스 검색

elxr pullall and init-gitea

production
Pradeep Bhaskaran 4 년 전
부모
커밋
29489c9f0c
1개의 변경된 파일144개의 추가작업 그리고 56개의 파일을 삭제
  1. 144
    56
      index.js

+ 144
- 56
index.js 파일 보기

var op = { var op = {
'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' } 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
, 'undefined' : ()=>{ return op.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' : ()=>{ , 'upgrade' : ()=>{
console.log('upgrade.......') console.log('upgrade.......')
var tasks = [ var tasks = [
// git push origin master // git push origin master


var repo = processedArgs._[1]; 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 = []; var sequentialTaskShellCommands = [];
if(!existsSync(`Z:/${repo}.git`)){ if(!existsSync(`Z:/${repo}.git`)){
, inherit : true, shell: true , inherit : true, shell: true
, env: process.env , env: process.env
}] }]
// PB : TODO -- Do this conditionally only...
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd : `${repo}`}, (err)=>{ , ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd : `${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 : `${repo}`}]
// PB : TODO -- If threre is a gitbubclone origin
// Set the master to pull from the local repo.
] ]
if(!existsSync(`Z:`)){ if(!existsSync(`Z:`)){
sequentialTaskShellCommands.splice(0,0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm,'\\')], { sequentialTaskShellCommands.splice(0,0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm,'\\')], {
any(tasks); 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) => { , 'pull' : (label) => {
// Usage : // Usage :
// elxr pull -- Defaults to run config // elxr pull -- Defaults to run config
// env: env // 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) => { var performPull = (repo) => {
if(existsSync(repo)) { if(existsSync(repo)) {
console.log('pulling ' + 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 { else {
console.log('cloning ' + repo) 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, inherit : true, shell: true,
env: process.env env: process.env
env: process.env env: process.env
, cwd : repo , cwd : repo
, runas : processedArgs.runas , 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'}`
}) })


}) })
} }
} }
.then( () => { .then( () => {
// Move test config from dev. // Move test config from dev.
// if(process.env.NODE_ENV === 'test'){ // 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) return Promise.resolve(true)
// } // }
}).then(()=>{
})
.then(()=>{
fs.writeFileSync('run.done', 'success') fs.writeFileSync('run.done', 'success')
}).catch(()=>{ }).catch(()=>{
fs.writeFileSync('run.done', 'error') fs.writeFileSync('run.done', 'error')

Loading…
취소
저장