add cli asking for missing vars

This commit is contained in:
2017-05-07 01:23:03 +02:00
parent c6bc044058
commit 6334eb4d0f
8 changed files with 56 additions and 19 deletions

View File

@ -32,15 +32,24 @@ export class ScafTemplate {
*/
async supplyVariables (variablesArg) {
this.suppliedVariables = variablesArg
this.missingVariables = await this._checkSuppliedVariables(variablesArg)
this.missingVariables = await this._checkSuppliedVariables()
}
/**
* Will ask for the missing variables by cli interaction
*/
async askForMissingVariables () {
this.missingVariables = await this._checkSuppliedVariables(variablesArg)
async askCliForMissingVariables () {
this.missingVariables = await this._checkSuppliedVariables()
let localSmartInteract = new plugins.smartinteract.SmartInteract()
for (let missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([{
name: missingVariable,
type: 'input',
default: `undefined ${missingVariable}`,
message: `What is the value of ${missingVariable}?`
}])
}
let answers = await localSmartInteract.runQueue()
}
/**
@ -55,16 +64,16 @@ export class ScafTemplate {
/**
* checks if supplied Variables satisfy the template
*/
private async _checkSuppliedVariables(variablesArg) {
private async _checkSuppliedVariables() {
let missingVars: string[] = []
for (let templateSmartFile of this.templateSmartfileArray) {
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
templateSmartFile.contents.toString(),
variablesArg
this.suppliedVariables
)
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
missingVars = plugins.lodash.uniq(missingVars)
}
return missingVars
}
}