Переглянути джерело

refactor with standalone elxr build

production
pb 3 роки тому
джерело
коміт
468487fdb9
5 змінених файлів з 17688 додано та 48 видалено
  1. 34
    1
      bin/elxr
  2. 5
    0
      cliverse.js
  3. 17590
    0
      elxr.js
  4. 53
    45
      index.js
  5. 6
    2
      package.json

+ 34
- 1
bin/elxr Переглянути файл

@@ -1,3 +1,36 @@
#!/usr/bin/env node

require('../index.js')
var ENV = Object.assign({}, process.env); // Shallow clone it.

const spawn = require('child_process').spawn;
const child = spawn(
(process.platform === 'win32' ? 'npm.cmd' : 'npm')
, ['run', 'index'].concat(process.argv.slice(2)), { cwd: __dirname });

// const child = spawn(
// 'C:\\Program Files\\Git\\bin\\sh.exe'
// , ['notepad', 'index'], { cwd: __dirname });

// ENV.FORCE_COLOR = true;
// const child = spawn(
// 'node'
// , ['../index.js', 'pull'], { env : ENV, cwd: __dirname });

process.stdin.pipe(child.stdin)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)



// started.stdout.on('data', function (data) {
// console.log('stdout:', data.toString());
// });

// started.stderr.on('data', function (data) {
// console.log('stderr:', data.toString());
// });

// started.on('exit', function (code) {
// console.log('child process exited with code:', code.toString());
// });

+ 5
- 0
cliverse.js Переглянути файл

