Comparing version 2.0.0 to 2.1.0
@@ -17,2 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = void 0; | ||
var yargs_parser_1 = __importDefault(require("yargs-parser")); | ||
@@ -112,4 +113,4 @@ var forEach_1 = __importDefault(require("lodash/forEach")); | ||
var _a; | ||
var _b; | ||
if (cmdLine === void 0) { cmdLine = ""; } | ||
var _b; | ||
var parsed = yargs_parser_1.default.detailed(cmdArgs, appCmd.argsParserOpts); | ||
@@ -116,0 +117,0 @@ if (parsed.error) { |
@@ -49,2 +49,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findCommand = void 0; | ||
var forEach_1 = __importDefault(require("lodash/forEach")); | ||
@@ -51,0 +52,0 @@ var trim_1 = __importDefault(require("lodash/trim")); |
import { Prompt } from "makitso-prompt"; | ||
import { ContextSchema, Defs } from "../types"; | ||
declare type Args = { | ||
declare type StartArgs = { | ||
context: ContextSchema; | ||
commands: Defs; | ||
prompt: Prompt; | ||
cmdLine?: string; | ||
}; | ||
@@ -11,8 +12,8 @@ /** | ||
* | ||
* @param {Object} arg0 - | ||
* @param {Object} arg0.context - An instance of context | ||
* @param {Object} arg0.commands - app commands | ||
* @param {Object} args - | ||
* @param {Object} args.context - An instance of context | ||
* @param {Object} args.commands - app commands | ||
* @returns {void} | ||
*/ | ||
export declare function start(arg0: Args): Promise<void | Error>; | ||
export declare function start(args: StartArgs): Promise<void | Error>; | ||
export {}; |
@@ -46,2 +46,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.start = void 0; | ||
var makitso_prompt_1 = require("makitso-prompt"); | ||
@@ -55,14 +56,39 @@ var debug_1 = require("../debug"); | ||
var keypress_validate_1 = require("./keypress-validate"); | ||
function runCommandLine(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context, commands, cmdLine, cmd, appCmd, cmdArgs, input; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
context = args.context, commands = args.commands, cmdLine = args.cmdLine; | ||
debug_1.debug({ cmdLine: cmdLine }); | ||
return [4 /*yield*/, find_1.findCommand({ cmdLine: cmdLine, commands: commands })]; | ||
case 1: | ||
cmd = _a.sent(); | ||
if (!cmd) return [3 /*break*/, 3]; | ||
appCmd = cmd.appCmd, cmdArgs = cmd.cmdArgs; | ||
input = args_1.parse({ appCmd: appCmd, cmdArgs: cmdArgs }); | ||
debug_1.debug({ appCmd: appCmd, cmdArgs: cmdArgs, input: input }); | ||
if (!appCmd.action) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, appCmd.action({ commands: commands, context: context, command: appCmd, input: input })]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Prompt the user for a command and run it | ||
* | ||
* @param {Object} arg0 - | ||
* @param {Object} arg0.context - An instance of context | ||
* @param {Object} arg0.commands - app commands | ||
* @param {Object} arg0.options - app options | ||
* @param {Function|Array} [arg0.complete=[]] - prompt autocomplete | ||
* @param {Function} [arg0.validate] - prompt validation | ||
* @param {Object} args - | ||
* @param {Object} args.context - An instance of context | ||
* @param {Object} args.commands - app commands | ||
* @param {Object} args.options - app options | ||
* @param {Function|Array} [args.complete=[]] - prompt autocomplete | ||
* @param {Function} [args.validate] - prompt validation | ||
* @returns {void} | ||
*/ | ||
function promptAndRun(arg0) { | ||
function promptAndRun(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -73,3 +99,3 @@ var context, commands, prompt, cmdLine, _a, cmd, appCmd, cmdArgs, input, error_1; | ||
case 0: | ||
context = arg0.context, commands = arg0.commands, prompt = arg0.prompt; | ||
context = args.context, commands = args.commands, prompt = args.prompt; | ||
_b.label = 1; | ||
@@ -95,3 +121,3 @@ case 1: | ||
_b.label = 5; | ||
case 5: return [2 /*return*/, promptAndRun(arg0)]; | ||
case 5: return [2 /*return*/, promptAndRun(args)]; | ||
case 6: | ||
@@ -112,12 +138,12 @@ error_1 = _b.sent(); | ||
var keyPressParser = { | ||
keyPress: commandInfo | ||
keyPress: commandInfo, | ||
}; | ||
var keyPressAutocomplete = { | ||
keyPress: keypress_autocomplete_1.Autocomplete({ commandInfo: commandInfo }) | ||
keyPress: keypress_autocomplete_1.Autocomplete({ commandInfo: commandInfo }), | ||
}; | ||
var keyPressAutoHelp = { | ||
keyPress: keypress_autohelp_1.AutoHelp() | ||
keyPress: keypress_autohelp_1.AutoHelp(), | ||
}; | ||
var keyPressValidator = { | ||
keyPress: keypress_validate_1.keyPressValidate() | ||
keyPress: keypress_validate_1.keyPressValidate(), | ||
}; | ||
@@ -134,3 +160,3 @@ Object.assign(prompt, { | ||
}); | ||
} | ||
}, | ||
} | ||
@@ -142,4 +168,4 @@ ], prompt.keyPressers, [ | ||
keyPressAutoHelp, | ||
keyPressValidator | ||
]) | ||
keyPressValidator, | ||
]), | ||
}); | ||
@@ -151,12 +177,15 @@ return prompt; | ||
* | ||
* @param {Object} arg0 - | ||
* @param {Object} arg0.context - An instance of context | ||
* @param {Object} arg0.commands - app commands | ||
* @param {Object} args - | ||
* @param {Object} args.context - An instance of context | ||
* @param {Object} args.commands - app commands | ||
* @returns {void} | ||
*/ | ||
function start(arg0) { | ||
function start(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context, commands, prompt; | ||
var context, commands, prompt, cmdLine; | ||
return __generator(this, function (_a) { | ||
context = arg0.context, commands = arg0.commands, prompt = arg0.prompt; | ||
context = args.context, commands = args.commands, prompt = args.prompt, cmdLine = args.cmdLine; | ||
if (cmdLine) { | ||
return [2 /*return*/, runCommandLine({ context: context, commands: commands, cmdLine: cmdLine })]; | ||
} | ||
initCommandPrompt({ context: context, commands: commands, prompt: prompt }); | ||
@@ -163,0 +192,0 @@ process.on("SIGINT", function () { |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Autocomplete = void 0; | ||
var every_1 = __importDefault(require("lodash/every")); | ||
@@ -44,0 +45,0 @@ var debug_1 = require("../debug"); |
@@ -39,2 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AutoHelp = void 0; | ||
function AutoHelp() { | ||
@@ -41,0 +42,0 @@ return function keyPress(state) { |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.keyPressCommandInfo = void 0; | ||
var filter_1 = __importDefault(require("lodash/filter")); | ||
@@ -85,3 +86,3 @@ var args_1 = require("./args"); | ||
command: appCmd, | ||
input: info.input | ||
input: info.input, | ||
})]; | ||
@@ -107,3 +108,3 @@ case 3: | ||
command: appCmd, | ||
input: info.input | ||
input: info.input, | ||
})]; | ||
@@ -110,0 +111,0 @@ case 7: |
@@ -46,2 +46,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.keyPressValidate = void 0; | ||
var map_1 = __importDefault(require("lodash/map")); | ||
@@ -48,0 +49,0 @@ var get_1 = __importDefault(require("lodash/get")); |
@@ -60,2 +60,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Context = void 0; | ||
var app_error_1 = __importDefault(require("@lecstor/app-error")); | ||
@@ -62,0 +63,0 @@ var get_1 = __importDefault(require("lodash/get")); |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.keyPressAutoComplete = void 0; | ||
var filter_1 = __importDefault(require("lodash/filter")); | ||
@@ -44,0 +45,0 @@ function keyPressAutoComplete(choices) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.debug = void 0; | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
@@ -12,2 +13,3 @@ var debug; | ||
exports.debug = debug = function () { | ||
var _a; | ||
var stuff = []; | ||
@@ -17,3 +19,2 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
} | ||
var _a; | ||
if (stuff.length === 1) { | ||
@@ -20,0 +21,0 @@ stuff = stuff[0]; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./makitso")); | ||
__export(require("./plugins")); | ||
__exportStar(require("./makitso"), exports); | ||
__exportStar(require("./plugins"), exports); | ||
__exportStar(require("./types"), exports); |
@@ -22,4 +22,5 @@ import { Prompt } from "makitso-prompt"; | ||
}; | ||
cmdLine: string; | ||
}; | ||
export declare function Makitso(args: MakitsoArgs): Promise<void | Error>; | ||
export {}; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Makitso = void 0; | ||
var merge_1 = __importDefault(require("lodash/merge")); | ||
@@ -38,3 +39,3 @@ var flatten_1 = __importDefault(require("lodash/flatten")); | ||
isOptional: Boolean(isOptional), | ||
string: arg | ||
string: arg, | ||
}; | ||
@@ -54,3 +55,3 @@ } | ||
description: "", | ||
parseOpt: { boolean: false } | ||
parseOpt: { boolean: false }, | ||
}; | ||
@@ -212,3 +213,3 @@ var option = optBits.reduce(function (result, val) { | ||
function Makitso(args) { | ||
var commandPrompt = args.commandPrompt, plugins = args.plugins; | ||
var commandPrompt = args.commandPrompt, plugins = args.plugins, cmdLine = args.cmdLine; | ||
var prompt; | ||
@@ -229,5 +230,5 @@ if (commandPrompt) { | ||
var context = context_1.Context({ schema: schema, stores: stores, commands: commands }); | ||
return command_1.start({ context: context, commands: commands, prompt: prompt }); | ||
return command_1.start({ context: context, commands: commands, prompt: prompt, cmdLine: cmdLine }); | ||
}); | ||
} | ||
exports.Makitso = Makitso; |
@@ -14,2 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = void 0; | ||
var help_1 = require("./help"); | ||
@@ -16,0 +17,0 @@ var help = help_1.plugin(); |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = void 0; | ||
var forEach_1 = __importDefault(require("lodash/forEach")); | ||
@@ -44,0 +45,0 @@ var find_1 = require("../command/find"); |
@@ -39,2 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = void 0; | ||
var commands_1 = require("./commands"); | ||
@@ -41,0 +42,0 @@ var stores_1 = require("./stores"); |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = exports.FileStore = void 0; | ||
var fs_1 = __importDefault(require("fs")); | ||
@@ -44,0 +45,0 @@ var util_1 = require("util"); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
} | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -39,5 +49,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = void 0; | ||
var file_store_1 = require("./file-store"); | ||
var keychain_store_1 = require("./keychain-store"); | ||
var memory_store_1 = require("./memory-store"); | ||
__exportStar(require("./types"), exports); | ||
function plugin(args) { | ||
@@ -44,0 +56,0 @@ return __awaiter(this, void 0, void 0, function () { |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = exports.KeychainStore = void 0; | ||
var keytar_1 = __importDefault(require("keytar")); | ||
@@ -44,0 +45,0 @@ /** |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.plugin = exports.MemoryStore = void 0; | ||
var get_1 = __importDefault(require("lodash/get")); | ||
@@ -44,0 +45,0 @@ var set_1 = __importDefault(require("lodash/set")); |
@@ -15,2 +15,22 @@ "use strict"; | ||
type RunCommandLineArgs = { | ||
context: ContextSchema; | ||
commands: Defs; | ||
cmdLine: string; | ||
}; | ||
async function runCommandLine(args: RunCommandLineArgs): Promise<Error | void> { | ||
const { context, commands, cmdLine } = args; | ||
debug({ cmdLine }); | ||
const cmd = await findCommand({ cmdLine, commands }); | ||
if (cmd) { | ||
const { appCmd, cmdArgs } = cmd; | ||
const input = parse({ appCmd, cmdArgs }); | ||
debug({ appCmd, cmdArgs, input }); | ||
if (appCmd.action) { | ||
await appCmd.action({ commands, context, command: appCmd, input }); | ||
} | ||
} | ||
} | ||
type Args = { | ||
@@ -25,12 +45,12 @@ context: ContextSchema; | ||
* | ||
* @param {Object} arg0 - | ||
* @param {Object} arg0.context - An instance of context | ||
* @param {Object} arg0.commands - app commands | ||
* @param {Object} arg0.options - app options | ||
* @param {Function|Array} [arg0.complete=[]] - prompt autocomplete | ||
* @param {Function} [arg0.validate] - prompt validation | ||
* @param {Object} args - | ||
* @param {Object} args.context - An instance of context | ||
* @param {Object} args.commands - app commands | ||
* @param {Object} args.options - app options | ||
* @param {Function|Array} [args.complete=[]] - prompt autocomplete | ||
* @param {Function} [args.validate] - prompt validation | ||
* @returns {void} | ||
*/ | ||
async function promptAndRun(arg0: Args): Promise<Error | void> { | ||
const { context, commands, prompt } = arg0; | ||
async function promptAndRun(args: Args): Promise<Error | void> { | ||
const { context, commands, prompt } = args; | ||
try { | ||
@@ -48,3 +68,3 @@ const cmdLine = `${await prompt.start()}`; | ||
} | ||
return promptAndRun(arg0); | ||
return promptAndRun(args); | ||
} catch (error) { | ||
@@ -61,15 +81,15 @@ if (error.message !== "quit") { | ||
const keyPressParser = { | ||
keyPress: commandInfo | ||
keyPress: commandInfo, | ||
}; | ||
const keyPressAutocomplete = { | ||
keyPress: Autocomplete({ commandInfo }) | ||
keyPress: Autocomplete({ commandInfo }), | ||
}; | ||
const keyPressAutoHelp = { | ||
keyPress: AutoHelp() | ||
keyPress: AutoHelp(), | ||
}; | ||
const keyPressValidator = { | ||
keyPress: keyPressValidate() | ||
keyPress: keyPressValidate(), | ||
}; | ||
@@ -83,3 +103,3 @@ | ||
return state; | ||
} | ||
}, | ||
}, | ||
@@ -91,4 +111,4 @@ ...prompt.keyPressers, | ||
keyPressAutoHelp, | ||
keyPressValidator | ||
] | ||
keyPressValidator, | ||
], | ||
}); | ||
@@ -99,16 +119,27 @@ | ||
type StartArgs = { | ||
context: ContextSchema; | ||
commands: Defs; | ||
prompt: Prompt; | ||
cmdLine?: string; | ||
}; | ||
/** | ||
* Start the console app | ||
* | ||
* @param {Object} arg0 - | ||
* @param {Object} arg0.context - An instance of context | ||
* @param {Object} arg0.commands - app commands | ||
* @param {Object} args - | ||
* @param {Object} args.context - An instance of context | ||
* @param {Object} args.commands - app commands | ||
* @returns {void} | ||
*/ | ||
export async function start(arg0: Args) { | ||
const { context, commands, prompt } = arg0; | ||
export async function start(args: StartArgs) { | ||
const { context, commands, prompt, cmdLine } = args; | ||
if (cmdLine) { | ||
return runCommandLine({ context, commands, cmdLine }); | ||
} | ||
initCommandPrompt({ context, commands, prompt }); | ||
process.on("SIGINT", function() { | ||
process.on("SIGINT", function () { | ||
console.log("Interrupted"); | ||
@@ -115,0 +146,0 @@ console.log(prompt.state); |
@@ -12,3 +12,3 @@ import _filter from "lodash/filter"; | ||
function getSuggests(obj: { [key: string]: unknown }) { | ||
return _filter(Object.keys(obj), choice => !choice.startsWith("_")); | ||
return _filter(Object.keys(obj), (choice) => !choice.startsWith("_")); | ||
} | ||
@@ -43,3 +43,3 @@ | ||
command: appCmd, | ||
input: info.input | ||
input: info.input, | ||
}); | ||
@@ -60,3 +60,3 @@ debug(["command.suggests", info.suggests]); | ||
command: appCmd, | ||
input: info.input | ||
input: info.input, | ||
}); | ||
@@ -79,3 +79,3 @@ debug(["command.helps", info.help]); | ||
if (filter) { | ||
const matches = _filter(info.suggests, choice => | ||
const matches = _filter(info.suggests, (choice) => | ||
choice.startsWith(filter) | ||
@@ -82,0 +82,0 @@ ); |
@@ -13,6 +13,3 @@ /* eslint-disable @typescript-eslint/no-var-requires */ | ||
} | ||
const at = new Error().stack | ||
?.split(/\n/)[2] | ||
.trim() | ||
.replace(cwd, ""); | ||
const at = new Error().stack?.split(/\n/)[2].trim().replace(cwd, ""); | ||
const record = prettyjson.render(stuff, {}); | ||
@@ -19,0 +16,0 @@ fs.appendFileSync("debug.log", `${chalk.blue(at)}\n${record}\n`); |
@@ -17,3 +17,3 @@ import _merge from "lodash/merge"; | ||
Plugin, | ||
PluginSet | ||
PluginSet, | ||
} from "./types"; | ||
@@ -49,3 +49,3 @@ | ||
isOptional: Boolean(isOptional), | ||
string: arg | ||
string: arg, | ||
}; | ||
@@ -66,3 +66,3 @@ } | ||
description: "", | ||
parseOpt: { boolean: false } | ||
parseOpt: { boolean: false }, | ||
}; | ||
@@ -132,3 +132,3 @@ const option = optBits.reduce((result, val) => { | ||
}, {} as Def["aliasLookup"]); | ||
def.opts?.forEach(opt => { | ||
def.opts?.forEach((opt) => { | ||
if (opt.parseOpt.boolean) { | ||
@@ -211,5 +211,5 @@ if (!def.argsParserOpts?.boolean) { | ||
} | ||
return Promise.all(_flatten(plugins)).then(pluginList => { | ||
return Promise.all(_flatten(plugins)).then((pluginList) => { | ||
let pluginSet = { schema: {}, stores: {}, commands: {} }; | ||
pluginList.forEach(plugin => { | ||
pluginList.forEach((plugin) => { | ||
pluginSet = addPlugin(pluginSet, plugin); | ||
@@ -240,6 +240,7 @@ }); | ||
}; | ||
cmdLine: string; | ||
}; | ||
export function Makitso(args: MakitsoArgs) { | ||
const { commandPrompt, plugins } = args; | ||
const { commandPrompt, plugins, cmdLine } = args; | ||
@@ -258,7 +259,7 @@ let prompt: Prompt; | ||
return createPluginSet(plugins).then(pluginSet => { | ||
return createPluginSet(plugins).then((pluginSet) => { | ||
const { schema, stores, commands } = pluginSet; | ||
const context = Context({ schema, stores, commands }); | ||
return start({ context, commands, prompt }); | ||
return start({ context, commands, prompt, cmdLine }); | ||
}); | ||
} |
{ | ||
"name": "makitso", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A Framework for building composable interactive commandline apps", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
790725
6266