add cli asking for missing vars

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

View File

@ -20,6 +20,10 @@ export declare class ScafTemplate {
* @param variablesArg
*/
supplyVariables(variablesArg: any): Promise<void>;
/**
* Will ask for the missing variables by cli interaction
*/
askCliForMissingVariables(): Promise<void>;
/**
* finds all variables in a Template
*/
@ -27,5 +31,5 @@ export declare class ScafTemplate {
/**
* checks if supplied Variables satisfy the template
*/
private _checkSuppliedVariables(variablesArg);
private _checkSuppliedVariables();
}

View File

@ -30,7 +30,25 @@ class ScafTemplate {
supplyVariables(variablesArg) {
return __awaiter(this, void 0, void 0, function* () {
this.suppliedVariables = variablesArg;
this.missingVariables = yield this._checkSuppliedVariables(variablesArg);
this.missingVariables = yield this._checkSuppliedVariables();
});
}
/**
* Will ask for the missing variables by cli interaction
*/
askCliForMissingVariables() {
return __awaiter(this, void 0, void 0, function* () {
this.missingVariables = yield 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 = yield localSmartInteract.runQueue();
});
}
/**
@ -45,16 +63,17 @@ class ScafTemplate {
/**
* checks if supplied Variables satisfy the template
*/
_checkSuppliedVariables(variablesArg) {
_checkSuppliedVariables() {
return __awaiter(this, void 0, void 0, function* () {
let missingVars = [];
for (let templateSmartFile of this.templateSmartfileArray) {
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartFile.contents.toString(), variablesArg);
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartFile.contents.toString(), this.suppliedVariables);
missingVars = plugins.lodash.concat(missingVars, localMissingVars);
missingVars = plugins.lodash.uniq(missingVars);
}
return missingVars;
});
}
}
exports.ScafTemplate = ScafTemplate;
//# sourceMappingURL=data:application/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RUQ7O09BRUc7SUFDVyx1QkFBdUI7O1lBQ25DLElBQUksV0FBVyxHQUFhLEVBQUUsQ0FBQTtZQUM5QixHQUFHLENBQUMsQ0FBQyxJQUFJLGlCQUFpQixJQUFJLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxDQUFDLENBQUM7Z0JBQzFELElBQUksZ0JBQWdCLEdBQUcsTUFBTSxPQUFPLENBQUMsUUFBUSxDQUFDLHFCQUFxQixDQUNqRSxpQkFBaUIsQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLEVBQ3JDLElBQUksQ0FBQyxpQkFBaUIsQ0FDdkIsQ0FBQTtnQkFDRCxXQUFXLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsV0FBVyxFQUFFLGdCQUFnQixDQUFDLENBQUE7Z0JBQ2xFLFdBQVcsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUNoRCxDQUFDO1lBQ0QsTUFBTSxDQUFDLFdBQVcsQ0FBQTtRQUNwQixDQUFDO0tBQUE7Q0FDRjtBQW5FRCxvQ0FtRUMifQ==

View File

@ -1 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=

View File

@ -3,5 +3,6 @@ import * as lodash from 'lodash';
import * as path from 'path';
import * as smartfile from 'smartfile';
import * as smarthbs from 'smarthbs';
import * as smartinteract from 'smartinteract';
import * as smartq from 'smartq';
export { lodash, path, smartfile, smarthbs, smartq };
export { lodash, path, smartfile, smarthbs, smartinteract, smartq };

View File

@ -9,6 +9,8 @@ const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smarthbs = require("smarthbs");
exports.smarthbs = smarthbs;
const smartinteract = require("smartinteract");
exports.smartinteract = smartinteract;
const smartq = require("smartq");
exports.smartq = smartq;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFPOUIsd0JBQU07QUFOUiw2QkFBNEI7QUFPMUIsb0JBQUk7QUFOTix1Q0FBc0M7QUFPcEMsOEJBQVM7QUFOWCxxQ0FBb0M7QUFPbEMsNEJBQVE7QUFOVixpQ0FBZ0M7QUFPOUIsd0JBQU0ifQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFROUIsd0JBQU07QUFQUiw2QkFBNEI7QUFRMUIsb0JBQUk7QUFQTix1Q0FBc0M7QUFRcEMsOEJBQVM7QUFQWCxxQ0FBb0M7QUFRbEMsNEJBQVE7QUFQViwrQ0FBOEM7QUFRNUMsc0NBQWE7QUFQZixpQ0FBZ0M7QUFROUIsd0JBQU0ifQ==

View File

@ -19,4 +19,8 @@ tap.test('smartfile -> should accept variables', async () => {
console.log(testScafTemplate.missingVariables)
})
tap.test('ask cli', async () => {
await testScafTemplate.askCliForMissingVariables()
})
tap.start()

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

View File

@ -44,11 +44,7 @@
version "2.0.29"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a"
"@types/node@*":
version "7.0.15"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.15.tgz#628429289604c5f7e56c13f3a0422f3e59df1a17"
"@types/node@^6.0.48":
"@types/node@*", "@types/node@^6.0.48":
version "6.0.72"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.72.tgz#0f19de38555f3c33d733d678991347f7d0eefaff"