ソースを参照

Merge branch 'master' of http://git.bbh/chess/elxr

production
guest 3年前
コミット
ed6672eefe
4個のファイルの変更4432行の追加2503行の削除
  1. 1407
    342
      elxr.js
  2. 2817
    2088
      i.js
  3. 55
    0
      i.win.js
  4. 153
    73
      index.js

+ 1407
- 342
elxr.js
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 2817
- 2088
i.js
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 55
- 0
i.win.js ファイルの表示

@@ -876,7 +876,37 @@ function __main( selectedinstance ){
})
}

function unique(arr) {
var hash = {}, result = [];
for ( var i = 0, l = arr.length; i < l; ++i ) {
if ( !hash.hasOwnProperty(arr[i]) ) { //it works with objects! in FF, at least
hash[ arr[i] ] = true;
result.push(arr[i]);
}
}
return result;
}

// var ENV = Object.assign({}, process.env); // Shallow clone it.
var WshShell = WScript.CreateObject("WScript.Shell")
var ENV = WshShell.Environment("Process")
WScript.echo( ENV("Path") )
function sysAddPathVar(path){
// Object.assign({
// inherit: true, shell: true, env: ENV, title: `${command} ${args}`
// }, options)
// var newpath = ENV("Path").split(';');
// newpath = Array.from(new Set(newpath.push(path))).join(';')
var newpath = [];
newpath.push(path)
newpath = unique(newpath).join(';')
// path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } )
return any([nodeShellExec('setx', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
// , nodeShellExec('set', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
] );
}
var prerequisites = [
{
shellcmd: 'git',
@@ -1046,6 +1076,31 @@ function __main( selectedinstance ){
// return any([any(steps), any(prompts)])
}
}
, {
shellcmd: 'python2'
, url: 'https://www.python.org/ftp/python/2.7.18/python-2.7.18.amd64.msi'
, installer: 'python-2.7.18.amd64.msi'
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi')
, 'ACCEPT=YES', '/passive']]
, preinstallsteps : function() { return Promise.resolve(true) }
, install : function() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
console.log('Installing')
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
}).then(function(){
return self.postinstallsteps()
})
}
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
, exists : exists
}
,
{
shellcmd: 'elxr'

+ 153
- 73
index.js ファイルの表示

@@ -8,8 +8,36 @@ Tasq.addlistener(statuslog.statuslog)
var cli = require('./cliverse')
var nodeShellExec = cli.nodeShellExec;
var chalk = require('chalk')
const homedir = require('os').homedir();


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

function sysAddPathVar(path){
// Object.assign({
// inherit: true, shell: true, env: ENV, title: `${command} ${args}`
// }, options)
var newpath = path.split(';');
newpath = Array.from(new Set(newpath.push(path))).join(';')
// path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } )
return nodeShellExec('setx', ['/m', 'PATH', newpath ]);
}

// singleton one time lazy
var getCredentials = function(){

// First call
var creds = fs.readFileSync(path.normalize(`${homedir}/.elxrcredentials`), { encoding: 'utf8' });
var creds = creds.split('\n').map( c => c.trim() && new URL(c));
console.log(creds);

// Subsequent calls
getCredentials = ()=>{ return creds }
return getCredentials();
}

const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
const runtimestamp = (new Date()).getTime();
@@ -82,78 +110,13 @@ console.dir(processedArgs)

//

// elxr cli operations
var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
, remote : true, 'c' : true, 'h' : true
, httpget : true, getuser : true
, 'switch user' : true
, 'switch' : true
// , 'undefined' : true
}

var reconfirmcmds = { create : true }

var subcommandlabels = {
remote : (`remote ${processedArgs._[1] || ''}`).trim()
, switch : (`switch ${processedArgs._[1] || ''}`).trim()
}

var cmds = {
remote : {
// return a interpreted set of arguments for this comd run context.
interpret() {
return { cmd : subcommandlabels['remote'], runchoice : 'c' }
}
}
, switch : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2]
, reposerver : __default.reposerver
}
}
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument...
}
, 'switch user' : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] }
}
, getPossiblePrompts(){ return { username : true } } // Requires only one argument...
}
}

var interpretrun = function(){

var cmd = processedArgs._[0];
var clioverrides = { cmd }
processedArgs.node_env ? clioverrides.node_env = processedArgs.node_env
: (process.env.NODE_ENV && process.env.NODE_ENV.trim())
? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) : null;
return cmds[cmd] ? cmds[cmd].interpret() : (function(){
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
// return clioverrides
cmds[cmd] = {
interpret() {
return Object.assign(clioverrides, { cmd, runchoice : 'c' })
}
, getPossiblePrompts(){ return { cmd, username : true, password : true,
instanceName : true, instanceType : true, reposerver : true } }
}
return cmds[cmd].interpret()
})()
}

var clioverrides = interpretrun()
console.dir(clioverrides)

