Sfoglia il codice sorgente

Elixir prerequisite installs

master
chess 3 anni fa
parent
commit
c054e0d923
3 ha cambiato i file con 139 aggiunte e 56 eliminazioni
  1. 137
    54
      index.js
  2. 1
    1
      package.json
  3. 1
    1
      rollup.config.js

+ 137
- 54
index.js Vedi File

@@ -1486,37 +1486,35 @@ var detectInstance = function () {
}
}
instanceroot = root.replace(/\\/, '/');
var __default = {
return Object.assign({ root }, __default);
}

// Default is public server only.
reposervers: ['https://git.bbh.org.in']
var __default = {

// All public repos are by default available.
, repos: [
// 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'
}
return Object.assign({ root }, __default);
, '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'
}

var gitUser = 'chessdemo';
var gitEmail = 'chessdemo@bbh.org.in'
var downloadsdir = '../Downloads';
var prerequisites = [
{
@@ -1528,34 +1526,105 @@ var prerequisites = [
, '/VERYSILENT'
// , '/MERGETASKS=!runcode' // This is required only for vscode...
]]
, preinstallsteps: () => {
, preinstallsteps: function() {
var prompt = cli.prompt;
var steps = [
() => {
if (!existsSync(downloadsdir + '/' + preq.installer)) {
return nodeShellExec('download.bat', [preq.url, downloadsdir + '/' + preq.installer])
if (!existsSync(downloadsdir + '/' + this.installer)) {
return nodeShellExec('download.bat', [this.url, downloadsdir + '/' + this.installer])
}
else return Promise.resolve(true)
}
]
var prompts = [
() => prompt.ask(`git user name : ( <= ${gitUser} )`).then((user) => { gitUser = user; })
, () => prompt.ask(`git user name : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; })
, () => prompt.ask(`git email : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; })
]
return Promise.all([any(steps), any(prompts)]).finally(() => { prompt.close() })
return any([any(steps), any(prompts)]).then(() => { prompt.close() })
}
, installsteps: function () {
return any([this.installcmd].map(callsheltask))
}
, postinstallsteps: () => {
var steps = [
['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]]
, ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]]
]
return any(steps.map(callsheltask)).then(() => { })
, postinstallsteps: function(){
var prompt = cli.prompt;
var gitUser = 'guest';
var gitEmail = 'guest@bbh.org.in';
var prompts = [];
prompts.push(
()=>{
var choices = { 0 : 'guest', 1 : 'chessdemo' }
return prompt.ask(
`git user name \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${choices[0]} ) : `
).then(choice => {
if(!choice) return gitUser = choices[0];
if(choice && isNaN(+choice)) return gitUser = choice;
return gitUser = choices[choice + 1];
})
}
)

prompts.push(
()=>{
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
return prompt.ask(
`git user email \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${choices[0]} ) : `
).then(choice => {
if(!choice) return gitEmail = choices[0];
if(choice && isNaN(+choice)) return gitEmail = choice;
return gitEmail = choices[choice + 1];
})
}
)

return any(prompts).then(()=>{
var steps = [
['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]]
, ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]]
]
return any(steps.map(callsheltask)).then(() => {

})
});
}
, install: function () {
return any([ /*this.preinstallsteps,*/ this.installsteps, this.postinstallsteps])
return any([ /*this.preinstallsteps,*/ this.installsteps.bind(this), this.postinstallsteps.bind(this)])
}
, verifyAndInstall : function(){
return getTaskCheckExists(this.shellcmd, { ignorefailures: true })().then((exists) => {
if(exists) {
// return any(['git', ['config', '--global', '-l']].map(callsheltask))
return this.getUser(null, this.postinstallsteps.bind(this))
}
return this.install();
});
}
, getUser : function(repo, onNoResult){
onNoResult = onNoResult || function(){return false}
var globalOrLocal = '--global';
if(!repo) globalOrLocal = '--global';
else globalOrLocal = '--local'

return any([['git', ['config', globalOrLocal, '--get-all', 'user.name']]].map(callsheltask)).then((result)=>{
// not yet configured.
if(!result.success) return onNoResult()
else {
var users = result.messages[0].trim().split('\n');
if(users.length === 0 ||
users.length === 1 && users[0] === 'guest') {
return onNoResult()
}
else return users[0]; // PB : TODO == We should probably prompt with all the users available for selection !
}
})
.catch((e)=>{
console.log(e)
return onNoResult()
})
}
}
,
@@ -1566,9 +1635,12 @@ var prerequisites = [
, installcmd: ['MSIEXEC.exe', ['/i'
, path.resolve(downloadsdir + '/' + 'node-v14.16.0-x64.msi')
, 'ACCEPT=YES', '/passive']]
, install : function() { return any([this.installcmd].map(callsheltask)).then(() => { }) }
}
]

