Преглед изворни кода

modified defaults

pull/6/head
chess пре 3 година
родитељ
комит
e3646525a5
2 измењених фајлова са 103 додато и 48 уклоњено
  1. 2
    1
      cliverse.js
  2. 101
    47
      index.js

+ 2
- 1
cliverse.js Прегледај датотеку

@@ -56,7 +56,7 @@ function nodeShellExec() {
});
}
child.on('close', (code) => {
console.log('Proper close was fired')
// console.log('Proper close was fired')
var logEntry = { code, success }
if(+code !== 0 || opts.haserrors) { success = false; logEntry = { result: `${opts.title} exited with code ${code}`, success, code }};
if(opts.stdio !== 'ignore') {
@@ -88,6 +88,7 @@ function nodeShellExec() {
}

var prompt = function(choices, label, defaultchoice){
var choices = choices || [];
return this.prompter.ask(
`${label} \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${ defaultchoice || choices[0]} ) : `
).then(choice => {

+ 101
- 47
index.js Прегледај датотеку

@@ -13,7 +13,7 @@ var chalk = require('chalk')
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
const runtimestamp = (new Date()).getTime();
function getVersion() { return BUILD_VERSION; }
console.log(getVersion())
console.log(getVersion());

// 'use strict';

@@ -27,6 +27,27 @@ console.log(getVersion())
// support runas lauched directly from shell.
// pass in environment in hta to shellexecute.

// PB : NOTE -- iife doesnt work if previous statement is not terminated by ;
(function () {
"use strict";
if (!Array.prototype.earlyreduce) {
Array.prototype.earlyreduce = function(eachcallback, initialValue, donecallback){
var iterable = this;
var donecallback = donecallback || (a=>a)
var result = { value : initialValue === undefined ? iterable[0] : initialValue };
initialValue === undefined ? null : result = eachcallback(result, element, i, iterable);
// function *earlyReduceGenerator(acc, v, i, a) {
for(var i = initialValue === undefined ? 0 : 1; i < iterable.length; i++){
var element = iterable[i]
result = eachcallback(result, element, i, iterable)
if(result.done) return donecallback(result)
}
// }
return donecallback(result)
}
}
}());

const { existsSync } = require('fs');
const fs = require('fs')

@@ -40,6 +61,14 @@ console.dir(processedArgs)
// }
// })

var clioverrides = { }
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
clioverrides.node_env = processedArgs.node_env ?
processedArgs.node_env || (process.env.NODE_ENV && process.env.NODE_ENV.trim())
: (process.env.NODE_ENV && process.env.NODE_ENV.trim())
? (process.env.NODE_ENV && process.env.NODE_ENV.trim()): null;
clioverrides.reconfirm = processedArgs.reconfirm

var globSync = require('glob').sync;

var ENV = Object.assign({}, process.env); // Shallow clone it.
@@ -1963,6 +1992,7 @@ var acquireConfig = function (selected) {
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } })
}
chessinstances[selected.instanceName][selected.node_env] = selectedinstance = utils.assign(selected, selectedinstance)
chessinstances[selected.instanceName][selected.node_env].reposervers = Array.from(new Set(chessinstances[selected.instanceName][selected.node_env].reposervers))
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online...
cacheWriteInstanceConfig(chessinstances)
ENV.NODE_ENV = selectedinstance.node_env;
@@ -1976,6 +2006,32 @@ var acquireConfig = function (selected) {
var launchpath = process.cwd().replace(/\\/, '/')
var thisscriptdir = __dirname
var instanceroot = launchpath;

var __default = {

// Default is public server only.
// All public repos are by default available.
reposervers: ['https://git.bbh.org.in']
, repos: [
{ repo : 'setup' }
, { repo : 'elxr' }
, { repo : 'loopback-connector-mysql' }
, { repo : 'loopback-jsonapi-model-serializer' }
, { repo : 'loopback-component-jsonapi' }
, { repo : 'ember-service-worker' }
, { repo : 'ember-service-worker-asset-cache' }
, { repo : 'ember-service-worker-cache-fallback' }
, { repo : 'ember-service-worker-index' }
, { repo : 'ember-sw-client-route' }
]

, elevated: []
, exludeMergeRepos: {}
, instanceName: 'chess'
// Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in.
, node_env: 'development'
}

var detectInstance = function () {
console.log(`launchpath = ${launchpath}`)
console.log(`thisscriptdir = ${thisscriptdir}`)
@@ -2010,35 +2066,34 @@ var detectInstance = function () {
}
}
}
instanceroot = root.replace(/\\/, '/');
instanceroot = root.replace(/\\/g, '/');
__default.root = root;
return Promise.resolve(__default);
}

//
var __default = {

// Default is public server only.
// All public repos are by default available.
reposervers: ['https://git.bbh.org.in']
, repos: [
'setup'
, 'elxr'
, 'loopback-connector-mysql'
, 'loopback-jsonapi-model-serializer'
, 'loopback-component-jsonapi'
, 'ember-service-worker'
, 'ember-service-worker-asset-cache'
, 'ember-service-worker-cache-fallback'
, 'ember-service-worker-index'
, 'ember-sw-client-route'
]

, elevated: []
, exludeMergeRepos: {}
, instanceName: 'chess'
// Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in.
, node_env: 'development'
clioverrides.root = clioverrides.root || root;

// Resolves undefined when No known instances detected.
return Promise.resolve(
// We can expect a .elxr at each level.
['' /* instanceroot */, '../' /* instanceTypes or node_env */, '../..' /* instanceNames */].earlyreduce( ( acc, p, i, a )=>{
var root = `${instanceroot}/${p}.elxr`;
if(existsSync( root )) {
try {
var chessinstances = acquirelocalinstances( { root } )
return Object.keys(chessinstances).earlyreduce( ( acc, instanceName) => {
return Object.keys(chessinstances[instanceName]).earlyreduce( (acc, instanceType) => {
if( path.normalize(chessinstances[instanceName][instanceType].root) === path.normalize(root) ) return {
value : chessinstances[instanceName][instanceType]
, done : true
};s
})
})
}
catch(e){
return {}
}
}
else return {}
}).value
)
}

var __interactve_promts = {
@@ -2326,12 +2381,20 @@ var getPromptableAsyncPropDescriptor = function(propName, choices, defaultchoise
}
}




function acquirelocalinstances(selected){
var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js')));
return chessinstances
}


// function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) }
var selectedinstance = null;
var chessinstances = { current_run : {} };
acquireElevationState().then(() => {
var skipprerequisites = false;
var clioverrides = { }
function initinstances(selected) {
// PB : TODO -- processedArgs should already be part of selected.
var instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
@@ -2376,12 +2439,7 @@ acquireElevationState().then(() => {

return chessinstances
}
function acquirelocalinstances(selected){
var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js')));
return chessinstances
}


var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
, remote : true
@@ -2429,16 +2487,10 @@ acquireElevationState().then(() => {
}

return detectInstance().then((detectedInstance)=>{

processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
processedArgs.node_env ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || 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;
clioverrides.reconfirm = processedArgs.reconfirm
selectedinstance = Object.assign(detectedInstance, clioverrides);
selectedinstance = Object.assign(detectedInstance || {}, clioverrides);
var todo = Promise.resolve(true);
var promptkeys = { 'instanceName' : processedArgs._[1] }
var promptkeys = { 'instanceName' : clioverrides.instanceName, 'node_env' : clioverrides.node_env }

if(clioverrides.reconfirm) {
var reconfirm = {
@@ -2453,7 +2505,9 @@ acquireElevationState().then(() => {
// No local instances config found. We use a default initialized instance available in selectedinstance
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt.
if(promptkeys[k] && selectedinstance[k] !== promptkeys[k] || promptkeys[k] === undefined && selectedinstance[k] === undefined
// PB : TODO -- selectedinstance === __default check to prompt everything...
if( (promptkeys[k] !== undefined && promptkeys[k] !== null) && selectedinstance[k] !== promptkeys[k]
|| (promptkeys[k] === undefined || promptkeys[k] === null) && (selectedinstance[k] === undefined || selectedinstance[k] === null)
|| reconfirm[k]) {
prompts.push(async ()=>{
// PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked.
@@ -2489,8 +2543,7 @@ acquireElevationState().then(() => {
}
catch (e) {
console.error(e) // Missing chessinstances is not an error...
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error...
initinstances(selectedinstance)
var instanceNameChoices = new Set(Object.keys( chessinstances) )
@@ -2501,6 +2554,7 @@ acquireElevationState().then(() => {
var choices = {
'instanceName' : Array.from(instanceNameChoices)
, 'reposerver' : selectedinstance['reposervers']
, 'instanceType' : ['development', 'production']
}
Object.keys(__interactve_promts).forEach(eachPrompt, __interactve_promts)

Loading…
Откажи
Сачувај