implement standardJS

This commit is contained in:
Philipp Kunz 2016-10-15 00:56:02 +02:00
parent 7ca18c4a46
commit 7833bd0be8
17 changed files with 152 additions and 162 deletions

View File

View File

@ -43,5 +43,8 @@ mySmartcli.standardTask()
// do something if program is called without an command // do something if program is called without an command
}); });
mySmartcli.question mySmartcli.addCommand({commandname: 'install'})
.then(argvArg => {
// do something if program is called with command "install"
})
``` ```

3
dist/index.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-global"; export { Smartcli } from './smartcli.classes.smartcli';
export { Smartcli } from "./smartcli.classes.smartcli";

3
dist/index.js vendored
View File

@ -1,5 +1,4 @@
"use strict"; "use strict";
require("typings-global");
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli"); var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli; exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBR3hCLDBDQUF1Qiw2QkFBNkIsQ0FBQztBQUE3Qyx3REFBNkMifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUVBQXNEO0FBQTdDLCtDQUFBLFFBQVEsQ0FBQSJ9

View File

@ -1,13 +1,12 @@
import "typings-global";
/** /**
* allows to specify an user interaction during runtime * allows to specify an user interaction during runtime
*/ */
export declare type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor"; export declare type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
export interface choiceObject { export interface IChoiceObject {
name: string; name: string;
value: any; value: any;
} }
export interface validateFunction { export interface IValidateFunction {
(any: any): boolean; (any: any): boolean;
} }
export declare class Interaction { export declare class Interaction {
@ -16,8 +15,8 @@ export declare class Interaction {
type: questionType; type: questionType;
message: string; message: string;
default: any; default: any;
choices: string[] | choiceObject[]; choices: string[] | IChoiceObject[];
validate: validateFunction; validate: IValidateFunction;
}): void; }): void;
askQuestionArray: any; askQuestionArray: any;
} }

View File