prerequisites.forEach(p=>{ prerequisites[p.shellcmd] = p })

function ensureDirectoryExistence(filePath) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
@@ -1600,8 +1672,8 @@ function verifyAndInstallPrerequisites() {
if (exists) console.log(`${preq.shellcmd} exists`)
else {
console.log(`${preq.shellcmd} is not installed`)
return preq.preinstallsteps().then(() => {
installtasks.push(task.install)
return preq.preinstallsteps.call(preq).then(() => {
installtasks.push(preq.install.bind(preq))
})
}
}))
@@ -1630,16 +1702,19 @@ 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;

selectedinstance = detectedInstance = Object.assign(selectedinstance, clioverrides);
var maintask = () => {
try {
// Default cmd to run !
var chessinstances = acquirelocalinstances(selectedinstance);
processedArgs._[0] === processedArgs._[0] || 'pull';
// defaultRepoServer = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available...
return acquireConfig(selectedinstance, chessinstances).catch((e) => {
console.error('Exisitng config Failed. Fix config and rerun or chose another.')
console.error(e);
}).then(() => { return elxrworker(true) })
return prerequisites.git.verifyAndInstall().then(()=>{
return acquireConfig(selectedinstance, chessinstances).catch((e) => {
console.error('Exisitng config Failed. Fix config and rerun or chose another.')
console.error(e);
}).then(() => { return elxrworker(true) })
});
}
catch (e) {
console.error(e)
@@ -1647,7 +1722,14 @@ var maintask = () => {
chessinstances = {}
chessinstances.current_run = {}
initinstances(chessinstances, selectedinstance)
return acquireChoices(selectedinstance).then(() => {
var todo = Promise.resolve(true);
if(processedArgs._[0] && selectedinstance.node_env && selectedinstance.instanceName){
// Weve been told what to do.
todo = Promise.resolve(true)
}
else todo = acquireChoices(selectedinstance)

return todo.then(() => {
try {
var chessinstances = acquirelocalinstances(selectedinstance)
}
@@ -1657,15 +1739,16 @@ var maintask = () => {
console.log('A config will be createed with the instance and environment chosen...')
}
finally {
return acquireConfig(selectedinstance, chessinstances).catch((e) => {
console.error('Chosen cofiguraton failed or not found')
console.error(e)
}).then(() => { return elxrworker(true) })
.finally(()=>{
fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
fs.writeFileSync('run.done', 'error');
// return process.exit()
return prerequisites.git.verifyAndInstall().then(()=>{
return acquireConfig(selectedinstance, chessinstances).catch((e) => {
console.error('Chosen cofiguraton failed or not found')
console.error(e)
}).then(() => { return elxrworker(true) })
.finally(()=>{
fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
fs.writeFileSync('run.done', 'error');
// return process.exit()
})
})
}
})

+ 1
- 1
package.json Vedi File

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-commented": "rollup index.js --format cjs --file elxr.js",
"build-commented": "rollup index.js --format cjs --file i.js",
"build": "rollup -c"
},
"keywords": [],

+ 1
- 1
rollup.config.js Vedi File

@@ -5,7 +5,7 @@ import versionInjector from 'rollup-plugin-version-injector';
export default {
input: 'index.js',
output: {
file : 'elxr.js'
file : 'i.js'
, format: 'cjs'
},
// external: ['chessinstances'],

Loading…
Annulla
Salva