@qodalis/cli-core
Version:
Core Angular CLI for @qodalis extensions.
678 lines (666 loc) • 22.7 kB
JavaScript
var CliForegroundColor;
(function (CliForegroundColor) {
CliForegroundColor["Black"] = "\u001B[30m";
CliForegroundColor["Red"] = "\u001B[31m";
CliForegroundColor["Green"] = "\u001B[32m";
CliForegroundColor["Yellow"] = "\u001B[33m";
CliForegroundColor["Blue"] = "\u001B[34m";
CliForegroundColor["Magenta"] = "\u001B[35m";
CliForegroundColor["Cyan"] = "\u001B[36m";
CliForegroundColor["White"] = "\u001B[37m";
CliForegroundColor["Reset"] = "\u001B[0m";
})(CliForegroundColor || (CliForegroundColor = {}));
var CliBackgroundColor;
(function (CliBackgroundColor) {
CliBackgroundColor["Black"] = "\u001B[40m";
CliBackgroundColor["Red"] = "\u001B[41m";
CliBackgroundColor["Green"] = "\u001B[42m";
CliBackgroundColor["Yellow"] = "\u001B[43m";
CliBackgroundColor["Blue"] = "\u001B[44m";
CliBackgroundColor["Magenta"] = "\u001B[45m";
CliBackgroundColor["Cyan"] = "\u001B[46m";
CliBackgroundColor["White"] = "\u001B[47m";
})(CliBackgroundColor || (CliBackgroundColor = {}));
var CliIcon;
(function (CliIcon) {
// General Symbols
CliIcon["CheckIcon"] = "\u2714";
CliIcon["CrossIcon"] = "\u2718";
CliIcon["InfoIcon"] = "\u2139";
CliIcon["WarningIcon"] = "\u26A0";
CliIcon["QuestionMark"] = "?";
CliIcon["Exclamation"] = "\u2757";
CliIcon["Ellipsis"] = "\u2026";
CliIcon["Dot"] = "\u2022";
CliIcon["Bullet"] = "\u2023";
// Arrows
CliIcon["ArrowRight"] = "\u2192";
CliIcon["ArrowLeft"] = "\u2190";
CliIcon["ArrowUp"] = "\u2191";
CliIcon["ArrowDown"] = "\u2193";
CliIcon["ArrowRightFilled"] = "\u25B6";
CliIcon["ArrowLeftFilled"] = "\u25C0";
CliIcon["ArrowUpFilled"] = "\u25B2";
CliIcon["ArrowDownFilled"] = "\u25BC";
CliIcon["DoubleArrowRight"] = "\u00BB";
CliIcon["DoubleArrowLeft"] = "\u00AB";
// Lists and Progress
CliIcon["Star"] = "\u2605";
CliIcon["StarEmpty"] = "\u2606";
CliIcon["Plus"] = "+";
CliIcon["Minus"] = "-";
CliIcon["Progress"] = "\u23F3";
CliIcon["Success"] = "\u2705";
CliIcon["Failure"] = "\u274C";
// Time and Calendar
CliIcon["Clock"] = "\u23F0";
CliIcon["Timer"] = "\u23F1";
CliIcon["Alarm"] = "\uD83D\uDD14";
CliIcon["Calendar"] = "\uD83D\uDCC5";
// Navigation and Folders
CliIcon["Folder"] = "\uD83D\uDCC1";
CliIcon["FolderOpen"] = "\uD83D\uDCC2";
CliIcon["File"] = "\uD83D\uDCC4";
CliIcon["Archive"] = "\uD83D\uDDC3";
CliIcon["Link"] = "\uD83D\uDD17";
CliIcon["Chain"] = "\u26D3";
CliIcon["Bookmark"] = "\uD83D\uDD16";
// Actions
CliIcon["Edit"] = "\u270F";
CliIcon["Trash"] = "\uD83D\uDDD1";
CliIcon["Add"] = "\u2795";
CliIcon["Remove"] = "\u2796";
CliIcon["Reload"] = "\uD83D\uDD04";
CliIcon["Save"] = "\uD83D\uDCBE";
CliIcon["Undo"] = "\u21A9";
CliIcon["Redo"] = "\u21AA";
CliIcon["Play"] = "\u25B6";
CliIcon["Pause"] = "\u23F8";
CliIcon["Stop"] = "\u23F9";
CliIcon["Cancel"] = "\u274E";
// User and Security
CliIcon["User"] = "\uD83D\uDC64";
CliIcon["Group"] = "\uD83D\uDC65";
CliIcon["Lock"] = "\uD83D\uDD12";
CliIcon["Unlock"] = "\uD83D\uDD13";
CliIcon["Help"] = "\u2753";
CliIcon["Key"] = "\uD83D\uDD11";
CliIcon["Shield"] = "\uD83D\uDEE1";
// Tools and Settings
CliIcon["Gear"] = "\u2699";
CliIcon["Settings"] = "\u2699\uFE0F";
CliIcon["Theme"] = "\uD83C\uDFA8";
CliIcon["Light"] = "\uD83D\uDCA1";
CliIcon["Bug"] = "\uD83D\uDC1E";
CliIcon["Wrench"] = "\uD83D\uDD27";
CliIcon["Hammer"] = "\uD83D\uDD28";
// Technology and Devices
CliIcon["Terminal"] = "\uD83D\uDCBB";
CliIcon["Database"] = "\uD83D\uDDC4";
CliIcon["Server"] = "\uD83D\uDDA5";
CliIcon["Cloud"] = "\u2601";
CliIcon["Network"] = "\uD83C\uDF10";
CliIcon["Monitor"] = "\uD83D\uDDA5";
CliIcon["Printer"] = "\uD83D\uDDA8";
CliIcon["USB"] = "\uD83D\uDD0C";
CliIcon["Speaker"] = "\uD83D\uDD0A";
CliIcon["Microphone"] = "\uD83C\uDF99";
CliIcon["Camera"] = "\uD83D\uDCF7";
CliIcon["Video"] = "\uD83C\uDFA5";
CliIcon["Music"] = "\uD83C\uDFB5";
CliIcon["Phone"] = "\uD83D\uDCDE";
// Development and Evaluation
CliIcon["Package"] = "\uD83D\uDCE6";
CliIcon["Plugin"] = "\uD83D\uDD0C";
CliIcon["Extension"] = "\uD83E\uDDE9";
CliIcon["Module"] = "\uD83D\uDCE6";
CliIcon["Evaluate"] = "\uD83D\uDD0D";
CliIcon["Variable"] = "\uD83D\uDD27";
CliIcon["Script"] = "\uD83D\uDCDC";
CliIcon["Code"] = "\uD83D\uDCBE";
// Status and Completion
CliIcon["Logs"] = "\uD83D\uDCDC";
CliIcon["Power"] = "\u23FB";
CliIcon["Heart"] = "\u2764";
CliIcon["Flame"] = "\uD83D\uDD25";
CliIcon["Growth"] = "\uD83D\uDCC8";
CliIcon["Decline"] = "\uD83D\uDCC9";
CliIcon["WarningFilled"] = "\u26A0\uFE0F";
// Nature and Weather
CliIcon["Sun"] = "\u2600";
CliIcon["Moon"] = "\uD83C\uDF19";
CliIcon["Rain"] = "\uD83C\uDF27";
CliIcon["Snow"] = "\u2744";
CliIcon["Lightning"] = "\u26A1";
CliIcon["Tree"] = "\uD83C\uDF32";
// Emotions and Expressions
CliIcon["Smile"] = "\uD83D\uDE0A";
CliIcon["Sad"] = "\uD83D\uDE22";
CliIcon["Angry"] = "\uD83D\uDE21";
CliIcon["Clap"] = "\uD83D\uDC4F";
CliIcon["ThumbsUp"] = "\uD83D\uDC4D";
CliIcon["ThumbsDown"] = "\uD83D\uDC4E";
// Miscellaneous
CliIcon["Rocket"] = "\uD83D\uDE80";
CliIcon["Globe"] = "\uD83C\uDF0D";
CliIcon["Medal"] = "\uD83C\uDFC5";
CliIcon["Trophy"] = "\uD83C\uDFC6";
CliIcon["Flag"] = "\uD83D\uDEA9";
CliIcon["StarFilled"] = "\u2B50";
CliIcon["StarOutline"] = "\u2729";
CliIcon["Fireworks"] = "\uD83C\uDF86";
CliIcon["Balloon"] = "\uD83C\uDF88";
CliIcon["Gift"] = "\uD83C\uDF81";
})(CliIcon || (CliIcon = {}));
/**
* Represents a log level for the CLI
*/
var CliLogLevel;
(function (CliLogLevel) {
CliLogLevel[CliLogLevel["None"] = 0] = "None";
CliLogLevel[CliLogLevel["DEBUG"] = 1] = "DEBUG";
CliLogLevel[CliLogLevel["LOG"] = 2] = "LOG";
CliLogLevel[CliLogLevel["INFO"] = 3] = "INFO";
CliLogLevel[CliLogLevel["WARN"] = 4] = "WARN";
CliLogLevel[CliLogLevel["ERROR"] = 5] = "ERROR";
})(CliLogLevel || (CliLogLevel = {}));
const enums = {
CliForegroundColor,
CliBackgroundColor,
CliIcon,
CliLogLevel,
};
const DefaultLibraryAuthor = {
name: 'Nicolae Lupei',
email: 'nicolae.lupei@qodalis.com',
};
const constants = {
DefaultLibraryAuthor,
};
const delay = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
class ObjectDescriber {
static describe(obj, options) {
const { filter } = options || {};
const processors = [];
const keys = Object.keys(obj);
const functions = keys.filter((key) => typeof obj[key] === 'function');
for (const func of functions) {
const funcValue = obj[func];
const args = this.getFunctionArguments(funcValue);
if (filter) {
const shouldInclude = filter({
funcName: func,
func: funcValue,
args,
});
if (!shouldInclude) {
continue;
}
}
const supportsMultipleArgs = args.length > 1;
const supportsDynamicArgs = this.supportsDynamicArgs(funcValue);
if (args.length === 0 && !supportsDynamicArgs) {
continue;
}
if (args.length > 0 &&
args.some((arg) => arg === 'function' || arg === 'func')) {
continue;
}
const processor = {
command: func,
description: `A command that executes the function ${func} with the provided arguments`,
allowUnlistedCommands: true,
valueRequired: true,
parameters: [
{
name: 'debug',
description: 'Debug',
type: 'boolean',
required: false,
},
],
processCommand: async (command, context) => {
const debug = command.args['debug'];
if (debug) {
context.writer.writeln('Executing command: ' + func);
context.writer.writeln('Arguments: ' + JSON.stringify(command.args));
context.writer.writeln('Function: ' + funcValue.toString());
}
const argsToCallF = [];
if (supportsMultipleArgs) {
for (const arg of args.slice(1)) {
argsToCallF.push(command.args[arg]);
}
}
if (supportsDynamicArgs) {
const delimiter = command.args['delimiter'] || ',';
argsToCallF.push(...command.value.split(delimiter));
}
if (debug) {
context.writer.writeln('Arguments after processing: ' +
JSON.stringify(argsToCallF));
}
const result = supportsDynamicArgs && args.length === 0
? funcValue(...argsToCallF)
: funcValue(command.value, ...argsToCallF);
context.writer.write(context.writer.wrapInColor('Result: ', CliForegroundColor.Yellow));
if (result === null) {
context.writer.writeln('null');
}
else if (result === undefined) {
context.writer.writeln('undefined');
}
else if (typeof result === 'boolean') {
context.writer.writeln(result.toString());
}
else if (typeof result === 'number') {
context.writer.writeln(result.toString());
}
else if (Array.isArray(result)) {
context.writer.writeJson(result);
}
else if (typeof result === 'string') {
context.writer.writeln(result);
}
else if (typeof result === 'object') {
context.writer.writeJson(result);
}
else {
context.writer.writeln(result?.toString());
}
context.process.output(result?.toString());
},
writeDescription: (context) => {
context.writer.writeln(func);
},
};
if (supportsDynamicArgs) {
processor.parameters?.push({
name: 'delimiter',
description: 'Delimiter',
type: 'string',
required: false,
});
}
if (supportsMultipleArgs) {
processor.parameters?.push(...args.slice(1).map((arg) => ({
name: arg,
description: arg,
type: 'string',
required: false,
})));
}
processors.push(processor);
}
return processors;
}
static supportsDynamicArgs(func) {
const funcStr = func.toString();
return funcStr.includes('arguments');
}
static getFunctionArguments(func) {
const funcStr = func.toString();
const args = funcStr.match(/\(([^)]*)\)/);
if (!args) {
return [];
}
return args[1]
.split(',')
.map((arg) => arg.trim())
.filter((arg) => arg !== '');
}
}
const getParameterValue = (p, args) => {
return (args[p.name] ??
(p.aliases?.find((alias) => args[alias]) &&
args[p.aliases.find((alias) => args[alias])]));
};
const formatJson = (json) => {
const identedJson = JSON.stringify(json, null, 2);
return colorizeJson(identedJson.split('\n').join('\r\n'));
};
const colorizeJson = (jsonString) => {
return jsonString
.replace(/"([^"]+)":/g, '\x1b[33m"$1":\x1b[0m') // Keys (yellow)
.replace(/: "([^"]*)"/g, ': \x1b[32m"$1"\x1b[0m') // Strings (green)
.replace(/: (\d+)/g, ': \x1b[34m$1\x1b[0m') // Numbers (blue)
.replace(/: (true|false)/g, ': \x1b[35m$1\x1b[0m') // Booleans (magenta)
.replace(/: (null)/g, ': \x1b[36m$1\x1b[0m'); // Null (cyan)
};
const toQueryString = (params) => {
const searchParams = new URLSearchParams();
for (const key in params) {
if (params.hasOwnProperty(key)) {
const value = params[key];
// Handle array and non-primitive values
if (Array.isArray(value)) {
value.forEach((v) => searchParams.append(key, v.toString()));
}
else if (value !== null && value !== undefined) {
searchParams.append(key, value.toString());
}
}
}
return searchParams.toString();
};
const highlightTextWithBg = (text, pattern, bgColor = CliBackgroundColor.Yellow) => {
// Replace matches with background-colored text
return text.replace(pattern, (match) => `${bgColor}${match}${CliForegroundColor.Reset}`);
};
const getRightOfWord = (command, word) => {
// Find the position of the word in the command
const index = command.indexOf(word);
// If the word is found, extract the substring to the right
if (index !== -1) {
return command.slice(index + word.length).trim();
}
// If the word is not found, return null
return undefined;
};
const colorFirstWord = (text, colorFunction) => {
if (!text)
return text;
// Match leading spaces and first word separately
const match = text.match(/^(\s*)(\S+)(.*)$/);
if (!match)
return text; // If no match, return original text
const [, leadingSpaces, firstWord, restOfText] = match;
// Apply color only to the first word
const firstWordColored = colorFunction(firstWord);
// Reconstruct string: Keep spaces, color first word, and append rest
return `${leadingSpaces}${firstWordColored}${restOfText}`;
};
const utils = {
getParameterValue,
formatJson,
colorizeJson,
toQueryString,
highlightTextWithBg,
getRightOfWord,
colorFirstWord,
ObjectDescriber,
delay,
};
const initializeBrowserEnvironment = ({ context, handlers, }) => {
window.cliCore = {
onUmdModuleBoot: handlers || [],
bootUmdModule: async (module) => {
context.logger.log('Booting UMD module', module.name);
window[module.name] = module;
handlers.forEach(async (handler) => await handler(module));
},
...constants,
...utils,
...enums,
};
window.ngCore = {
Injectable: () => { },
};
};
const bootUmdModule = async (module) => {
if (typeof window !== 'undefined') {
await window.cliCore.bootUmdModule(module);
}
else {
console.log('window is undefined');
}
};
class CancellablePromise {
constructor(executor) {
this.executor = executor;
this.hasCancelled = false;
this.abortController = new AbortController();
}
execute() {
return new Promise((resolve, reject) => {
this.abortController.signal.onabort = () => {
reject(new Error('Promise cancelled'));
};
this.executor((value) => {
if (!this.hasCancelled) {
resolve(value);
}
}, (reason) => {
if (!this.hasCancelled) {
reject(reason);
}
});
});
}
cancel() {
this.hasCancelled = true;
this.abortController.abort();
}
}
const DefaultThemes = {
default: {
background: '#0c0c0c',
foreground: '#cccccc',
green: '#16c60c',
blue: '#3b78ff',
yellow: '#FFA500',
},
dracula: {
background: '#282A36',
foreground: '#F8F8F2',
cursor: '#50FA7B',
black: '#21222C',
red: '#FF5555',
green: '#50FA7B',
yellow: '#F1FA8C',
blue: '#BD93F9',
magenta: '#FF79C6',
cyan: '#8BE9FD',
white: '#F8F8F2',
brightBlack: '#6272A4',
brightRed: '#FF6E6E',
brightGreen: '#69FF94',
brightYellow: '#FFFFA5',
brightBlue: '#D6ACFF',
brightMagenta: '#FF92D0',
brightCyan: '#A4FFFF',
brightWhite: '#FFFFFF',
},
monokai: {
background: '#272822',
foreground: '#F8F8F2',
cursor: '#F8F8F0',
black: '#272822',
red: '#F92672',
green: '#A6E22E',
yellow: '#F4BF75',
blue: '#66D9EF',
magenta: '#AE81FF',
cyan: '#A1EFE4',
white: '#F8F8F2',
brightBlack: '#75715E',
brightRed: '#F92672',
brightGreen: '#A6E22E',
brightYellow: '#F4BF75',
brightBlue: '#66D9EF',
brightMagenta: '#AE81FF',
brightCyan: '#A1EFE4',
brightWhite: '#F9F8F5',
},
solarizedDark: {
background: '#002B36',
foreground: '#839496',
cursor: '#93A1A1',
black: '#073642',
red: '#DC322F',
green: '#859900',
yellow: '#B58900',
blue: '#268BD2',
magenta: '#D33682',
cyan: '#2AA198',
white: '#EEE8D5',
brightBlack: '#002B36',
brightRed: '#CB4B16',
brightGreen: '#586E75',
brightYellow: '#657B83',
brightBlue: '#839496',
brightMagenta: '#6C71C4',
brightCyan: '#93A1A1',
brightWhite: '#FDF6E3',
},
solarizedLight: {
background: '#FDF6E3',
foreground: '#657B83',
cursor: '#586E75',
black: '#073642',
red: '#DC322F',
green: '#859900',
yellow: '#B58900',
blue: '#268BD2',
magenta: '#D33682',
cyan: '#2AA198',
white: '#EEE8D5',
brightBlack: '#002B36',
brightRed: '#CB4B16',
brightGreen: '#586E75',
brightYellow: '#657B83',
brightBlue: '#839496',
brightMagenta: '#6C71C4',
brightCyan: '#93A1A1',
brightWhite: '#FDF6E3',
},
gruvboxDark: {
background: '#282828',
foreground: '#EBDBB2',
cursor: '#EBDBB2',
black: '#282828',
red: '#CC241D',
green: '#98971A',
yellow: '#D79921',
blue: '#458588',
magenta: '#B16286',
cyan: '#689D6A',
white: '#A89984',
brightBlack: '#928374',
brightRed: '#FB4934',
brightGreen: '#B8BB26',
brightYellow: '#FABD2F',
brightBlue: '#83A598',
brightMagenta: '#D3869B',
brightCyan: '#8EC07C',
brightWhite: '#EBDBB2',
},
gruvboxLight: {
background: '#FBF1C7',
foreground: '#3C3836',
cursor: '#3C3836',
black: '#FBF1C7',
red: '#9D0006',
green: '#79740E',
yellow: '#B57614',
blue: '#076678',
magenta: '#8F3F71',
cyan: '#427B58',
white: '#3C3836',
brightBlack: '#D5C4A1',
brightRed: '#AF3A03',
brightGreen: '#B8BB26',
brightYellow: '#FABD2F',
brightBlue: '#83A598',
brightMagenta: '#D3869B',
brightCyan: '#8EC07C',
brightWhite: '#EBDBB2',
},
nord: {
background: '#2E3440',
foreground: '#D8DEE9',
cursor: '#88C0D0',
black: '#3B4252',
red: '#BF616A',
green: '#A3BE8C',
yellow: '#EBCB8B',
blue: '#81A1C1',
magenta: '#B48EAD',
cyan: '#88C0D0',
white: '#E5E9F0',
brightBlack: '#4C566A',
brightRed: '#BF616A',
brightGreen: '#A3BE8C',
brightYellow: '#EBCB8B',
brightBlue: '#81A1C1',
brightMagenta: '#B48EAD',
brightCyan: '#8FBCBB',
brightWhite: '#ECEFF4',
},
oneDark: {
background: '#282C34',
foreground: '#ABB2BF',
cursor: '#528BFF',
black: '#282C34',
red: '#E06C75',
green: '#98C379',
yellow: '#E5C07B',
blue: '#61AFEF',
magenta: '#C678DD',
cyan: '#56B6C2',
white: '#ABB2BF',
brightBlack: '#5C6370',
brightRed: '#E06C75',
brightGreen: '#98C379',
brightYellow: '#E5C07B',
brightBlue: '#61AFEF',
brightMagenta: '#C678DD',
brightCyan: '#56B6C2',
brightWhite: '#FFFFFF',
},
material: {
background: '#263238',
foreground: '#ECEFF1',
cursor: '#FFCC00',
black: '#263238',
red: '#F07178',
green: '#C3E88D',
yellow: '#FFCB6B',
blue: '#82AAFF',
magenta: '#C792EA',
cyan: '#89DDFF',
white: '#EEFFFF',
brightBlack: '#546E7A',
brightRed: '#F07178',
brightGreen: '#C3E88D',
brightYellow: '#FFCB6B',
brightBlue: '#82AAFF',
brightMagenta: '#C792EA',
brightCyan: '#89DDFF',
brightWhite: '#FFFFFF',
},
yellow: {
background: '#FFFACD',
foreground: '#000000',
cursor: '#FFA500',
selectionBackground: '#FFD700',
black: '#3B3A32',
red: '#D32F2F',
green: '#388E3C',
yellow: '#FBC02D',
blue: '#1976D2',
magenta: '#8E24AA',
cyan: '#0097A7',
white: '#FFFFFF',
brightBlack: '#616161',
brightRed: '#FF5252',
brightGreen: '#69F0AE',
brightYellow: '#FFEB3B',
brightBlue: '#64B5F6',
brightMagenta: '#BA68C8',
brightCyan: '#4DD0E1',
brightWhite: '#FAFAFA', // Very Light Gray
},
};
// Automatically generated during build
const LIBRARY_VERSION = '0.0.14';
/*
* Public API Surface of core
*/
/**
* Generated bundle index. Do not edit.
*/
export { CancellablePromise, CliBackgroundColor, CliForegroundColor, CliIcon, CliLogLevel, DefaultLibraryAuthor, DefaultThemes, LIBRARY_VERSION, ObjectDescriber, bootUmdModule, colorFirstWord, colorizeJson, constants, delay, enums, formatJson, getParameterValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, toQueryString, utils };
//# sourceMappingURL=qodalis-cli-core.mjs.map