@ -1,10 +1,8 @@
"use strict"; "use strict";
require("typings-global");
const plugins = require("./smartcli.plugins"); const plugins = require("./smartcli.plugins");
class Interaction { class Interaction {
constructor() { constructor() {
} }
;
askQuestion(optionsArg) { askQuestion(optionsArg) {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.inquirer.prompt([{ plugins.inquirer.prompt([{
@ -17,25 +15,21 @@ class Interaction {
done.resolve(answers); done.resolve(answers);
}); });
} }
;
} }
exports.Interaction = Interaction; exports.Interaction = Interaction;
class QuestionTree { class QuestionTree {
constructor(questionString, optionsArray) { constructor(questionString, optionsArray) {
} }
;
} }
exports.QuestionTree = QuestionTree; exports.QuestionTree = QuestionTree;
;
class QuestionTreeNode { class QuestionTreeNode {
constructor() { constructor() {
} }
} }
exports.QuestionTreeNode = QuestionTreeNode; exports.QuestionTreeNode = QuestionTreeNode;
;
class QuestionStorage { class QuestionStorage {
constructor() { constructor() {
} }
} }
exports.QuestionStorage = QuestionStorage; exports.QuestionStorage = QuestionStorage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5pbnRlcmFjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5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yIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDhDQUE2QztBQWU3QztJQUNJO0lBQ0EsQ0FBQztJQUVELFdBQVcsQ0FBQyxVQU1YO1FBQ0csSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDO2dCQUNyQixJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUk7Z0JBQ3JCLE9BQU8sRUFBRSxVQUFVLENBQUMsT0FBTztnQkFDM0IsT0FBTyxFQUFFLFVBQVUsQ0FBQyxPQUFPO2dCQUMzQixPQUFPLEVBQUUsVUFBVSxDQUFDLE9BQU87Z0JBQzNCLFFBQVEsRUFBRSxVQUFVLENBQUMsUUFBUTthQUNoQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsT0FBTztZQUNaLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDekIsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBRUo7QUF2QkQsa0NBdUJDO0FBR0Q7SUFFSSxZQUFZLGNBQXNCLEVBQUUsWUFBWTtJQUVoRCxDQUFDO0NBQ0o7QUFMRCxvQ0FLQztBQUVEO0lBQ0k7SUFFQSxDQUFDO0NBQ0o7QUFKRCw0Q0FJQztBQUVEO0lBQ0k7SUFFQSxDQUFDO0NBQ0o7QUFKRCwwQ0FJQyJ9

View File

@ -1,10 +1,9 @@
/// <reference types="q" /> /// <reference types="q" />
import "typings-global"; import * as q from 'q';
import * as plugins from "./smartcli.plugins"; import { Objectmap } from 'lik';
import { Objectmap } from "lik"; export interface ICommandPromiseObject {
export interface commandPromiseObject {
commandName: string; commandName: string;
promise: plugins.q.Promise<any>; promise: q.Promise<any>;
} }
export declare class Smartcli { export declare class Smartcli {
argv: any; argv: any;
@ -13,7 +12,7 @@ export declare class Smartcli {
commands: any; commands: any;
questions: any; questions: any;
version: string; version: string;
allCommandPromises: Objectmap<commandPromiseObject>; allCommandPromises: Objectmap<ICommandPromiseObject>;
constructor(); constructor();
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
@ -21,16 +20,15 @@ export declare class Smartcli {
addAlias(keyArg: any, aliasArg: any): void; addAlias(keyArg: any, aliasArg: any): void;
/** /**
* adds a Command by returning a Promise that reacts to the specific commandString given. * adds a Command by returning a Promise that reacts to the specific commandString given.
*
* Note: in e.g. "npm install something" the "install" is considered the command. * Note: in e.g. "npm install something" the "install" is considered the command.
*/ */
addCommand(definitionArg: { addCommand(definitionArg: {
commandName: string; commandName: string;
}): plugins.q.Promise<any>; }): q.Promise<any>;
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
getCommandPromiseByName(commandNameArg: string): plugins.q.Promise<any>; getCommandPromiseByName(commandNameArg: string): q.Promise<any>;
/** /**
* allows to specify help text to be printed above the rest of the help text * allows to specify help text to be printed above the rest of the help text
*/ */
@ -44,7 +42,7 @@ export declare class Smartcli {
/** /**
* returns promise that is resolved when no commands are specified * returns promise that is resolved when no commands are specified
*/ */
standardTask(): plugins.q.Promise<any>; standardTask(): q.Promise<any>;
/** /**
* start the process of evaluating commands * start the process of evaluating commands
*/ */

View File

@ -1,18 +1,16 @@
"use strict"; "use strict";
require("typings-global"); const q = require("q");
const plugins = require("./smartcli.plugins"); const plugins = require("./smartcli.plugins");
// import classes // import classes
const lik_1 = require("lik"); const lik_1 = require("lik");
;
class Smartcli { class Smartcli {
constructor() { constructor() {
// maps // maps
this.allCommandPromises = new lik_1.Objectmap(); this.allCommandPromises = new lik_1.Objectmap();
this.argv = plugins.yargs; this.argv = plugins.yargs;
this.questionsDone = plugins.q.defer(); this.questionsDone = q.defer();
this.parseStarted = plugins.q.defer(); this.parseStarted = q.defer();
} }
;
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
*/ */
@ -20,17 +18,15 @@ class Smartcli {
this.argv = this.argv.alias(keyArg, aliasArg); this.argv = this.argv.alias(keyArg, aliasArg);
return; return;
} }
;
/** /**
* adds a Command by returning a Promise that reacts to the specific commandString given. * adds a Command by returning a Promise that reacts to the specific commandString given.
*
* Note: in e.g. "npm install something" the "install" is considered the command. * Note: in e.g. "npm install something" the "install" is considered the command.
*/ */
addCommand(definitionArg) { addCommand(definitionArg) {
let done = plugins.q.defer(); let done = q.defer();
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) { if (this.argv._.indexOf(definitionArg.commandName) === 0) {
done.resolve(this.argv); done.resolve(this.argv);
} }
else { else {
@ -39,7 +35,6 @@ class Smartcli {
}); });
return done.promise; return done.promise;
} }
;
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
@ -48,24 +43,22 @@ class Smartcli {
return commandPromiseObjectArg.commandName === commandNameArg; return commandPromiseObjectArg.commandName === commandNameArg;
}).promise; }).promise;
} }
;
/** /**
* allows to specify help text to be printed above the rest of the help text * allows to specify help text to be printed above the rest of the help text
*/ */
addHelp(optionsArg) { addHelp(optionsArg) {
this.addCommand({ this.addCommand({
commandName: "help" commandName: 'help'
}).then(argvArg => { }).then(argvArg => {
plugins.beautylog.log(optionsArg.helpText); plugins.beautylog.log(optionsArg.helpText);
}); });
} }
;
/** /**
* specify version to be printed for -v --version * specify version to be printed for -v --version
*/ */
addVersion(versionArg) { addVersion(versionArg) {
this.version = versionArg; this.version = versionArg;
this.addAlias("v", "version"); this.addAlias('v', 'version');
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv.v) { if (this.argv.v) {
@ -73,21 +66,19 @@ class Smartcli {
} }
}); });
} }
;
/** /**
* returns promise that is resolved when no commands are specified * returns promise that is resolved when no commands are specified
*/ */
standardTask() { standardTask() {
let done = plugins.q.defer(); let done = q.defer();
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv._.length == 0 && !this.argv.v) { if (this.argv._.length === 0 && !this.argv.v) {
done.resolve(this.argv); done.resolve(this.argv);
} }
else { else {
done.reject(this.argv); done.reject(this.argv);
} }
;
}); });
return done.promise; return done.promise;
} }
@ -101,4 +92,4 @@ class Smartcli {
} }
} }
exports.Smartcli = Smartcli; exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBRzlDLGlCQUFpQjtBQUNqQixzQkFBd0IsS0FBSyxDQUFDLENBQUE7QUFNN0IsQ0FBQztBQUVGO0lBVUk7UUFGQSxPQUFPO1FBQ1AsdUJBQWtCLEdBQUcsSUFBSSxlQUFTLEVBQXdCLENBQUM7UUFFdkQsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDO1FBQzFCLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUN2QyxJQUFJLENBQUMsWUFBWSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDMUMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxNQUFNLEVBQUMsUUFBUTtRQUNwQixJ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FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7WUFDMUIsQ0FBQztRQUNMLENBQUMsQ0FBQyxDQUFBO1FBQ04sTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsVUFBVTtRQUNOLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUE7UUFDMUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUMzQixNQUFNLENBQUE7SUFDVixDQUFDO0NBRUo7QUF0R0QsNEJBc0dDIn0=

