contensis-cli 1.0.12-beta.5 → 1.0.12-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/util/logger.ts"],
4
- "sourcesContent": ["/* eslint-disable no-console */\nimport chalk from 'chalk';\nimport dateFormat from 'dateformat';\nimport deepCleaner from 'deep-cleaner';\nimport { ansiEscapeCodes, first, strlen } from 'printable-characters';\n// import ProgressBar from 'progress';\nimport { isSysError, tryStringify } from '.';\n\ntype LogMethod = (content: string) => void;\ntype LogErrorMethod = (content: string, err?: any, newline?: string) => void;\ntype LogJsonMethod = (content: any, depth?: number, indent?: string) => void;\ntype LogJsonDepthMethod = (content: any, depth?: number) => void;\ntype LogArrayMethod = (contentArray: string[]) => void;\ntype LogErrorFunc = (\n err: any,\n msg?: string,\n level?: 'error' | 'critical'\n) => void;\n\nexport class Logger {\n static isUserTerminal = !!process.stdout.columns;\n static getPrefix = () => {\n return Logger.isUserTerminal\n ? Logger.infoText(`[cli]`)\n : `[${dateFormat(new Date(), 'dd/mm HH:MM:ss')}]`;\n };\n static errorText = chalk.bold.red;\n static warningText = chalk.keyword('orange');\n static successText = chalk.keyword('green');\n static helpText = chalk.blue;\n static highlightText = chalk.yellow;\n static infoText = chalk.keyword('grey');\n static standardText = chalk.keyword('white');\n static boldText = chalk.bold;\n static critical: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n '[CRITICAL]'\n )} ${content}`;\n console.log(message);\n };\n static error: LogErrorMethod = (content, err, newline = '\\n') => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n `${Logger.isUserTerminal ? '\u274C' : '[ERROR]'} ${content}${\n err\n ? `\\n\\n${Logger.infoText(\n isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)\n )}`\n : ''\n }`\n )}${newline}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static warning: LogMethod = content => {\n // if (process.env.DEBUG === 'true') {\n const message = `${Logger.getPrefix()} ${Logger.warningText(\n `${Logger.isUserTerminal ? '\u26A0\uFE0F ' : '[WARN]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n // }\n };\n static success: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.successText(\n `${Logger.isUserTerminal ? '\u2705' : '[OK]'} ${content}`\n )}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static info: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? chalk.bgCyan(' \u2139 ') : '[INFO]'\n } ${Logger.infoText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static help: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${chalk.blue(\n `${Logger.isUserTerminal ? '\u23E9' : '[HELP]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static standard: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? '\u25FB\uFE0F' : '[STD]'\n } \\n${Logger.standardText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n progress.current.interrupt(message);\n };\n static debug: LogMethod = content => {\n if (['true', '1'].includes(process.env.debug || '')) {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? chalk.bgGrey(' \u2699 ') : '[DEBUG]'\n } ${Logger.infoText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n }\n };\n static json: LogJsonDepthMethod = (content, depth = 9) =>\n console.dir(deepCleaner(content), { colors: true, depth });\n static mixed: LogArrayMethod = contentArray =>\n console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);\n static line = () =>\n Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);\n\n static object: LogJsonMethod = content => {\n for (const [key, value] of Object.entries(content || {})) {\n if (value && typeof value === 'object') {\n Logger.raw(` ${chalk.bold.grey(key)}:`);\n if (key === 'fields' && Array.isArray(value)) {\n for (const field of value || []) {\n Logger.raw(\n ` ${chalk.bold(field.id)}${\n field.id === content.entryTitleField\n ? '**'\n : field.validations.minCount?.value ||\n typeof field.validations.required?.message !== 'undefined'\n ? '*'\n : ''\n }: ${chalk.grey(\n `${field.dataType}${\n field.dataFormat\n ? `<${\n Array.isArray(\n field.validations.allowedFieldTypes?.fields\n )\n ? `composer[${field.validations.allowedFieldTypes.fields\n .map((f: any) => f.id)\n .join(' | ')}]`\n : field.dataFormat\n }${\n field.dataFormat === 'entry'\n ? `, ${field.validations.allowedContentTypes.contentTypes.join(\n ' | '\n )}`\n : ''\n }>`\n : ''\n }${\n field.validations.maxLength?.value\n ? `(${field.validations.maxLength.value})`\n : ''\n }`\n )}`\n );\n }\n } else if (key === 'groups' && Array.isArray(value)) {\n for (const group of value || []) {\n const description =\n Object.keys(group.description).length &&\n Object.values(group.description)?.[0];\n Logger.raw(\n ` ${chalk.bold(group.id)}${\n description\n ? `: ${chalk.grey(Object.values(group.description)?.[0])}`\n : ''\n }`\n );\n }\n } else {\n Logger.objectRecurse(value, 3, ' ');\n // for (const [innerkey, innervalue] of Object.entries(value)) {\n // if (innervalue && typeof innervalue === 'object') {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}:`);\n // console.table(innervalue);\n // } else if (\n // typeof innervalue !== 'undefined' &&\n // innervalue !== null\n // ) {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);\n // }\n // }\n }\n } else if (typeof value !== 'undefined' && value !== null) {\n const valueText =\n key === 'id' && typeof value === 'string'\n ? Logger.highlightText(value)\n : value;\n Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);\n }\n }\n };\n\n static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {\n if (Array.isArray(content)) {\n for (const item of content) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else Logger.raw(`${indent}${item}`);\n }\n } else {\n let pos = 0;\n for (const [key, value] of Object.entries(content)) {\n const thisIndent =\n pos === 0 ? `${indent.substring(0, indent.length - 2)}- ` : indent;\n if (Array.isArray(value)) {\n if (value.length) Logger.raw(`${thisIndent}${chalk.bold.grey(key)}:`);\n for (const item of value) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else {\n Logger.raw(`${indent} ${item}`);\n }\n }\n } else if (value && typeof value === 'object') {\n Logger.raw(`${indent}${chalk.bold.grey(key)}:`);\n\n Logger.objectRecurse(value, depth + 1, `${indent} `);\n // console.table(value);\n } else if (typeof value !== 'undefined' && value !== null) {\n Logger.raw(`${thisIndent}${chalk.bold.grey(key)}: ${value}`);\n }\n pos++;\n }\n }\n };\n static raw: LogMethod = (content: string) => {\n if (progress.active) progress.current.interrupt(content);\n else console.log(content);\n };\n\n static limits = (content: string, displayLength = 30) => {\n const consoleWidth = process.stdout.columns;\n console.info(\n consoleWidth\n ? content\n .split('\\n')\n .slice(0, consoleWidth ? displayLength : undefined)\n .map((line: string) =>\n consoleWidth && strlen(line) > consoleWidth\n ? first(line, consoleWidth)\n : line\n )\n .join('\\n')\n : content.replace(ansiEscapeCodes, '')\n );\n const tableArray = content.split('\\n');\n if (consoleWidth && tableArray.length > displayLength)\n console.info(`\\n`, `- and ${tableArray.length - displayLength} more...`);\n };\n}\n\nexport const logError: LogErrorFunc = (\n err = new Error('Undefined error'),\n msg,\n level = 'error'\n) => {\n Logger[level](msg || err.message || err?.data?.message || err.Message);\n (Array.isArray(err) ? err : [err]).map((error: AppError) => {\n if (typeof error === 'string') {\n Logger.raw(`${Logger.infoText(error)}\\n`);\n return;\n }\n if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}\\n`);\n if ('data' in error)\n Logger.raw(` ${Logger.infoText(tryStringify(error.data))}\\n`);\n });\n //Logger.line();\n return null;\n};\n\nexport const progress = {\n current: { interrupt: (x: string) => {} },\n active: false,\n // done: () => new ProgressBar('', 0),\n // colours: { green: '\\u001b[42m \\u001b[0m', red: '\\u001b[41m \\u001b[0m' },\n // current: new ProgressBar(`:bar`, {\n // complete: '=',\n // incomplete: ' ',\n // width: 20,\n // total: 100,\n // }),\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,wBAAuB;AACvB,0BAAwB;AACxB,kCAA+C;AAE/C,eAAyC;AAalC,MAAM,OAAO;AAAA,EAClB,OAAO,iBAAiB,CAAC,CAAC,QAAQ,OAAO;AAAA,EACzC,OAAO,YAAY,MAAM;AACvB,WAAO,OAAO,iBACV,OAAO,SAAS,OAAO,IACvB,QAAI,kBAAAA,SAAW,IAAI,KAAK,GAAG,gBAAgB;AAAA,EACjD;AAAA,EACA,OAAO,YAAY,aAAAC,QAAM,KAAK;AAAA,EAC9B,OAAO,cAAc,aAAAA,QAAM,QAAQ,QAAQ;AAAA,EAC3C,OAAO,cAAc,aAAAA,QAAM,QAAQ,OAAO;AAAA,EAC1C,OAAO,WAAW,aAAAA,QAAM;AAAA,EACxB,OAAO,gBAAgB,aAAAA,QAAM;AAAA,EAC7B,OAAO,WAAW,aAAAA,QAAM,QAAQ,MAAM;AAAA,EACtC,OAAO,eAAe,aAAAA,QAAM,QAAQ,OAAO;AAAA,EAC3C,OAAO,WAAW,aAAAA,QAAM;AAAA,EACxB,OAAO,WAAsB,aAAW;AACtC,UAAM,UAAU,GAAG,OAAO,UAAU,MAAM,OAAO;AAAA,MAC/C;AAAA,IACF,KAAK;AACL,YAAQ,IAAI,OAAO;AAAA,EACrB;AAAA,EACA,OAAO,QAAwB,CAAC,SAAS,KAAK,UAAU,SAAS;AAC/D,UAAM,UAAU,GAAG,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MAAM,IAAI,CAAC;AAAA,CAAK;AAAA,EACjE,CAAC;AAED,SAAO;AACT;AAEO,MAAM,WAAW;AAAA,EACtB,SAAS,EAAE,WAAW,CAAC,MAAc;AAAA,EAAC,EAAE;AAAA,EACxC,QAAQ;AASV;",
6
- "names": ["dateFormat", "chalk", "deepCleaner"]
4
+ "sourcesContent": ["/* eslint-disable no-console */\nimport chalk from 'chalk';\nimport dateFormat from 'dateformat';\nimport deepCleaner from 'deep-cleaner';\nimport {\n ansiEscapeCodes,\n first,\n partition,\n strlen,\n} from 'printable-characters';\n// import ProgressBar from 'progress';\nimport { isSysError, tryStringify } from '.';\n\ntype LogMethod = (content: string) => void;\ntype LogErrorMethod = (content: string, err?: any, newline?: string) => void;\ntype LogJsonMethod = (content: any, depth?: number, indent?: string) => void;\ntype LogJsonDepthMethod = (content: any, depth?: number) => void;\ntype LogArrayMethod = (contentArray: string[]) => void;\ntype LogErrorFunc = (\n err: any,\n msg?: string,\n level?: 'error' | 'critical'\n) => void;\n\nexport class Logger {\n static isUserTerminal = !!process.stdout.columns;\n static getPrefix = () => {\n return Logger.isUserTerminal\n ? Logger.infoText(`[cli]`)\n : `[${dateFormat(new Date(), 'dd/mm HH:MM:ss')}]`;\n };\n static errorText = chalk.bold.red;\n static warningText = chalk.keyword('orange');\n static successText = chalk.keyword('green');\n static helpText = chalk.blue;\n static highlightText = chalk.yellow;\n static infoText = chalk.keyword('grey');\n static standardText = chalk.keyword('white');\n static boldText = chalk.bold;\n static critical: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n '[CRITICAL]'\n )} ${content}`;\n console.log(message);\n };\n static error: LogErrorMethod = (content, err, newline = '\\n') => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n `${Logger.isUserTerminal ? '\u274C' : '[ERROR]'} ${content}${\n err\n ? `\\n\\n${Logger.infoText(\n isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)\n )}`\n : ''\n }`\n )}${newline}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static warning: LogMethod = content => {\n // if (process.env.DEBUG === 'true') {\n const message = `${Logger.getPrefix()} ${Logger.warningText(\n `${Logger.isUserTerminal ? '\u26A0\uFE0F ' : '[WARN]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n // }\n };\n static success: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.successText(\n `${Logger.isUserTerminal ? '\u2705' : '[OK]'} ${content}`\n )}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static info: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? chalk.bgCyan(' \u2139 ') : '[INFO]'\n } ${Logger.infoText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static help: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${chalk.blue(\n `${Logger.isUserTerminal ? '\u23E9' : '[HELP]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static standard: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? '\u25FB\uFE0F' : '[STD]'\n } \\n${Logger.standardText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n progress.current.interrupt(message);\n };\n static debug: LogMethod = content => {\n if (['true', '1'].includes(process.env.debug || '')) {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? chalk.bgGrey(' \u2699 ') : '[DEBUG]'\n } ${Logger.infoText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n }\n };\n static json: LogJsonDepthMethod = (content, depth = 9) =>\n console.dir(deepCleaner(content), { colors: true, depth });\n static mixed: LogArrayMethod = contentArray =>\n console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);\n static line = () =>\n Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);\n\n static object: LogJsonMethod = content => {\n for (const [key, value] of Object.entries(content || {})) {\n if (value && typeof value === 'object') {\n Logger.raw(` ${chalk.bold.grey(key)}:`);\n if (key === 'fields' && Array.isArray(value)) {\n for (const field of value || []) {\n Logger.raw(\n ` ${chalk.bold(field.id)}${\n field.id === content.entryTitleField\n ? '**'\n : field.validations.minCount?.value ||\n typeof field.validations.required?.message !== 'undefined'\n ? '*'\n : ''\n }: ${chalk.grey(\n `${field.dataType}${\n field.dataFormat\n ? `<${\n Array.isArray(\n field.validations.allowedFieldTypes?.fields\n )\n ? `composer[${field.validations.allowedFieldTypes.fields\n .map((f: any) => f.id)\n .join(' | ')}]`\n : field.dataFormat\n }${\n field.dataFormat === 'entry'\n ? `, ${field.validations.allowedContentTypes.contentTypes.join(\n ' | '\n )}`\n : ''\n }>`\n : ''\n }${\n field.validations.maxLength?.value\n ? `(${field.validations.maxLength.value})`\n : ''\n }`\n )}`\n );\n }\n } else if (key === 'groups' && Array.isArray(value)) {\n for (const group of value || []) {\n const description =\n Object.keys(group.description).length &&\n Object.values(group.description)?.[0];\n Logger.raw(\n ` ${chalk.bold(group.id)}${\n description\n ? `: ${chalk.grey(Object.values(group.description)?.[0])}`\n : ''\n }`\n );\n }\n } else {\n Logger.objectRecurse(value, 3, ' ');\n // for (const [innerkey, innervalue] of Object.entries(value)) {\n // if (innervalue && typeof innervalue === 'object') {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}:`);\n // console.table(innervalue);\n // } else if (\n // typeof innervalue !== 'undefined' &&\n // innervalue !== null\n // ) {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);\n // }\n // }\n }\n } else if (typeof value !== 'undefined' && value !== null) {\n const valueText =\n key === 'id' && typeof value === 'string'\n ? Logger.highlightText(value)\n : value;\n Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);\n }\n }\n };\n\n static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {\n if (Array.isArray(content)) {\n for (const item of content) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else Logger.raw(`${indent}${item}`);\n }\n } else {\n let pos = 0;\n for (const [key, value] of Object.entries(content)) {\n const thisIndent =\n pos === 0 ? `${indent.substring(0, indent.length - 2)}- ` : indent;\n if (Array.isArray(value)) {\n if (value.length) Logger.raw(`${thisIndent}${chalk.bold.grey(key)}:`);\n for (const item of value) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else {\n Logger.raw(`${indent} ${item}`);\n }\n }\n } else if (value && typeof value === 'object') {\n Logger.raw(`${indent}${chalk.bold.grey(key)}:`);\n\n Logger.objectRecurse(value, depth + 1, `${indent} `);\n // console.table(value);\n } else if (typeof value !== 'undefined' && value !== null) {\n Logger.raw(`${thisIndent}${chalk.bold.grey(key)}: ${value}`);\n }\n pos++;\n }\n }\n };\n static raw: LogMethod = (content: string) => {\n if (progress.active) progress.current.interrupt(content);\n else console.log(content);\n };\n\n static limits = (\n content: string,\n displayLength = 30,\n consoleWidth = process.stdout.columns,\n logMethod: Function = console.info\n ) => {\n if (consoleWidth) {\n content\n .split('\\n')\n .slice(0, consoleWidth ? displayLength : undefined)\n .map((line: string) =>\n logMethod(\n line\n .split('~n')\n .map(l =>\n consoleWidth && strlen(l) > consoleWidth\n ? first(l, consoleWidth)\n : l\n )\n .join('\\n')\n )\n )\n .join('\\n');\n } else {\n logMethod(content.replace(ansiEscapeCodes, ''));\n }\n\n const tableArray = content.split('\\n');\n if (consoleWidth && tableArray.length > displayLength)\n console.info(\n `\\n`,\n `- and ${tableArray.length - displayLength} more...\\n`\n );\n };\n}\n\nexport const logError: LogErrorFunc = (\n err = new Error('Undefined error'),\n msg,\n level = 'error'\n) => {\n Logger[level](msg || err.message || err?.data?.message || err.Message);\n (Array.isArray(err) ? err : [err]).map((error: AppError) => {\n if (typeof error === 'string') {\n Logger.raw(`${Logger.infoText(error)}\\n`);\n return;\n }\n if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}\\n`);\n if ('data' in error)\n Logger.raw(` ${Logger.infoText(tryStringify(error.data))}\\n`);\n });\n //Logger.line();\n return null;\n};\n\nexport const addNewLines = (\n message = '',\n newLineSeparater = '\\n',\n atPosition = process.stdout.columns\n) => {\n if (message === '' || atPosition === 0) {\n return '';\n }\n\n let result = '';\n let lengthCounter = 0;\n\n // Partition the message string into an array of\n // [nonPrintable, printable][]\n const partitioned = partition(message);\n const addSeparater = () => {\n // If line length counter has exceeded the console width\n // add a new line separater and reset the line length counter\n if (lengthCounter >= atPosition) {\n result += newLineSeparater;\n lengthCounter = 0;\n }\n };\n\n // Loop through the partitioned message parts\n for (const [nonPrintable, printable] of partitioned) {\n // Convert string to array as this will provide accurate\n // lengths and splicing methods with all unicode chars\n const textParts = Array.from(printable);\n // Splice the remaining allowable line length from the text parts array\n const text = textParts.splice(0, atPosition - lengthCounter);\n // In the first iteration append the non printable unicode chars\n // to the beginning of the spliced text\n result += nonPrintable + text.join('');\n // Keep a count of the current line length\n // as one line of output could span multiple \"partitions\"\n lengthCounter += text.length;\n addSeparater();\n\n // Handle any remaining text in this \"partition\"\n while (textParts.length) {\n // Splice the remaining allowable line length from the text parts array\n const text = textParts.splice(0, atPosition - lengthCounter);\n // Append the spliced text to the result\n result += text.join('');\n // Increase line length counter\n lengthCounter += text.length;\n addSeparater();\n }\n }\n return result;\n};\n\nexport const progress = {\n current: { interrupt: (x: string) => {} },\n active: false,\n // done: () => new ProgressBar('', 0),\n // colours: { green: '\\u001b[42m \\u001b[0m', red: '\\u001b[41m \\u001b[0m' },\n // current: new ProgressBar(`:bar`, {\n // complete: '=',\n // incomplete: ' ',\n // width: 20,\n // total: 100,\n // }),\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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SAAS;AACb,MAAI,gBAAgB;AAIpB,QAAM,kBAAc,uCAAU,OAAO;AACrC,QAAM,eAAe,MAAM;AAGzB,QAAI,iBAAiB,YAAY;AAC/B,gBAAU;AACV,sBAAgB;AAAA,IAClB;AAAA,EACF;AAGA,aAAW,CAAC,cAAc,SAAS,KAAK,aAAa;AAGnD,UAAM,YAAY,MAAM,KAAK,SAAS;AAEtC,UAAM,OAAO,UAAU,OAAO,GAAG,aAAa,aAAa;AAG3D,cAAU,eAAe,KAAK,KAAK,EAAE;AAGrC,qBAAiB,KAAK;AACtB,iBAAa;AAGb,WAAO,UAAU,QAAQ;AAEvB,YAAME,QAAO,UAAU,OAAO,GAAG,aAAa,aAAa;AAE3D,gBAAUA,MAAK,KAAK,EAAE;AAEtB,uBAAiBA,MAAK;AACtB,mBAAa;AAAA,IACf;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,WAAW;AAAA,EACtB,SAAS,EAAE,WAAW,CAAC,MAAc;AAAA,EAAC,EAAE;AAAA,EACxC,QAAQ;AASV;",
6
+ "names": ["dateFormat", "chalk", "deepCleaner", "text"]
7
7
  }
package/dist/version.js CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  LIB_VERSION: () => LIB_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const LIB_VERSION = "1.0.12-beta.5";
24
+ const LIB_VERSION = "1.0.12-beta.7";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  LIB_VERSION
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["export const LIB_VERSION = \"1.0.12-beta.5\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.0.12-beta.7\";\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contensis-cli",
3
- "version": "1.0.12-beta.5",
3
+ "version": "1.0.12-beta.7",
4
4
  "description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
5
5
  "repository": "https://github.com/contensis/cli",
6
6
  "homepage": "https://github.com/contensis/cli/tree/main/packages/contensis-cli#readme",
@@ -40,7 +40,7 @@
40
40
  "jsonpath-mapper": "^1.1.0",
41
41
  "keytar": "^7.9.0",
42
42
  "lodash": "^4.17.21",
43
- "migratortron": "^1.0.0-beta.36",
43
+ "migratortron": "^1.0.0-beta.37",
44
44
  "nanospinner": "^1.1.0",
45
45
  "node-fetch": "^2.6.7",
46
46
  "parse-git-config": "^3.0.0",
@@ -98,6 +98,24 @@ Example call:
98
98
  ).PrintWebhookSubscriptions(webhookNameOrId);
99
99
  });