@@ -7,6 +7,11 @@ function nodeShellExec() {
var opts = args[2] = args[2] || {}
opts.title ? null : opts.title = `${args[0]} ${args[1] }`
const child = spawn(...arguments);
// // const spawn = require('child_process').spawn;
// const s = spawn(
// 'C:\\Program Files\\Git\\bin\\sh.exe'
// , ['notepad', 'index'], { cwd: __dirname });

var p = new Promise(function(resolve, reject){
if(!opts.detached) {

+ 17590
- 0
elxr.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 53
- 45
index.js Переглянути файл

@@ -36,6 +36,15 @@ var globSync = require('glob').sync;

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) => {
return () => {
var p = nodeShellExec.apply(null, [command, args, Object.assign({
@@ -71,7 +80,7 @@ var getPullCmd = (repo) => {

var pullCmd = [gitInstallDir
, ['-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 }]
if (useGitPull) pullCmd = ['git', ['pull'], {
inherit: true, shell: true,
@@ -107,7 +116,8 @@ var performPull = (repo) => {
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'],
{
inherit: true, shell: true,
env: process.env
env: process.env
, cwd : instanceroot
, runas: processedArgs.runas
}).catch((e) => {
throw e;
@@ -117,7 +127,7 @@ var performPull = (repo) => {
{
inherit: true, shell: true,
env: process.env
, cwd: repo
, cwd: instanceroot + '/' + repo
, runas: processedArgs.runas
, title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
})
@@ -202,7 +212,13 @@ var configPromise = null

// elxr cli operations
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(); }
, 'reset': () => {

@@ -408,10 +424,10 @@ var op = {
, env: process.env
}]
// 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.
}] // 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
// Set the master to pull from the local repo.
]
@@ -425,7 +441,7 @@ var op = {
}
}

sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${repo}` }])
sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${instanceroot + '/' + repo}` }])
// console.dir(sequentialTaskShellCommands);

var tasks = [];
@@ -448,11 +464,11 @@ var op = {
remotename = remotename || processedArgs._[1]
url = url || processedArgs._[2]
var serial_perform_git_seturl = (repo) => {
var options = { cwd: repo }
var options = { cwd: instanceroot + '/' + repo }
// console.log(repo)
if (pushable) {
return [
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: repo }]
['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
]
}
else {
@@ -469,14 +485,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_seturl)
}
, 'add': (remotename, url, branch) => {
@@ -485,22 +493,22 @@ var op = {
url = url || processedArgs._[2]
branch = branch || processedArgs._[3]
var serial_perform_git_add = (repo) => {
var options = { cwd: repo }
var options = { cwd: instanceroot + '/' + repo }
// console.log(repo)
if (pushable) {
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 {

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 }]
]
}

@@ -542,10 +550,10 @@ var op = {
, 'remove': (remotename) => {
remotename = remotename || processedArgs._[1]
var serial_perform_git_remove = (repo) => {
var options = { cwd: repo }
var options = { cwd: instanceroot + '/' + repo }
// console.log(repo)
return [
['git', ['remote', 'remove', remotename], { cwd: repo }]
['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }]
]
}
var x = (args) => {
@@ -586,12 +594,12 @@ var op = {
user = user || processedArgs._[1]
if (!user) throw 'User name required'
var serial_perform_init_gitea = (repo) => {
var options = { cwd: repo }
var options = { cwd: instanceroot + '/' + repo }
// console.log(repo)
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) => {
@@ -720,7 +728,7 @@ var op = {
tasks.push(() => {
return nodeShellExec('npm', ['i --force'], {
inherit: true, shell: true
, cwd: repo
, cwd: instanceroot + '/' + repo
, env: process.env
, title: `npm i for ${repo}`
}).catch((e) => {
@@ -729,7 +737,7 @@ var op = {
console.log(`--------------------npm run build for ${repo}--------------------`)
return nodeShellExec('npm', ['run build'], {
inherit: true, shell: true
, cwd: repo
, cwd: instanceroot + '/' + repo
, env: process.env
, title: `npm run build for ${repo}`
}).then(Tasq.then).catch(Tasq.catch)
@@ -750,7 +758,7 @@ var op = {
console.log(`--------------------rm package-lock.json for ${repo}--------------------`)
return nodeShellExec('rm', ['package-lock.json'], {
inherit: true, shell: true
, cwd: repo
, cwd: instanceroot + '/' + repo
, env: process.env
, title: `rm 'package-lock.json' for ${repo}`
}).catch((e) => { console.error(e) })
@@ -762,7 +770,7 @@ var op = {
console.log(`--------------------npm i for ${repo}--------------------`)
var p = nodeShellExec('npm', ['i --force'], {
inherit: true, shell: true
, cwd: repo
, cwd: instanceroot + '/' + repo
, env: process.env
, title: `npm i for ${repo}`
}).then(Tasq.then).catch(Tasq.catch)
@@ -776,7 +784,7 @@ var op = {
repotasks.push(() => {
var p = nodeShellExec('bower', ['install'], {
inherit: true, shell: true
, cwd: repo
, cwd: instanceroot + '/' + repo
, env: process.env
, title: `bower i for ${repo}`
}).then(Tasq.then).catch(Tasq.catch)
@@ -804,7 +812,7 @@ var op = {
shell: true,
detached: true,
stdio: 'ignore',
cwd: 'elixir-server'
cwd: instanceroot + '/' + 'elixir-server'
, env: env
})

@@ -839,7 +847,7 @@ var op = {
shell: true,
detached: true,
stdio: 'ignore',
cwd: 'client'
cwd: instanceroot + '/' + 'client'
, env: env
})
// .catch(e=>console.error(e))
@@ -930,7 +938,7 @@ var op = {
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], {
// inherit : true, shell: true,
cwd: repo
cwd: repoinstanceroot + '/' + repo
// , stdio : ignore // Use when we want to silcence output completely.
, runas: processedArgs.runas
, title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}`
@@ -942,7 +950,7 @@ var op = {
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
return nodeShellExec('git', ['pull', '--all'], {
// inherit : true, shell: true,
cwd: repo
cwd: instanceroot + '/' + repo
, runas: processedArgs.runas
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}`
}).catch((e) => { console.error(e); return { error: true, message: repo } })
@@ -962,7 +970,7 @@ var op = {
if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true })
return nodeShellExec('git', ['merge', mergeSource], {
inherit: true, shell: true,
cwd: repo
cwd: instanceroot + '/' + repo
, runas: processedArgs.runas
}).catch((e) => { console.error(e) })
}
@@ -1392,13 +1400,13 @@ var detectInstance = function () {
// 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) {
// Unbuilt therefore we are in the elxr directory.
root = path.normalize(launchpath + '../');
root = path.normalize(launchpath + '/..');
}
else {
// Built version.
// check if we have a elxr subfolder.
if (fs.existsSync(launchpath + '/..' + path.normalize('/elxr'))) {
// Probably in the right place.
// Probably in the right place.
root = path.normalize(launchpath + '/..');
}
else {
@@ -1577,8 +1585,8 @@ var maintask = () => {
}
catch (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 {

+ 6
- 2
package.json Переглянути файл

@@ -6,13 +6,17 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-commented": "rollup index.js --format cjs --file elxr.js",
"build": "rollup -c"
"build": "rollup -c",
"index": "SET FORCE_COLOR=true && node index"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bbhverse": "file:../bbhverse",
"bbhverse": "git+http://git.bbh/chess/bbhverse",
"global-this": "git+http://git.bbh/chess/global-this",
"moment": "^2.27.0",
"crossfilter2": "^1.5.4",
"chalk": "^4.1.0",
"glob": "^7.1.2",
"tree-kill": "^1.2.2"

Завантаження…
Відмінити
Зберегти