View File

@ -1,9 +1,8 @@
import "typings-global"; import 'typings-global';
export import yargs = require('yargs'); import * as yargs from 'yargs';
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog';
export import cliff = require("cliff"); import * as inquirer from 'inquirer';
export import inquirer = require("inquirer"); import * as lik from 'lik';
export import lik = require("lik"); import * as path from 'path';
export import path = require("path"); import * as smartparam from 'smartparam';
export import q = require("q"); export { yargs, beautylog, cliff, inquirer, lik, path, smartparam };
export import smartparam = require("smartparam");

View File

@ -1,11 +1,15 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.yargs = require('yargs'); const yargs = require("yargs");
exports.beautylog = require("beautylog"); exports.yargs = yargs;
exports.cliff = require("cliff"); const beautylog = require("beautylog");
exports.inquirer = require("inquirer"); exports.beautylog = beautylog;
exports.lik = require("lik"); const inquirer = require("inquirer");
exports.path = require("path"); exports.inquirer = inquirer;
exports.q = require("q"); const lik = require("lik");
exports.smartparam = require("smartparam"); exports.lik = lik;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUVWLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUNyQixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ== const path = require("path");
exports.path = path;
const smartparam = require("smartparam");
exports.smartparam = smartparam;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QjtBQUV4QiwrQkFBOEI7QUFRMUIsZ0JBUlEsS0FBSyxDQVFSO0FBUFQsdUNBQXNDO0FBUWxDLG9CQVJRLFNBQVMsQ0FRUjtBQVBiLHFDQUFvQztBQVNoQyxtQkFUUSxRQUFRLENBU1I7QUFSWiwyQkFBMEI7QUFTdEIsY0FUUSxHQUFHLENBU1I7QUFSUCw2QkFBNEI7QUFTeEIsZUFUUSxJQUFJLENBU1I7QUFSUix5Q0FBd0M7QUFTcEMscUJBVFEsVUFBVSxDQVNSIn0=

View File