100
100
 
101
+ program
102
+ .command('workflow')
103
+ .description('get a workflow')
104
+ .argument('<workflowNameOrId>', 'id or name of the workflow to get')
105
+ .addHelpText(
106
+ 'after',
107
+ `
108
+ Example call:
109
+ > get workflow "Approval workflow"
110
+ `
111
+ )
112
+ .action(async (workflowNameOrId: string, opts) => {
113
+ await cliCommand(
114
+ ['get', 'workflow', workflowNameOrId],
115
+ opts
116
+ ).PrintWorkflow(workflowNameOrId);
117
+ });
118
+
101
119
  program
102
120
  .command('model')
103
121
  .description('get a content model')
@@ -150,16 +150,21 @@ Example call:
150
150
  '-preserve --preserve-guids',
151
151
  'include this flag when you are importing nodes that you have previously exported and wish to update'
152
152
  )
153
+ .addOption(ignoreErrors)
153
154
  .addOption(commit)
154
155
  .addOption(
155
156
  new Option(
156
- '-on --output-nodes <outputNodes>',
157
- 'how much detail to output from the nodes import'
157
+ '-od --output-detail <outputDetail>',
158
+ 'how much detail to output from the import'
158
159
  )
159
160
  .choices(['errors', 'changes', 'all'])
160
161
  .default('errors')
161
162
  )
