@fluent/console
Advanced tools
Comparing version 1.0.5 to 1.0.8
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const command_descriptor_1 = require("./command-descriptor"); | ||
class CommandCollection extends Set { | ||
addCommand(commandType, commandInstance) { | ||
if (!commandType.prototype.__fluent_command_template) { | ||
throw new Error(`Command ${commandType.name} should be implemented with @Command(string) decorator`); | ||
} | ||
let commandDescriptor; | ||
if (commandInstance) { | ||
commandDescriptor = new command_descriptor_1.CommandDescriptor(commandType.prototype.__fluent_command_template, commandType, commandInstance); | ||
} | ||
else { | ||
commandDescriptor = new command_descriptor_1.CommandDescriptor(commandType.prototype.__fluent_command_template, commandType); | ||
} | ||
return this.add(commandDescriptor); | ||
} | ||
} | ||
exports.CommandCollection = CommandCollection; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class CommandContext { | ||
constructor() { | ||
this.arguments = new Map(); | ||
this.options = new Map(); | ||
} | ||
} | ||
exports.CommandContext = CommandContext; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const command_parser_1 = require("./command-parser"); | ||
const command_token_1 = require("./command-token"); | ||
const argument_token_1 = require("./argument-token"); | ||
const option_token_1 = require("./option-token"); | ||
class CommandDescriptor { | ||
constructor(signature, commandHandler, instance) { | ||
this.signature = signature instanceof Array ? signature.join(' ') : signature; | ||
this.handler = commandHandler; | ||
if (instance) { | ||
this.instance = instance; | ||
constructor(commandTemplate, commandType, commandInstance) { | ||
this.commandTemplate = commandTemplate instanceof Array ? commandTemplate.join(' ') : commandTemplate; | ||
this.commandType = commandType; | ||
if (typeof this.commandTemplate !== 'string' || this.commandTemplate.trim().length <= 0) { | ||
throw new Error('Command template is empty.'); | ||
} | ||
const [args, opts] = command_parser_1.CommandParser.parse(this.signature); | ||
this.arguments = new Set(args); | ||
this.options = new Set(opts); | ||
if (commandInstance) { | ||
this.commandInstance = commandInstance; | ||
} | ||
const commandTokenCollection = command_parser_1.CommandParser.parse(this.commandTemplate); | ||
const commandTokens = Array.from(commandTokenCollection) | ||
.filter(token => token.constructor === command_token_1.CommandToken); | ||
if (commandTokens.length < 1) { | ||
throw new Error(`Command name is missed in '${this.commandTemplate}'.`); | ||
} | ||
if (commandTokens.length > 1) { | ||
const commandNames = commandTokens.map(commandToken => commandToken.name).join(', '); | ||
throw new Error(`Command name is not single. Try use one of [${commandNames}].`); | ||
} | ||
this.commandToken = commandTokens[0]; | ||
const argumentNames = []; | ||
const argumentTokens = Array.from(commandTokenCollection) | ||
.filter(token => token.constructor === argument_token_1.ArgumentToken); | ||
this.argumentTokenCollection = new Set(argumentTokens); | ||
if (argumentTokens.length > 0) { | ||
let lastArgumentToken = undefined; | ||
let arrayArgumentExists = false; | ||
for (const argumentToken of argumentTokens) { | ||
if (argumentNames.indexOf(argumentToken.name) !== -1) { | ||
throw new Error(`Argument '${argumentToken.name}' have duplicates.`); | ||
} | ||
else { | ||
argumentNames.push(argumentToken.name); | ||
} | ||
if (argumentToken.isArray) { | ||
if (arrayArgumentExists) { | ||
throw new Error(`Command '${this.commandTemplate}' cannot have more than one array arguments.`); | ||
} | ||
arrayArgumentExists = true; | ||
} | ||
if (!lastArgumentToken) { | ||
lastArgumentToken = argumentToken; | ||
} | ||
else { | ||
if (lastArgumentToken.isOptional && argumentToken.isRequired) { | ||
throw new Error(`Argument '${lastArgumentToken.name}'` | ||
+ ` is optional and should be after all required arguments.`); | ||
} | ||
if (lastArgumentToken.isArray && !argumentToken.isArray) { | ||
throw new Error(`Argument '${lastArgumentToken.name}'` | ||
+ ` is array and should be after all arguments.`); | ||
} | ||
} | ||
} | ||
} | ||
const optionTokens = Array.from(commandTokenCollection) | ||
.filter(token => token.constructor === option_token_1.OptionToken); | ||
this.optionTokenCollection = new Set(optionTokens); | ||
const optionNames = []; | ||
for (const optionToken of optionTokens) { | ||
for (const [optionFlag, optionsName] of optionToken.nameValues) { | ||
if (argumentNames.indexOf(optionsName) !== -1) { | ||
throw new Error(`Option flag '${optionFlag}' have the same name as argument. Try to change it.`); | ||
} | ||
if (optionNames.indexOf(optionsName) !== -1) { | ||
throw new Error(`Option flag '${optionFlag}' have duplicates of name.`); | ||
} | ||
else { | ||
optionNames.push(optionsName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
exports.CommandDescriptor = CommandDescriptor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const argument_token_1 = require("./argument-token"); | ||
const command_token_1 = require("./command-token"); | ||
const option_token_1 = require("./option-token"); | ||
class CommandParser { | ||
static parse(signature) { | ||
const tokens = signature.split(' '); | ||
const args = []; | ||
const opts = []; | ||
for (const token of tokens) { | ||
const matches = token.match(/^-{1,}(.*)$/); | ||
if (matches !== null) { | ||
opts.push(matches[1]); | ||
static parse(template) { | ||
template = this.normalizeTemplate(template); | ||
const tokenTemplates = template.match(/(\{.+?\}|\S+)/g); | ||
if (tokenTemplates === null) { | ||
throw new Error(`Command tokenization failed. Incorrect template '${template.length > 0 ? template : '[empty]'}'.`); | ||
} | ||
for (const tokenTemplate of tokenTemplates) { | ||
if (!this.isValidToken(tokenTemplate)) { | ||
throw new Error(`Command tokenization failed. Incorrect token '${tokenTemplate}'`); | ||
} | ||
} | ||
const commandTokens = tokenTemplates.map(tokenTemplate => this.parseToken(tokenTemplate)); | ||
return new Set(commandTokens); | ||
} | ||
static normalizeTemplate(template) { | ||
return template.trim().replace(/\s+/g, ' '); | ||
} | ||
static parseToken(tokenTemplate) { | ||
tokenTemplate = this.normalizeTokenTemplate(tokenTemplate); | ||
if (/^[\w\:]+$/.test(tokenTemplate)) { | ||
const commandToken = new command_token_1.CommandToken(); | ||
commandToken.name = tokenTemplate; | ||
return commandToken; | ||
} | ||
tokenTemplate = tokenTemplate.substr(1, tokenTemplate.length - 2); | ||
if (tokenTemplate.startsWith('-') || tokenTemplate.startsWith('-')) { | ||
const optionToken = new option_token_1.OptionToken(); | ||
if (tokenTemplate.endsWith('=')) { | ||
tokenTemplate = tokenTemplate.substr(0, tokenTemplate.length - 1); | ||
} | ||
else if (tokenTemplate.endsWith('=*')) { | ||
tokenTemplate = tokenTemplate.substr(0, tokenTemplate.length - 2); | ||
optionToken.isArray = true; | ||
optionToken.defaultValue = []; | ||
} | ||
else if (tokenTemplate.includes('=')) { | ||
[tokenTemplate, optionToken.defaultValue] = tokenTemplate.split('='); | ||
} | ||
else { | ||
args.push(token); | ||
optionToken.isLogical = true; | ||
optionToken.defaultValue = false; | ||
} | ||
const flags = tokenTemplate.split('|'); | ||
optionToken.nameValues = new Map(flags.map(flag => [flag, flag.replace(/^\-+/, '')])); | ||
return optionToken; | ||
} | ||
return [args, opts]; | ||
const argumentToken = new argument_token_1.ArgumentToken(); | ||
if (tokenTemplate.endsWith('?')) { | ||
argumentToken.isOptional = true; | ||
argumentToken.name = tokenTemplate.substr(0, tokenTemplate.length - 1); | ||
} | ||
else if (tokenTemplate.endsWith('*')) { | ||
argumentToken.name = tokenTemplate.substr(0, tokenTemplate.length - 1); | ||
argumentToken.isOptional = true; | ||
argumentToken.defaultValue = []; | ||
} | ||
else if (tokenTemplate.endsWith('=')) { | ||
argumentToken.isRequired = true; | ||
argumentToken.name = tokenTemplate.substr(0, tokenTemplate.length - 1); | ||
} | ||
else if (tokenTemplate.includes('=')) { | ||
argumentToken.isOptional = true; | ||
[argumentToken.name, argumentToken.defaultValue] = tokenTemplate.split('='); | ||
} | ||
else { | ||
argumentToken.isRequired = true; | ||
argumentToken.name = tokenTemplate; | ||
} | ||
return argumentToken; | ||
} | ||
static isValidToken(tokenTemplate) { | ||
tokenTemplate = this.normalizeTokenTemplate(tokenTemplate); | ||
const patterns = [ | ||
/^[\w\:]+$/, | ||
/^\{[\w]+(\=.+|\?|\*|)\}$/, | ||
/^\{\-{1,2}[\w]+(\|\-{1,2}[\w]+)*(\=|\=.+|\=\*|)\}$/ | ||
]; | ||
for (const pattern of patterns) { | ||
if (pattern.test(tokenTemplate)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
static normalizeTokenTemplate(tokenTemplate) { | ||
return tokenTemplate.replace(/\s/g, ''); | ||
} | ||
} | ||
exports.CommandParser = CommandParser; |
@@ -6,10 +6,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./application")); | ||
__export(require("./application-builder")); | ||
__export(require("./command")); | ||
__export(require("./decorators")); | ||
__export(require("./command-context")); | ||
__export(require("./command-descriptor")); | ||
__export(require("./command-handler")); | ||
__export(require("./command-provider")); | ||
__export(require("./command-collection")); | ||
__export(require("./command")); | ||
__export(require("./inline-command")); | ||
__export(require("./decorators")); | ||
__export(require("./prompt")); | ||
__export(require("./input-command")); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fileSystem = require("fs"); | ||
class InputCommand { | ||
constructor(...argv) { | ||
if (argv.length < 2) { | ||
throw new Error(`Input command received no enough arguments. Try to use [interpreter, scriptPath, ...arguments].`); | ||
} | ||
const [interpreter, scriptPath, ...tokens] = argv; | ||
const args = []; | ||
const opts = []; | ||
fileSystem.lstatSync(scriptPath); | ||
const argumentCollection = new Set(); | ||
const optionValues = new Map(); | ||
for (const token of tokens) { | ||
const matches = token.match(/^-{1,}(.*)$/); | ||
if (matches !== null) { | ||
const [name, value] = matches[1].split('='); | ||
opts.push([name, value ? value : true]); | ||
if (/^\-+.*$/.test(token)) { | ||
const [optionKey, optionValue] = token.split('='); | ||
if (optionValues.has(optionKey)) { | ||
const valueBefore = optionValues.get(optionKey); | ||
if (valueBefore instanceof Array) { | ||
valueBefore.push(optionValue ? optionValue : undefined); | ||
} | ||
else { | ||
const valueAfter = [valueBefore, optionValue]; | ||
optionValues.set(optionKey, valueAfter); | ||
} | ||
} | ||
else { | ||
optionValues.set(optionKey, optionValue ? optionValue : undefined); | ||
} | ||
} | ||
else { | ||
args.push(token); | ||
argumentCollection.add(token); | ||
} | ||
@@ -20,9 +36,6 @@ } | ||
this.scriptPath = scriptPath; | ||
this.arguments = new Set(args); | ||
this.options = new Map(opts); | ||
this.argumentCollection = argumentCollection; | ||
this.optionValues = optionValues; | ||
} | ||
match(commandDescriptor) { | ||
return Array.from(this.arguments).join(' ') === Array.from(commandDescriptor.arguments).join(' '); | ||
} | ||
} | ||
exports.InputCommand = InputCommand; |
{ | ||
"name": "@fluent/console", | ||
"version": "1.0.5", | ||
"version": "1.0.8", | ||
"description": "Fluent - console component", | ||
"main": "build/index.js", | ||
"typings": "build/index.d.ts", | ||
"typings": "types/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
"prepublishOnly": "npm run build", | ||
"pretest": "npm run-script build", | ||
"test": "mocha --exit build/**/*.spec.js" | ||
}, | ||
@@ -22,13 +24,16 @@ "keywords": [ | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.12" | ||
"reflect-metadata": "0.1.*" | ||
}, | ||
"peerDependencies": { | ||
"@fluent/core": "^1.0.5", | ||
"@fluent/di": "^1.0.5", | ||
"@fluent/logging": "^1.0.5" | ||
"@fluent/di": "1.0.8", | ||
"@fluent/reflect": "1.0.8" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.2", | ||
"@types/node": "^9.3.0", | ||
"chai": "^4.1.2", | ||
"@types/mocha": "^2.2.47", | ||
"mocha": "^5.0.0", | ||
"typescript": "2.6.*" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
50048
3
37
955
1
150
6
1
- Removed@fluent/console@1.0.8(transitive)
- Removed@fluent/core@1.0.8(transitive)
- Removed@fluent/logging@1.0.8(transitive)
- Removedasync@2.6.4(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedisstream@0.1.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedwinston@2.4.7(transitive)
Updatedreflect-metadata@0.1.*