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
});
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";
require("typings-global");
var smartcli_classes_smartcli_1 = require("./smartcli.classes.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
*/
export declare type questionType = "input" | "confirm" | "list" | "rawlist" | "expand" | "checkbox" | "password" | "editor";
export interface choiceObject {
export declare type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
export interface IChoiceObject {
name: string;
value: any;
}
export interface validateFunction {
export interface IValidateFunction {
(any: any): boolean;
}
export declare class Interaction {
@ -16,8 +15,8 @@ export declare class Interaction {
type: questionType;
message: string;
default: any;
choices: string[] | choiceObject[];
validate: validateFunction;
choices: string[] | IChoiceObject[];
validate: IValidateFunction;
}): void;
askQuestionArray: any;
}

View File

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

View File

@ -1,10 +1,9 @@
/// <reference types="q" />
import "typings-global";
import * as plugins from "./smartcli.plugins";
import { Objectmap } from "lik";
export interface commandPromiseObject {
import * as q from 'q';
import { Objectmap } from 'lik';
export interface ICommandPromiseObject {
commandName: string;
promise: plugins.q.Promise<any>;
promise: q.Promise<any>;
}
export declare class Smartcli {
argv: any;
@ -13,7 +12,7 @@ export declare class Smartcli {
commands: any;
questions: any;
version: string;
allCommandPromises: Objectmap<commandPromiseObject>;
allCommandPromises: Objectmap<ICommandPromiseObject>;
constructor();
/**
* 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;
/**
* 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.
*/
addCommand(definitionArg: {
commandName: string;
}): plugins.q.Promise<any>;
}): q.Promise<any>;
/**
* 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
*/
@ -44,7 +42,7 @@ export declare class Smartcli {
/**
* 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
*/

View File

@ -1,18 +1,16 @@
"use strict";
require("typings-global");
const q = require("q");
const plugins = require("./smartcli.plugins");
// import classes
const lik_1 = require("lik");
;
class Smartcli {
constructor() {
// maps
this.allCommandPromises = new lik_1.Objectmap();
this.argv = plugins.yargs;
this.questionsDone = plugins.q.defer();
this.parseStarted = plugins.q.defer();
this.questionsDone = q.defer();
this.parseStarted = q.defer();
}
;
/**
* 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);
return;
}
;
/**
* 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.
*/
addCommand(definitionArg) {
let done = plugins.q.defer();
let done = q.defer();
this.parseStarted.promise
.then(() => {
if (this.argv._.indexOf(definitionArg.commandName) == 0) {
if (this.argv._.indexOf(definitionArg.commandName) === 0) {
done.resolve(this.argv);
}
else {
@ -39,7 +35,6 @@ class Smartcli {
});
return done.promise;
}
;
/**
* gets a Promise for a command word
*/
@ -48,24 +43,22 @@ class Smartcli {
return commandPromiseObjectArg.commandName === commandNameArg;
}).promise;
}
;
/**
* allows to specify help text to be printed above the rest of the help text
*/
addHelp(optionsArg) {
this.addCommand({
commandName: "help"
commandName: 'help'
}).then(argvArg => {
plugins.beautylog.log(optionsArg.helpText);
});
}
;
/**
* specify version to be printed for -v --version
*/
addVersion(versionArg) {
this.version = versionArg;
this.addAlias("v", "version");
this.addAlias('v', 'version');
this.parseStarted.promise
.then(() => {
if (this.argv.v) {
@ -73,21 +66,19 @@ class Smartcli {
}
});
}
;
/**
* returns promise that is resolved when no commands are specified
*/
standardTask() {
let done = plugins.q.defer();
let done = q.defer();
this.parseStarted.promise
.then(() => {
if (this.argv._.length == 0 && !this.argv.v) {
if (this.argv._.length === 0 && !this.argv.v) {
done.resolve(this.argv);
}
else {
done.reject(this.argv);
}
;
});
return done.promise;
}
@ -101,4 +92,4 @@ class Smartcli {
}
}
exports.Smartcli = Smartcli;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixNQUFZLE9BQU8sV0FBTSxvQkFBb0IsQ0FBQyxDQUFBO0FBRzlDLGlCQUFpQjtBQUNqQixzQkFBd0IsS0FBSyxDQUFDLENBQUE7QUFNN0IsQ0FBQztBQUVGO0lBVUk7UUFGQSxPQUFPO1FBQ1AsdUJBQWtCLEdBQUcsSUFBSSxlQUFTLEVBQXdCLENBQUM7UUFFdkQsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDO1FBQzFCLElBQUksQ0FBQyxhQUFhLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUN2QyxJQUFJLENBQUMsWUFBWSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDMUMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxNQUFNLEVBQUMsUUFBUTtRQUNwQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sRUFBQyxRQUFRLENBQUMsQ0FBQztRQUM3QyxNQUFNLENBQUM7SUFDWCxDQUFDOztJQUVE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FBQztJQUVEOztPQUVHO0lBQ0gsVUFBVTtRQUNOLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUE7UUFDMUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUMzQixNQUFNLENBQUE7SUFDVixDQUFDO0NBRUo7QUF0R0QsNEJBc0dDIn0=

View File

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

View File

@ -1,11 +1,15 @@
"use strict";
require("typings-global");
exports.yargs = require('yargs');
exports.beautylog = require("beautylog");
exports.cliff = require("cliff");
exports.inquirer = require("inquirer");
exports.lik = require("lik");
exports.path = require("path");
exports.q = require("q");
exports.smartparam = require("smartparam");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUVWLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGFBQUssV0FBVyxPQUFPLENBQUMsQ0FBQztBQUN6QixnQkFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQy9CLFdBQUcsV0FBVyxLQUFLLENBQUMsQ0FBQztBQUNyQixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ==
const yargs = require("yargs");
exports.yargs = yargs;
const beautylog = require("beautylog");
exports.beautylog = beautylog;
const inquirer = require("inquirer");
exports.inquirer = inquirer;
const lik = require("lik");
exports.lik = lik;
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",
"dependencies": {
"@types/cliff": "^0.1.3",
"@types/inquirer": "0.x.x",
"@types/q": "0.x.x",
"@types/yargs": "0.x.x",
"beautylog": "^5.0.20",
"cliff": "^0.1.10",
"inquirer": "^1.1.2",
"lik": "^1.0.15",
"q": "^1.4.1",

View File

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

View File

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

View File

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

View File

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

View File

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

3
tslint.json Normal file
View File

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