@ionic/cli-framework
Advanced tools
Comparing version 0.2.0-alpha.fefc39d3 to 1.0.0-alpha.0303b03e
@@ -6,2 +6,10 @@ # Change Log | ||
<a name="0.1.2"></a> | ||
## [0.1.2](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@0.1.1...@ionic/cli-framework@0.1.2) (2017-11-22) | ||
**Note:** Version bump only for package @ionic/cli-framework | ||
<a name="0.1.1"></a> | ||
@@ -8,0 +16,0 @@ ## [0.1.1](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@0.1.0...@ionic/cli-framework@0.1.1) (2017-11-09) |
import * as minimistType from 'minimist'; | ||
export declare type CommandLineInput = string | boolean | null | undefined | string[]; | ||
export declare type ParsedArg = string | boolean | null | undefined | string[]; | ||
export declare type Validator = (input?: string, key?: string) => true | string; | ||
export declare type CommandLineInputs = string[]; | ||
export declare type Validator = (input?: string, key?: string) => true | string; | ||
export interface CommandLineOptions extends minimistType.ParsedArgs { | ||
[arg: string]: CommandLineInput; | ||
[arg: string]: ParsedArg; | ||
} | ||
export declare type CommandOptionType = StringConstructor | BooleanConstructor; | ||
export interface CommandInput { | ||
export interface CommandMetadataInput { | ||
name: string; | ||
description: string; | ||
validators?: Validator[]; | ||
required?: boolean; | ||
private?: boolean; | ||
} | ||
export interface CommandOption { | ||
export declare type MetadataGroup = string | number | symbol; | ||
export interface CommandMetadataOption { | ||
name: string; | ||
description: string; | ||
type?: CommandOptionType; | ||
default?: CommandLineInput; | ||
default?: ParsedArg; | ||
aliases?: string[]; | ||
private?: boolean; | ||
intents?: string[]; | ||
visible?: boolean; | ||
advanced?: boolean; | ||
groups?: MetadataGroup[]; | ||
} | ||
export interface CommandData<T = CommandInput, U = CommandOption> { | ||
export interface HydratedCommandOption { | ||
type: CommandOptionType; | ||
default: ParsedArg; | ||
aliases: string[]; | ||
} | ||
export interface HydratedParseArgsOptions extends minimistType.Opts { | ||
string: string[]; | ||
boolean: string[]; | ||
alias: { | ||
[key: string]: string[]; | ||
}; | ||
default: { | ||
[key: string]: ParsedArg; | ||
}; | ||
} | ||
export interface Metadata { | ||
name: string; | ||
description: string; | ||
longDescription?: string; | ||
groups?: MetadataGroup[]; | ||
} | ||
export interface CommandMetadata<I = CommandMetadataInput, O = CommandMetadataOption> extends Metadata { | ||
exampleCommands?: string[]; | ||
deprecated?: boolean; | ||
aliases?: string[]; | ||
inputs?: T[]; | ||
options?: U[]; | ||
visible?: boolean; | ||
inputs?: I[]; | ||
options?: O[]; | ||
} | ||
export interface ICommand<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> { | ||
namespace: N; | ||
getMetadata(): Promise<M>; | ||
run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void>; | ||
validate(argv: CommandLineInputs): Promise<void>; | ||
} | ||
export declare type CommandMapKey = string | symbol; | ||
export declare type CommandMapGetter<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> = () => Promise<C>; | ||
export declare type NamespaceMapGetter<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> = () => Promise<N>; | ||
export interface ICommandMap<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> extends Map<CommandMapKey, string | CommandMapGetter<C, N, M, I, O>> { | ||
getAliases(): Map<CommandMapKey, CommandMapKey[]>; | ||
resolveAliases(cmd: string): CommandMapGetter<C, N, M, I, O> | undefined; | ||
} | ||
export interface INamespaceMap<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> extends Map<string, NamespaceMapGetter<C, N, M, I, O>> { | ||
} | ||
export interface INamespace<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> { | ||
parent: N | undefined; | ||
getMetadata(): Promise<NamespaceMetadata>; | ||
getNamespaces(): Promise<INamespaceMap<C, N, M, I, O>>; | ||
getCommands(): Promise<ICommandMap<C, N, M, I, O>>; | ||
locate(argv: string[]): Promise<NamespaceLocateResult<C, N, M, I, O>>; | ||
getCommandMetadataList(): Promise<(M & HydratedCommandMetadata<C, N, M, I, O>)[]>; | ||
} | ||
export declare type CommandPathItem<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> = [string, C | N]; | ||
export interface NamespaceLocateResult<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> { | ||
obj: C | N; | ||
args: string[]; | ||
path: CommandPathItem<C, N, M, I, O>[]; | ||
} | ||
export interface HydratedCommandMetadata<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> { | ||
command: C; | ||
namespace: N; | ||
path: CommandPathItem<C, N, M, I, O>[]; | ||
aliases: string[]; | ||
} | ||
export interface NamespaceMetadata extends Metadata { | ||
} | ||
export interface PackageJson { | ||
name: string; | ||
version?: string; | ||
version: string; | ||
scripts?: { | ||
@@ -64,6 +114,8 @@ [key: string]: string; | ||
numeric: Validator; | ||
url: Validator; | ||
} | ||
export interface ValidationError { | ||
key: string; | ||
message: string; | ||
inputName: string; | ||
validator: Validator; | ||
} |
@@ -1,4 +0,6 @@ | ||
import { BowerJson, PackageJson, ValidationError } from './definitions'; | ||
export declare function isPackageJson(o: Object): o is PackageJson; | ||
export declare function isBowerJson(o: Object): o is BowerJson; | ||
export declare function isValidationErrorArray(e: Object[]): e is ValidationError[]; | ||
import { BowerJson, CommandMapKey, CommandMetadata, CommandMetadataInput, CommandMetadataOption, ICommand, INamespace, PackageJson } from './definitions'; | ||
export declare function isNamespace<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption>(obj: any): obj is N; | ||
export declare function isCommand<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption>(obj: any): obj is C; | ||
export declare function isCommandMapKey(v: any): v is CommandMapKey; | ||
export declare function isPackageJson(obj: any): obj is PackageJson; | ||
export declare function isBowerJson(obj: any): obj is BowerJson; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isPackageJson(o) { | ||
const obj = o; | ||
function isNamespace(obj) { | ||
return obj && | ||
typeof obj.getMetadata === 'function' && | ||
typeof obj.getNamespaces === 'function' && | ||
typeof obj.getCommands === 'function'; | ||
} | ||
exports.isNamespace = isNamespace; | ||
function isCommand(obj) { | ||
return obj && isNamespace(obj.namespace) && | ||
typeof obj.getMetadata === 'function' && | ||
typeof obj.run === 'function' && | ||
typeof obj.validate === 'function'; | ||
} | ||
exports.isCommand = isCommand; | ||
function isCommandMapKey(v) { | ||
return typeof v === 'string' || typeof v === 'symbol'; | ||
} | ||
exports.isCommandMapKey = isCommandMapKey; | ||
function isPackageJson(obj) { | ||
return obj && typeof obj.name === 'string'; | ||
} | ||
exports.isPackageJson = isPackageJson; | ||
function isBowerJson(o) { | ||
const obj = o; | ||
function isBowerJson(obj) { | ||
return obj && typeof obj.name === 'string'; | ||
} | ||
exports.isBowerJson = isBowerJson; | ||
function isValidationErrorArray(e) { | ||
const err = e; | ||
return err && err[0] | ||
&& typeof err[0].message === 'string' | ||
&& typeof err[0].inputName === 'string'; | ||
} | ||
exports.isValidationErrorArray = isValidationErrorArray; |
@@ -1,1 +0,1 @@ | ||
export * from './definitions'; | ||
export * from './lib'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./lib"), exports); |
@@ -1,7 +0,41 @@ | ||
import { CommandData, CommandLineInputs, CommandLineOptions } from '../definitions'; | ||
export declare abstract class Command<T extends CommandData> { | ||
readonly metadata: T; | ||
validate(inputs: CommandLineInputs): Promise<void>; | ||
import { CommandLineInputs, CommandLineOptions, CommandMapGetter, CommandMapKey, CommandMetadata, CommandMetadataInput, CommandMetadataOption, CommandPathItem, HydratedCommandMetadata, ICommand, ICommandMap, INamespace, INamespaceMap, NamespaceLocateResult, NamespaceMapGetter, NamespaceMetadata } from '../definitions'; | ||
export declare abstract class BaseCommand<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> { | ||
namespace: N; | ||
constructor(namespace: N); | ||
abstract getMetadata(): Promise<M>; | ||
abstract run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void>; | ||
validate(argv: CommandLineInputs): Promise<void>; | ||
} | ||
export declare function validateInputs(argv: string[], metadata: CommandData): void; | ||
export declare const CommandMapDefault: symbol; | ||
export declare class BaseCommandMap<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> extends Map<CommandMapKey, string | CommandMapGetter<C, N, M, I, O>> implements ICommandMap<C, N, M, I, O> { | ||
getAliases(): Map<CommandMapKey, CommandMapKey[]>; | ||
resolveAliases(cmdName: string): undefined | CommandMapGetter<C, N, M, I, O>; | ||
} | ||
export declare class BaseNamespaceMap<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> extends Map<string, NamespaceMapGetter<C, N, M, I, O>> implements INamespaceMap<C, N, M, I, O> { | ||
} | ||
export declare abstract class BaseNamespace<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption> implements INamespace<C, N, M, I, O> { | ||
parent: N | undefined; | ||
constructor(parent?: N | undefined); | ||
abstract getMetadata(): Promise<NamespaceMetadata>; | ||
getNamespaces(): Promise<INamespaceMap<C, N, M, I, O>>; | ||
getCommands(): Promise<ICommandMap<C, N, M, I, O>>; | ||
/** | ||
* Recursively inspect inputs supplied to walk down all the tree of | ||
* namespaces available to find the command that we will execute or the | ||
* right-most namespace matched if the command is not found. | ||
*/ | ||
locate(argv: string[]): Promise<NamespaceLocateResult<C, N, M, I, O>>; | ||
/** | ||
* Get all command metadata in a flat structure. | ||
*/ | ||
getCommandMetadataList(): Promise<(M & HydratedCommandMetadata<C, N, M, I, O>)[]>; | ||
} | ||
export declare abstract class Command extends BaseCommand<Command, Namespace, CommandMetadata, CommandMetadataInput, CommandMetadataOption> { | ||
} | ||
export declare abstract class Namespace extends BaseNamespace<Command, Namespace, CommandMetadata, CommandMetadataInput, CommandMetadataOption> { | ||
} | ||
export declare class CommandMap extends BaseCommandMap<Command, Namespace, CommandMetadata, CommandMetadataInput, CommandMetadataOption> { | ||
} | ||
export declare class NamespaceMap extends BaseNamespaceMap<Command, Namespace, CommandMetadata, CommandMetadataInput, CommandMetadataOption> { | ||
} | ||
export declare function generateCommandPath<C extends ICommand<C, N, M, I, O>, N extends INamespace<C, N, M, I, O>, M extends CommandMetadata<I, O>, I extends CommandMetadataInput, O extends CommandMetadataOption>(cmd: C): Promise<CommandPathItem<C, N, M, I, O>[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const lodash = require("lodash"); | ||
const string_1 = require("../utils/string"); | ||
const guards_1 = require("../guards"); | ||
const errors_1 = require("./errors"); | ||
const validators_1 = require("./validators"); | ||
class Command { | ||
validate(inputs) { | ||
class BaseCommand { | ||
constructor(namespace) { | ||
this.namespace = namespace; | ||
} | ||
validate(argv) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
validateInputs(inputs, this.metadata); | ||
const metadata = yield this.getMetadata(); | ||
if (!metadata.inputs) { | ||
return; | ||
} | ||
const errors = []; | ||
for (const i in metadata.inputs) { | ||
const input = metadata.inputs[i]; | ||
if (input.validators && input.validators.length > 0) { | ||
try { | ||
validators_1.validate(argv[i], input.name, [...input.validators]); | ||
} | ||
catch (e) { | ||
if (!(e instanceof errors_1.InputValidationError)) { | ||
throw e; | ||
} | ||
errors.push(e.errors); | ||
} | ||
} | ||
} | ||
if (errors.length > 0) { | ||
throw new errors_1.InputValidationError('Invalid inputs.', lodash.flatten(errors)); | ||
} | ||
}); | ||
} | ||
} | ||
exports.Command = Command; | ||
function validateInputs(argv, metadata) { | ||
if (!metadata.inputs) { | ||
return; | ||
exports.BaseCommand = BaseCommand; | ||
exports.CommandMapDefault = Symbol('default'); | ||
class BaseCommandMap extends Map { | ||
getAliases() { | ||
const aliasmap = new Map(); | ||
// TODO: waiting for https://github.com/Microsoft/TypeScript/issues/18562 | ||
const aliases = [...this.entries()].filter(([, v]) => guards_1.isCommandMapKey(v)); | ||
aliases.forEach(([alias, cmd]) => { | ||
const cmdaliases = aliasmap.get(cmd) || []; | ||
cmdaliases.push(alias); | ||
aliasmap.set(cmd, cmdaliases); | ||
}); | ||
return aliasmap; | ||
} | ||
const errors = []; | ||
for (let i in metadata.inputs) { | ||
const input = metadata.inputs[i]; | ||
if (input.validators && input.validators.length > 0) { | ||
const vnames = input.validators.map(v => v.name); | ||
if (vnames.includes('required')) { | ||
validators_1.validate(argv[i], input.name, [validators_1.validators.required], errors); | ||
} | ||
else { | ||
if (argv[i]) { | ||
validators_1.validate(argv[i], input.name, input.validators, errors); | ||
} | ||
} | ||
resolveAliases(cmdName) { | ||
const r = this.get(cmdName); | ||
if (typeof r !== 'string') { | ||
return r; | ||
} | ||
return this.resolveAliases(r); | ||
} | ||
if (errors.length > 0) { | ||
throw errors; | ||
} | ||
exports.BaseCommandMap = BaseCommandMap; | ||
class BaseNamespaceMap extends Map { | ||
} | ||
exports.BaseNamespaceMap = BaseNamespaceMap; | ||
class BaseNamespace { | ||
constructor(parent = undefined) { | ||
this.parent = parent; | ||
} | ||
// TODO: https://github.com/Microsoft/TypeScript/issues/9659 | ||
getNamespaces() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return new BaseNamespaceMap(); | ||
}); | ||
} | ||
// TODO: https://github.com/Microsoft/TypeScript/issues/9659 | ||
getCommands() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return new BaseCommandMap(); | ||
}); | ||
} | ||
/** | ||
* Recursively inspect inputs supplied to walk down all the tree of | ||
* namespaces available to find the command that we will execute or the | ||
* right-most namespace matched if the command is not found. | ||
*/ | ||
locate(argv) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const _locate = (inputs, parent, path) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const [key] = inputs; | ||
const children = yield parent.getNamespaces(); | ||
const nsgetter = children.get(key); | ||
if (!nsgetter) { | ||
const commands = yield parent.getCommands(); | ||
const cmdgetter = commands.resolveAliases(key); | ||
if (cmdgetter) { | ||
const cmd = yield cmdgetter(); | ||
return { args: inputs.slice(1), obj: cmd, path: [...path, [key, cmd]] }; | ||
} | ||
const defaultcmdgetter = commands.get(exports.CommandMapDefault); | ||
if (defaultcmdgetter && typeof defaultcmdgetter !== 'string') { | ||
const cmd = yield defaultcmdgetter(); | ||
if (path.length > 0) { | ||
// The default command was found via the namespace, so we replace the | ||
// previous path entry (the namespace which contains this default | ||
// command) with the command itself. | ||
path[path.length - 1][1] = cmd; | ||
} | ||
return { args: inputs, obj: cmd, path }; | ||
} | ||
return { args: inputs, obj: parent, path }; | ||
} | ||
const child = yield nsgetter(); | ||
return _locate(inputs.slice(1), child, [...path, [key, child]]); | ||
}); | ||
const metadata = yield this.getMetadata(); | ||
// TODO: typescript complains about `this`. Calling this method on | ||
// BaseNamespace would be unsafe if the class weren't abstract. Typescript | ||
// bug? I may be wrong. | ||
return _locate(argv, this, [[metadata.name, this]]); | ||
}); | ||
} | ||
/** | ||
* Get all command metadata in a flat structure. | ||
*/ | ||
getCommandMetadataList() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const _getCommandMetadataList = (parent, path) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const commandList = []; | ||
const commands = yield parent.getCommands(); | ||
const nsAliases = commands.getAliases(); | ||
// Gather all commands for a namespace and turn them into simple key value | ||
// objects. Also keep a record of the namespace path. | ||
yield Promise.all([...commands.entries()].map(([k, cmdgetter]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (typeof cmdgetter === 'string') { | ||
return; | ||
} | ||
const command = yield cmdgetter(); | ||
const aliases = nsAliases.get(k) || []; | ||
const metadata = yield command.getMetadata(); | ||
const cmdPath = [...path]; | ||
if (typeof k === 'string') { | ||
cmdPath.push([k, command]); | ||
} | ||
// TODO: can't use spread: https://github.com/Microsoft/TypeScript/pull/13288 | ||
const result = lodash.assign({}, metadata, { command, namespace: parent, aliases, path: cmdPath }); | ||
commandList.push(result); | ||
}))); | ||
commandList.sort((a, b) => string_1.strcmp(a.name, b.name)); | ||
let namespacedCommandList = []; | ||
const children = yield parent.getNamespaces(); | ||
// If this namespace has children then get their commands | ||
if (children.size > 0) { | ||
yield Promise.all([...children.entries()].map(([k, nsgetter]) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const ns = yield nsgetter(); | ||
const cmds = yield _getCommandMetadataList(ns, [...path, [k, ns]]); | ||
namespacedCommandList = namespacedCommandList.concat(cmds); | ||
}))); | ||
} | ||
return commandList.concat(namespacedCommandList); | ||
}); | ||
// TODO: typescript complains about `this`. Calling this method on | ||
// BaseNamespace would be unsafe if the class weren't abstract. Typescript | ||
// bug? I may be wrong. | ||
return _getCommandMetadataList(this, []); | ||
}); | ||
} | ||
} | ||
exports.validateInputs = validateInputs; | ||
exports.BaseNamespace = BaseNamespace; | ||
class Command extends BaseCommand { | ||
} | ||
exports.Command = Command; | ||
class Namespace extends BaseNamespace { | ||
} | ||
exports.Namespace = Namespace; | ||
class CommandMap extends BaseCommandMap { | ||
} | ||
exports.CommandMap = CommandMap; | ||
class NamespaceMap extends BaseNamespaceMap { | ||
} | ||
exports.NamespaceMap = NamespaceMap; | ||
function generateCommandPath(cmd) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const ns = cmd.namespace; | ||
const cmdmeta = yield cmd.getMetadata(); | ||
const _cmdpath = (namespace) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const nsmeta = yield namespace.getMetadata(); | ||
const nspath = [nsmeta.name, namespace]; | ||
if (!namespace.parent) { | ||
return [nspath]; | ||
} | ||
return [...(yield _cmdpath(namespace.parent)), nspath]; | ||
}); | ||
return [...(yield _cmdpath(ns)), [cmdmeta.name, cmd]]; | ||
}); | ||
} | ||
exports.generateCommandPath = generateCommandPath; |
@@ -0,2 +1,6 @@ | ||
export * from '../definitions'; | ||
export * from './command'; | ||
export * from './errors'; | ||
export * from './executor'; | ||
export * from './options'; | ||
export * from './validators'; |
@@ -5,2 +5,5 @@ "use strict"; | ||
tslib_1.__exportStar(require("./command"), exports); | ||
tslib_1.__exportStar(require("./errors"), exports); | ||
tslib_1.__exportStar(require("./executor"), exports); | ||
tslib_1.__exportStar(require("./options"), exports); | ||
tslib_1.__exportStar(require("./validators"), exports); |
@@ -1,3 +0,3 @@ | ||
import { ValidationError, Validator, Validators } from '../definitions'; | ||
export declare function validate(input: string, key: string, validators: Validator[], errors?: ValidationError[]): void; | ||
import { Validator, Validators } from '../definitions'; | ||
export declare function validate(input: string, key: string, validators: Validator[]): void; | ||
export declare const validators: Validators; | ||
@@ -4,0 +4,0 @@ export declare function contains(values: (string | undefined)[], {caseSensitive}: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk_1 = require("chalk"); | ||
const errors_1 = require("./errors"); | ||
const string_1 = require("../utils/string"); | ||
function validate(input, key, validators, errors) { | ||
const throwErrors = typeof errors === 'undefined'; | ||
if (!errors) { | ||
errors = []; | ||
} | ||
for (let validator of validators) { | ||
const r = validator(input, key); | ||
if (r !== true) { | ||
errors.push({ message: r, inputName: key }); | ||
function validate(input, key, validators) { | ||
const errors = []; | ||
for (const validator of validators) { | ||
const message = validator(input, key); | ||
if (message !== true) { | ||
errors.push({ key, message, validator }); | ||
} | ||
} | ||
if (throwErrors && errors.length > 0) { | ||
throw errors; | ||
if (errors.length > 0) { | ||
throw new errors_1.InputValidationError('Invalid inputs.', errors); | ||
} | ||
@@ -44,2 +42,13 @@ } | ||
}, | ||
url(input, key) { | ||
if (!string_1.isValidURL(input)) { | ||
if (key) { | ||
return `${chalk_1.default.green(key)} is an invalid URL.`; | ||
} | ||
else { | ||
return 'Invalid URL.'; | ||
} | ||
} | ||
return true; | ||
}, | ||
numeric(input, key) { | ||
@@ -68,7 +77,8 @@ if (isNaN(Number(input))) { | ||
const mustBe = (strValues.length !== values.length ? 'unset or one of' : 'one of') + ': ' + strValues.map(v => chalk_1.default.green(v)).join(', '); | ||
const fmtPretty = (v) => typeof v === 'undefined' ? 'unset' : (v === '' ? 'empty' : chalk_1.default.green(v)); | ||
if (key) { | ||
return `${chalk_1.default.green(key)} must be ${mustBe} (not ${typeof input === 'undefined' ? 'unset' : chalk_1.default.green(input)})`; | ||
return `${chalk_1.default.green(key)} must be ${mustBe} (not ${fmtPretty(input)})`; | ||
} | ||
else { | ||
return `Must be ${mustBe} (not ${typeof input === 'undefined' ? 'unset' : chalk_1.default.green(input)})`; | ||
return `Must be ${mustBe} (not ${fmtPretty(input)})`; | ||
} | ||
@@ -75,0 +85,0 @@ } |
{ | ||
"name": "@ionic/cli-framework", | ||
"version": "0.2.0-alpha.fefc39d3", | ||
"version": "1.0.0-alpha.0303b03e", | ||
"description": "The foundation framework of the Ionic CLI", | ||
"homepage": "http://ionicframework.com/", | ||
"author": "Ionic Team <hi@ionic.io> (http://ionic.io) ", | ||
"homepage": "https://ionicframework.com/", | ||
"author": "Ionic Team <hi@ionic.io> (https://ionicframework.com) ", | ||
"main": "./index.js", | ||
@@ -14,3 +14,3 @@ "types": "./index.d.ts", | ||
"clean": "rm -rf index.* definitions.* guards.* ./utils", | ||
"lint": "tslint --config ../../../tslint.js --project tsconfig.json --type-check", | ||
"lint": "tslint --config ../../../tslint.js --project tsconfig.json", | ||
"build": "npm run clean && tsc", | ||
@@ -39,14 +39,25 @@ "watch": "tsc -w", | ||
"chalk": "^2.3.0", | ||
"dargs": "^5.1.0", | ||
"debug": "^3.1.0", | ||
"lodash": "^4.17.4", | ||
"minimist": "^1.2.0", | ||
"ncp": "^2.0.0", | ||
"rimraf": "^2.6.2", | ||
"slice-ansi": "^1.0.0", | ||
"string-width": "^2.1.1", | ||
"strip-ansi": "^4.0.0", | ||
"superagent": "^3.8.0", | ||
"tslib": "^1.8.0" | ||
"superagent": "^3.8.2", | ||
"tslib": "^1.8.1", | ||
"wrap-ansi": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/dargs": "^5.1.0", | ||
"@types/debug": "0.0.30", | ||
"@types/lodash": "^4.14.92", | ||
"@types/minimist": "^1.2.0", | ||
"@types/ncp": "^2.0.1", | ||
"@types/rimraf": "^2.0.2", | ||
"@types/strip-ansi": "^3.0.0", | ||
"@types/superagent": "^3.5.6" | ||
} | ||
} |
@@ -52,3 +52,3 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return exports.fsWriteFile(filePath, JSON.stringify(json, null, 2) + '\n', options); | ||
return exports.fsWriteFile(filePath, JSON.stringify(json, undefined, 2) + '\n', options); | ||
}); | ||
@@ -77,3 +77,3 @@ } | ||
const dirs = dirnames.map((v, i) => path.resolve(pathObj.root, ...dirnames.slice(0, i), v)); | ||
for (let dir of dirs) { | ||
for (const dir of dirs) { | ||
try { | ||
@@ -181,6 +181,6 @@ yield exports.fsMkdir(dir, mode); | ||
exports.removeDirectory = removeDirectory; | ||
function copyFile(fileName, target, mode = 0o777) { | ||
function copyFile(fileName, target, mode = 0o666) { | ||
return new Promise((resolve, reject) => { | ||
const rs = fs.createReadStream(fileName); | ||
const ws = fs.createWriteStream(target, { mode: mode }); | ||
const ws = fs.createWriteStream(target, { mode }); | ||
rs.on('error', reject); | ||
@@ -225,9 +225,9 @@ ws.on('error', reject); | ||
.map((segment, index, array) => { | ||
let pathSegments = array.slice(0, (array.length - index)); | ||
const pathSegments = array.slice(0, (array.length - index)); | ||
return dirInfo.root + path.join(...pathSegments); | ||
}); | ||
for (let i = 0; i < directoriesToCheck.length; i++) { | ||
const results = yield exports.fsReadDir(directoriesToCheck[i]); | ||
for (const d of directoriesToCheck) { | ||
const results = yield exports.fsReadDir(d); | ||
if (results.includes(file)) { | ||
return directoriesToCheck[i]; | ||
return d; | ||
} | ||
@@ -234,0 +234,0 @@ } |
@@ -0,3 +1,6 @@ | ||
export declare const EMAIL_REGEX: RegExp; | ||
export declare const URL_REGEX: RegExp; | ||
export declare function isValidEmail(email?: any): boolean; | ||
export declare function isValidURL(url?: any): boolean; | ||
export declare function strcmp(a: string | undefined, b: string | undefined): number; | ||
export declare function str2num(value: any, defaultValue?: number): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
exports.EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
exports.URL_REGEX = /^[\S]+:[\S]+$/; | ||
function isValidEmail(email) { | ||
@@ -8,5 +9,12 @@ if (typeof email !== 'string') { | ||
} | ||
return EMAIL_REGEX.test(email); | ||
return exports.EMAIL_REGEX.test(email); | ||
} | ||
exports.isValidEmail = isValidEmail; | ||
function isValidURL(url) { | ||
if (typeof url !== 'string') { | ||
return false; | ||
} | ||
return exports.URL_REGEX.test(url); | ||
} | ||
exports.isValidURL = isValidURL; | ||
function strcmp(a, b) { | ||
@@ -13,0 +21,0 @@ if (!a) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59624
35
1341
13
8
+ Addeddargs@^5.1.0
+ Addeddebug@^3.1.0
+ Addedlodash@^4.17.4
+ Addedminimist@^1.2.0
+ Addedslice-ansi@^1.0.0
+ Addedstring-width@^2.1.1
+ Addedwrap-ansi@^3.0.1
+ Addeddargs@5.1.0(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedslice-ansi@1.0.0(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedwrap-ansi@3.0.1(transitive)
Updatedsuperagent@^3.8.2
Updatedtslib@^1.8.1