// Object.keys(clioverrides).forEach( prop => { })

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.
@@ -1921,9 +1884,8 @@ var op = {

g[processedArgs._[1]]();
}

, 'create' : () => {
return createInstance(selectedinstance) }
, 'create' : () => { return createInstance(selectedinstance) }

, 'httpget' : () => {
// RESTAPI.get({
@@ -1936,15 +1898,125 @@ var op = {
return createInstance(selectedinstance)
}

, 'getuser' : ()=>{
return prerequisites.git.getuser().then(u=>{ console.log(u)})
, 'getuser' : ()=>{ return prerequisites.git.getuser().then(u=>{ console.log(u)}) }
, 'switch user' : (tousername)=>{ return GIT['switch user'](tousername) }
}

// elxr cli operations
var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
, remote : true, 'c' : true, 'h' : true
, httpget : true, getuser : true
, 'switch user' : true
, 'switch' : true
// , 'undefined' : true
}

var reconfirmcmds = { create : true }

var subcommandlabels = {
remote : (`remote ${processedArgs._[1] || ''}`).trim()
, switch : (`switch ${processedArgs._[1] || ''}`).trim()
}

var cmds = {
remote : {
// return a interpreted set of arguments for this comd run context.
interpret() {
return { cmd : subcommandlabels['remote'], runchoice : 'c' }
}
}
, switch : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2]
, reposerver : __default.reposerver
}
}
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument...
}
, 'switch user' : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] }
}
, getPossiblePrompts(){ return { username : true } } // Requires only one argument...
}

, 'switch user' : (tousername)=>{
return GIT['switch user'](tousername)
// Flat linear structure. Every subcommand should have a top level 'label'
, 'users' : {
// default to the users list
subcommands : { list : {} }
, cmdFn : ()=>getCredentials() // default
, cmd : 'users'
, noprerequisites : true
}
, 'users list' : {
cmdFn : ()=>getCredentials()
, cmd : 'users list'
, noprerequisites : true
}
}

var elxrcmd = (function(){

var __cmdprototype = function(){}
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() }

var __cmd = {
interpret() { return { cmd : this.cmd } }
, getPossiblePrompts(){ return {} } // Requires only one argument...
, cmdFn : ()=>{ throw "Elxr Unknown command."}
, finalized : true
}

function __createO(o){
if(o.finalized) return o;
var subs = Object.keys(cmds[o.cmd].subcommands || {})
console.log(subs)
console.log(o)
subs.forEach(sub=>elxrcmd.create( cmds[subcommandlabelFor(o.cmd, sub)] ))
var created = utils.assign_strict({}, __cmd, cmds[o.cmd], o)
cmds[o.cmd] = created;
op[o.cmd] = created.cmdFn;
noprerequisites[o.cmd] = created.noprerequisites
return created.cmdFn;
}

function create(o){ return __createO(o) }

__cmdprototype.create = create;

return __cmdprototype;
})()

elxrcmd.create(cmds['users'])

var interpretrun = function(){

var cmd = processedArgs._[0];
var clioverrides = { cmd }
processedArgs.node_env ? clioverrides.node_env = processedArgs.node_env
: (process.env.NODE_ENV && process.env.NODE_ENV.trim())
? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) : null;


return cmds[cmd] ? cmds[cmd].interpret() : (function(){
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
// return clioverrides
cmds[cmd] = {
interpret() {
return Object.assign(clioverrides, { cmd, runchoice : 'c' })
}
, getPossiblePrompts(){ return { cmd, username : true, password : true,
instanceName : true, instanceType : true, reposerver : true } }
}
return cmds[cmd].interpret()
})()
}

var clioverrides = interpretrun()
console.dir(clioverrides)

var util = require('util');
var cliname = 'elxr';
var ver = '1.1';
@@ -2330,6 +2402,13 @@ var acquireData = function(slections){
return any(configPriority.map(cfg => { return function() { return instanceData[cfg](slections) } } ), true, true)
}

// Git Credential storage...
// notepad C:/Program Files/Git/etc/gitconfig
// git config --global --unset credential
// git config --edit --system
// git config --global credential.helper "store --file ~/gitcredentials"
// git credential fill
// git credential-store --file ~/git.store store
var __acquireConfig = function (selected, owner, clusternodename, configrepo, errHandler) {

configrepo = configrepo || selected.instanceName + '-config-' + selected.node_env;
@@ -2389,7 +2468,8 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er
var successHandler = () => {

var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest');
selectedinstance = require(manifestpath)( null, selectedinstance)
utils.assign_strict(selectedinstance, require(manifestpath)( null, selectedinstance))
console.dir(selectedinstance.repos)
// Config from server always override merges into selection except for the current selection.
// PB : TODO -- utils.assign Array merges are non-distinct...
if(!selectedinstance.repos[0].repo) {

読み込み中…
キャンセル
保存