162
- .addOption(ignoreErrors)
163
+ .option(
164
+ '-ol --output-limit <outputLimit>',
165
+ 'expand or limit the number of records output to the console',
166
+ '200'
167
+ )
163
168
  .addHelpText(
164
169
  'after',
165
170
  `
@@ -176,7 +181,8 @@ Example call:
176
181
  ).ImportNodes({
177
182
  commit: opts.commit,
178
183
  fromFile: opts.fromFile,
179
- logOutput: opts.outputNodes,
184
+ logOutput: opts.outputDetail,
185
+ logLimit: Number(opts.outputLimit),
180
186
  });
181
187
  });
182
188
 
@@ -160,5 +160,20 @@ Example call:
160
160
  name ? [name] : id
161
161
  );
162
162
  });
163
+
164
+ list
165
+ .command('workflows')
166
+ .description('print list of workflow definitions')
167
+ .addHelpText(
168
+ 'after',
169
+ `
170
+ Example call:
171
+ > list workflows
172
+ `
173
+ )
174
+ .action(async opts => {
175
+ await cliCommand(['list', 'workflows'], opts).PrintWorkflows();
176
+ });
177
+
163
178
  return list;
164
179
  };
@@ -432,6 +432,13 @@ export const LogMessages = {
432
432
  id
433
433
  )}`,
434
434
  },