@ -28,12 +28,10 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartcli", "homepage": "https://gitlab.com/pushrocks/smartcli",
"dependencies": { "dependencies": {
"@types/cliff": "^0.1.3",
"@types/inquirer": "0.x.x", "@types/inquirer": "0.x.x",
"@types/q": "0.x.x", "@types/q": "0.x.x",
"@types/yargs": "0.x.x", "@types/yargs": "0.x.x",
"beautylog": "^5.0.20", "beautylog": "^5.0.20",
"cliff": "^0.1.10",
"inquirer": "^1.1.2", "inquirer": "^1.1.2",
"lik": "^1.0.15", "lik": "^1.0.15",
"q": "^1.4.1", "q": "^1.4.1",

View File

@ -33,4 +33,4 @@ describe("smartcli.Smartcli class", function () {
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFFdEIsTUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUUvQixRQUFRLENBQUMseUJBQXlCLEVBQUM7SUFDL0IsSUFBSSxrQkFBb0MsQ0FBQztJQUN6QyxRQUFRLENBQUMsZ0JBQWdCLEVBQUM7UUFDdEIsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1lBQzlCLGtCQUFrQixHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO1lBQzdDLGtCQUFrQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUMvRCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGFBQWEsRUFBQztRQUNuQixFQUFFLENBQUMsdUJBQXVCLEVBQUM7WUFDdkIsa0JBQWtCLENBQUMsVUFBVSxDQUFDO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4QixFQUFDO1lBQzlCLGtCQUFrQixHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO1lBQzdDLGtCQUFrQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUMvRCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGFBQWEsRUFBQztRQUNuQixFQUFFLENBQUMsdUJBQXVCLEVBQUM7WUFDdkIsa0JBQWtCLENBQUMsVUFBVSxDQUFDO2dCQUMxQixXQUFXLEVBQUMsU0FBUzthQUN4QixDQUFDLENBQUM7UUFFUCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMscUNBQXFDLEVBQUMsVUFBUyxJQUFJO1lBQ2xELGtCQUFrQixDQUFDLFlBQVksRUFBRTtpQkFDNUIsSUFBSSxDQUFDO2dCQUNGLE9BQU8sQ0FBQyxHQUFHLENBQUMsNEJBQTRCLENBQUMsQ0FBQztZQUM5QyxDQUFDLENBQUMsQ0FBQztZQUNQLElBQUksRUFBRSxDQUFDO1FBQ1gsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUNGLFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLG9DQUFvQyxFQUFDO1lBQ3BDLGtCQUFrQixDQUFDLFVBQVUsRUFBRSxDQUFDO1FBQ3BDLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQyJ9

View File

@ -1,4 +1 @@
import "typings-global"; export { Smartcli } from './smartcli.classes.smartcli'
import {Smartcli} from "./smartcli.classes.smartcli";
export {Smartcli} from "./smartcli.classes.smartcli";

View File

@ -1,31 +1,30 @@
import "typings-global"; import * as plugins from './smartcli.plugins'
import * as plugins from "./smartcli.plugins";
/** /**
* allows to specify an user interaction during runtime * allows to specify an user interaction during runtime
*/ */
export type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor" export type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor'
export interface choiceObject { export interface IChoiceObject {
name: string; name: string
value: any value: any
} }
export interface validateFunction { export interface IValidateFunction {
(any): boolean (any): boolean
} }
export class Interaction { export class Interaction {
constructor() { constructor() {
}; }
askQuestion(optionsArg: { askQuestion(optionsArg: {
type: questionType, type: questionType,
message: string message: string
default: any default: any
choices: string[] | choiceObject[]; choices: string[] | IChoiceObject[]
validate: validateFunction validate: IValidateFunction
}) { }) {
let done = plugins.q.defer(); let done = plugins.q.defer()
plugins.inquirer.prompt([{ plugins.inquirer.prompt([{
type: optionsArg.type, type: optionsArg.type,
message: optionsArg.message, message: optionsArg.message,
@ -33,9 +32,9 @@ export class Interaction {
choices: optionsArg.choices, choices: optionsArg.choices,
validate: optionsArg.validate validate: optionsArg.validate
}]).then(answers => { }]).then(answers => {
done.resolve(answers); done.resolve(answers)
}); })
}; }
askQuestionArray askQuestionArray
} }
@ -44,14 +43,14 @@ export class QuestionTree {
constructor(questionString: string, optionsArray) { constructor(questionString: string, optionsArray) {
}; }
}; }
export class QuestionTreeNode { export class QuestionTreeNode {
constructor() { constructor() {
} }
}; }
export class QuestionStorage { export class QuestionStorage {
constructor() { constructor() {

View File

@ -1,67 +1,66 @@
import "typings-global"; import * as q from 'q'
import * as plugins from "./smartcli.plugins"; import * as plugins from './smartcli.plugins'
import * as interaction from "./smartcli.classes.interaction"; import * as interaction from './smartcli.classes.interaction'
// import classes // import classes
import {Objectmap} from "lik"; import {Objectmap} from 'lik'
// interfaces // interfaces
export interface commandPromiseObject { export interface ICommandPromiseObject {
commandName:string; commandName: string
promise: plugins.q.Promise<any>; promise: q.Promise<any>
}; }
export class Smartcli { export class Smartcli {
argv:any; argv: any
questionsDone; questionsDone
parseStarted; parseStarted
commands; commands
questions; questions
version:string; version: string
// maps // maps
allCommandPromises = new Objectmap<commandPromiseObject>(); allCommandPromises = new Objectmap<ICommandPromiseObject>()
constructor() { constructor() {
this.argv = plugins.yargs; this.argv = plugins.yargs
this.questionsDone = plugins.q.defer(); this.questionsDone = q.defer()
this.parseStarted = plugins.q.defer(); this.parseStarted = q.defer()
}; }
/** /**
* adds an alias, meaning one equals the other in terms of triggering associated commands * adds an alias, meaning one equals the other in terms of triggering associated commands
*/ */
addAlias(keyArg,aliasArg): void { addAlias(keyArg,aliasArg): void {
this.argv = this.argv.alias(keyArg,aliasArg); this.argv = this.argv.alias(keyArg,aliasArg)
return; return
}; }
/** /**
* adds a Command by returning a Promise that reacts to the specific commandString given. * adds a Command by returning a Promise that reacts to the specific commandString given.
*
* Note: in e.g. "npm install something" the "install" is considered the command. * Note: in e.g. "npm install something" the "install" is considered the command.
*/ */
addCommand(definitionArg:{commandName:string}):plugins.q.Promise<any>{ addCommand(definitionArg: {commandName: string}): q.Promise<any> {
let done = plugins.q.defer<any>(); let done = q.defer<any>()
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) { if (this.argv._.indexOf(definitionArg.commandName) === 0) {
done.resolve(this.argv); done.resolve(this.argv)
} else { } else {
done.reject(this.argv); done.reject(this.argv)
}
})
return done.promise
} }
});
return done.promise;
};
/** /**
* gets a Promise for a command word * gets a Promise for a command word
*/ */
getCommandPromiseByName(commandNameArg: string) { getCommandPromiseByName(commandNameArg: string) {
return this.allCommandPromises.find(commandPromiseObjectArg => { return this.allCommandPromises.find(commandPromiseObjectArg => {
return commandPromiseObjectArg.commandName === commandNameArg; return commandPromiseObjectArg.commandName === commandNameArg
}).promise; }).promise
}; }
/** /**
* allows to specify help text to be printed above the rest of the help text * allows to specify help text to be printed above the rest of the help text
@ -70,49 +69,49 @@ export class Smartcli {
helpText: string helpText: string
}) { }) {
this.addCommand({ this.addCommand({
commandName:"help" commandName: 'help'
}).then(argvArg => { }).then(argvArg => {
plugins.beautylog.log(optionsArg.helpText); plugins.beautylog.log(optionsArg.helpText)
}) })
}; }
/** /**
* specify version to be printed for -v --version * specify version to be printed for -v --version
*/ */
addVersion(versionArg: string) { addVersion(versionArg: string) {
this.version = versionArg; this.version = versionArg
this.addAlias("v","version"); this.addAlias('v','version')
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if (this.argv.v) { if (this.argv.v) {
console.log(this.version); console.log(this.version)
} }
}) })
}; }
/** /**
* returns promise that is resolved when no commands are specified * returns promise that is resolved when no commands are specified
*/ */
standardTask():plugins.q.Promise<any>{ standardTask(): q.Promise<any> {
let done = plugins.q.defer<any>(); let done = q.defer<any>()
this.parseStarted.promise this.parseStarted.promise
.then(() => { .then(() => {
if(this.argv._.length == 0 && !this.argv.v){ if (this.argv._.length === 0 && !this.argv.v) {
done.resolve(this.argv); done.resolve(this.argv)
} else { } else {
done.reject(this.argv); done.reject(this.argv)
}; }
}); })
return done.promise; return done.promise
} }
/** /**
* start the process of evaluating commands * start the process of evaluating commands
*/ */
startParse(): void { startParse(): void {
this.argv = this.argv.argv; this.argv = this.argv.argv
this.parseStarted.resolve(); this.parseStarted.resolve()
return; return
} }
} }

View File

@ -1,10 +1,18 @@
import "typings-global"; import 'typings-global';
export import yargs = require('yargs'); import * as yargs from 'yargs'
export import beautylog = require("beautylog"); import * as beautylog from 'beautylog'
export import cliff = require("cliff"); import * as inquirer from 'inquirer'
export import inquirer = require("inquirer"); import * as lik from 'lik'
export import lik = require("lik"); import * as path from 'path'
export import path = require("path"); import * as smartparam from 'smartparam'
export import q = require("q");
export import smartparam = require("smartparam"); export {
yargs,
beautylog,
cliff,
inquirer,
lik,
path,
smartparam
}

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}