435
+ workflows: {
436
+ list: (env: string) => `[${env}] Retrieved workflows`,
437
+ noList: (env: string) => `[${env}] Cannot retrieve workflows`,
438
+ noneExist: () => `No workflows found`,
439
+ failedGet: (env: string, name: string) =>
440
+ `[${env}] Unable to find workflow ${Logger.highlightText(name)}`,
441
+ },
435
442
  devinit: {
436
443
  intro: () => `Contensis developer environment initialisation`,
437
444
  //`This will initialise your local working directory to develop with the current connected Contensis project`,
@@ -11,7 +11,8 @@ export const appRootDir =
11
11
  : path.join(userHomeDir, '.contensis/');
12
12
 
13
13
  export const readJsonFile = <T>(filePath: string) => {
14
- const file = readFile(filePath);
14
+ const directoryPath = cwdPath(filePath);
15
+ const file = readFile(directoryPath);
15
16
  if (file) return tryParse(file) as T | string;
16
17
  return undefined;
17
18
  };
@@ -81,3 +82,6 @@ export const checkDir = (filePath: string) => {
81
82
 
82
83
  export const localPath = (filePath: string) =>
83
84
  path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);
85
+
86
+ export const cwdPath = (filePath: string) =>
87
+ path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);
@@ -779,7 +779,7 @@ class ContensisCli {
779
779
  }
780
780
  };
781
781
 
782
- CreateApiKey = async (name: string, description?: string) => {
782
+ CreateApiKey = async (name: string, description = '') => {
783
783
  const { currentEnv, log, messages } = this;
784
784
  const contensis = await this.ConnectContensis();
785
785
 
@@ -1033,6 +1033,98 @@ class ContensisCli {
1033
1033
  }
1034
1034
  };
1035
1035
 
1036
+ PrintWorkflows = async () => {
1037
+ const { currentEnv, log, messages } = this;
1038
+ const contensis = await this.ConnectContensis();
1039
+
1040
+ if (contensis) {
1041
+ // Retrieve workflows list for env
1042
+ const [workflowsErr, workflows] =
1043
+ await contensis.content.sourceRepo.workflows.GetWorkflows();
1044
+
1045
+ if (Array.isArray(workflows)) {
1046
+ log.success(messages.workflows.list(currentEnv));
1047
+
1048
+ if (!workflows.length) log.help(messages.workflows.noneExist());
1049
+
1050
+ const stringFromLanguageObject = (o: { [lang: string]: string }) =>
1051
+ Object.values(o || {})?.[0];
1052
+
1053
+ this.HandleFormattingAndOutput(workflows, () => {
1054
+ // print the workflows to console
1055
+ // log.object(workflows);
1056
+ for (const {
1057
+ id,
1058
+ name,
1059
+ description,
1060
+ states,
1061
+ eventGroups,
1062
+ isSystem,
1063
+ } of workflows as any) {
1064
+ const color = isSystem ? (s: string) => s : log.infoText;
1065
+
1066
+ console.log(
1067
+ color(
1068
+ ` - ${chalk.bold(
1069
+ stringFromLanguageObject(name)
1070
+ )} ${log.infoText(id)}`
1071
+ )
1072
+ );
1073
+ if (description)
1074
+ console.log(
1075
+ log.infoText(` ${stringFromLanguageObject(description)}`)
1076
+ );
1077
+ if (isSystem === false)
1078
+ console.log(` ${chalk.bold.grey('isSystem')}: false`);
1079
+ if (states?.length)
1080
+ console.log(
1081
+ ` ${chalk.bold.grey('states')}: ${states
1082
+ .map((state: any) => state.id)
1083
+ .join(', ')}`
1084
+ );
1085
+ if (eventGroups?.length)
1086
+ console.log(
1087
+ ` ${chalk.bold.grey('eventGroups')}: ${eventGroups
1088
+ .map((evtGrp: any) => evtGrp.id)
1089
+ .join(', ')}`
1090
+ );
1091
+ }
1092
+ });
1093
+ }
1094
+
1095
+ if (workflowsErr) {
1096
+ log.error(messages.workflows.noList(currentEnv));
1097
+ log.error(jsonFormatter(workflowsErr));
1098
+ }
1099
+ }
1100
+ };
1101
+
1102
+ PrintWorkflow = async (workflowNameOrId: string) => {
1103
+ const { currentEnv, log, messages } = this;
1104
+ const contensis = await this.ConnectContensis();
1105
+
1106
+ if (contensis) {
1107
+ // Retrieve workflows list for env
1108
+ const [workflowsErr, workflows] =
1109
+ await contensis.content.sourceRepo.workflows.GetWorkflows();
1110
+
1111
+ if (Array.isArray(workflows)) {
1112
+ log.success(messages.workflows.list(currentEnv));
1113
+
1114
+ const workflow = findByIdOrName(workflows, workflowNameOrId);
1115
+
1116
+ if (workflow) this.HandleFormattingAndOutput(workflow, log.object);
1117
+ else
1118
+ log.error(messages.workflows.failedGet(currentEnv, workflowNameOrId));
1119
+ }
1120
+
1121
+ if (workflowsErr) {
1122
+ log.error(messages.workflows.noList(currentEnv));
1123
+ log.error(jsonFormatter(workflowsErr));
1124
+ }
1125
+ }
1126
+ };
1127
+
1036
1128
  CreateProject = async (project: Project) => {
1037
1129
  const { currentEnv, log, messages } = this;
1038
1130
  const contensis = await this.ConnectContensis();
@@ -1710,6 +1802,7 @@ class ContensisCli {
1710
1802
 
1711
1803
  this.HandleFormattingAndOutput(nodes, () => {
1712
1804
  // print the nodes to console
1805
+ log.object({ ...root, children: undefined, language: undefined });
1713
1806
  printNodeTreeOutput(this, root);
1714
1807
  });
1715
1808
  } else {
@@ -1722,10 +1815,12 @@ class ContensisCli {
1722
1815
  commit,
1723
1816
  fromFile,
1724
1817
  logOutput,
1818
+ logLimit,
1725
1819
  }: {
1726
1820
  commit: boolean;
1727
1821
  fromFile: string;
1728
1822
  logOutput: string;
1823
+ logLimit: number;
1729
1824
  }) => {
1730
1825
  const { currentEnv, currentProject, log, messages } = this;
1731
1826
 
@@ -1744,29 +1839,34 @@ class ContensisCli {
1744
1839
  }
1745
1840
 
1746
1841
  const [err, result] = await contensis.MigrateNodes();
1842
+ const migrateTree =
1843
+ contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView;
1747
1844
 
1748
- if (err) logError(err);
1845
+ if (err) log.raw(``);
1749
1846
  else
1750
1847
  this.HandleFormattingAndOutput(result, () => {
1751
1848
  // print the migrateResult to console
1849
+ printNodeTreeOutput(this, migrateTree, logOutput, logLimit);
1752
1850
  printNodesMigrateResult(this, result, {
1753
1851
  showAll: logOutput === 'all',
1754
1852
  showChanged: logOutput === 'changes',
1755
1853
  });
1756
1854
  });
1757
1855
 
1758
- const nodesTotalCount =
1856
+ const nodesMigrateCount =
1759
1857
  result?.nodesToMigrate?.[currentProject].totalCount;
1760
1858
  const nodesCreated = result?.nodesResult?.['created'] || 0;
1761
1859
  const nodesUpdated = result?.nodesResult?.['updated'] || 0;
1762
- const noChange =
1763
- result?.nodesToMigrate?.[currentProject]['no change'] !== 0;
1860
+ const nodesErrored = result?.nodesResult?.['errored'] || 0;
1861
+ const noChanges =
1862
+ result?.nodesToMigrate?.[currentProject]['no change'] &&
1863
+ nodesMigrateCount === 0;
1764
1864
 
1765
1865
  if (
1766
1866
  !err &&
1767
1867
  (!result.errors?.length || this.contensisOpts.ignoreErrors) &&
1768
- ((!commit && nodesTotalCount) ||
1769
- (commit && (nodesCreated || nodesUpdated)))
1868
+ ((!commit && nodesMigrateCount) ||
1869
+ (commit && (nodesCreated || nodesUpdated || result.errors?.length)))
1770
1870
  ) {
1771
1871
  let totalCount: number;
1772
1872
  if (commit) {
@@ -1776,20 +1876,20 @@ class ContensisCli {
1776
1876
  totalCount = created + updated;
1777
1877
  } else {
1778
1878
  totalCount =
1779
- typeof nodesTotalCount === 'number' ? nodesTotalCount : 0;
1879
+ typeof nodesMigrateCount === 'number' ? nodesMigrateCount : 0;
1780
1880
  }
1781
1881
 
1782
1882
  log.success(messages.nodes.imported(currentEnv, commit, totalCount));
1883
+ log.raw(``);
1783
1884
  if (!commit) {
1784
- log.raw(``);
1785
1885
  log.help(messages.nodes.commitTip());
1786
1886
  }
1787
1887
  } else {
1788
- if (noChange) {
1888
+ if (noChanges && !err && !nodesErrored) {
1789
1889
  log.help(messages.nodes.noChange(currentEnv));
1790
1890
  } else {
1791
1891
  log.error(messages.nodes.failedImport(currentEnv), err);
1792
- if (!nodesTotalCount) log.help(messages.nodes.notFound(currentEnv));
1892
+ if (!nodesMigrateCount) log.help(messages.nodes.notFound(currentEnv));
1793
1893
  }
1794
1894
  }
1795
1895
  } else {
package/src/shell.ts CHANGED
@@ -156,6 +156,7 @@ class ContensisShell {
156
156
  'get token',
157
157
  'get version',
158
158
  'get webhook',
159
+ 'get workflow',
159
160
  'import contenttypes',
160
161
  'import components',
161
162
  'import entries',
@@ -170,6 +171,7 @@ class ContensisShell {
170
171
  'list renderers',
171
172
  'list roles',
172
173
  'list webhooks',
174
+ 'list workflows',
173
175
  'push block',
174
176
  'remove components',
175
177
  'remove contenttypes',