contensis-cli 1.0.0-beta.89 → 1.0.0-beta.90

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.
Files changed (43) hide show
  1. package/cli.js +3 -0
  2. package/dist/commands/dev.js.map +2 -2
  3. package/dist/localisation/en-GB.js +14 -6
  4. package/dist/localisation/en-GB.js.map +2 -2
  5. package/dist/mappers/DevInit-to-CIWorkflow.js +127 -0
  6. package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
  7. package/dist/mappers/DevInit-to-RolePermissions.js +54 -0
  8. package/dist/mappers/DevInit-to-RolePermissions.js.map +7 -0
  9. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +56 -0
  10. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +7 -0
  11. package/dist/models/DevService.d.js +17 -0
  12. package/dist/models/DevService.d.js.map +7 -0
  13. package/dist/services/ContensisDevService.js +57 -64
  14. package/dist/services/ContensisDevService.js.map +2 -2
  15. package/dist/services/ContensisRoleService.js +7 -12
  16. package/dist/services/ContensisRoleService.js.map +2 -2
  17. package/dist/util/diff.js +63 -0
  18. package/dist/util/diff.js.map +3 -3
  19. package/dist/util/dotenv.js +57 -0
  20. package/dist/util/dotenv.js.map +7 -0
  21. package/dist/util/git.js +8 -1
  22. package/dist/util/git.js.map +2 -2
  23. package/dist/util/logger.js +12 -5
  24. package/dist/util/logger.js.map +2 -2
  25. package/dist/util/yaml.js +45 -0
  26. package/dist/util/yaml.js.map +7 -0
  27. package/dist/version.js +1 -1
  28. package/dist/version.js.map +1 -1
  29. package/package.json +3 -1
  30. package/src/commands/dev.ts +1 -0
  31. package/src/localisation/en-GB.ts +18 -8
  32. package/src/mappers/DevInit-to-CIWorkflow.ts +150 -0
  33. package/src/mappers/DevInit-to-RolePermissions.ts +33 -0
  34. package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +44 -0
  35. package/src/models/DevService.d.ts +5 -0
  36. package/src/services/ContensisDevService.ts +66 -64
  37. package/src/services/ContensisRoleService.ts +7 -15
  38. package/src/util/diff.ts +96 -0
  39. package/src/util/dotenv.ts +37 -0
  40. package/src/util/git.ts +19 -7
  41. package/src/util/logger.ts +11 -5
  42. package/src/util/yaml.ts +13 -0
  43. package/src/version.ts +1 -1
@@ -112,11 +112,13 @@ ${Logger.standardText(content)}`;
112
112
  progress.current.interrupt(message);
113
113
  };
114
114
  static debug = (content) => {
115
- const message = `${Logger.getPrefix()} ${Logger.isUserTerminal ? import_chalk.default.bgGrey(" \u2699 ") : "[DEBUG]"} ${Logger.infoText(content)}`;
116
- if (progress.active)
117
- progress.current.interrupt(message);
118
- else
119
- console.log(message);
115
+ if (["true", "1"].includes(process.env.debug || "")) {
116
+ const message = `${Logger.getPrefix()} ${Logger.isUserTerminal ? import_chalk.default.bgGrey(" \u2699 ") : "[DEBUG]"} ${Logger.infoText(content)}`;
117
+ if (progress.active)
118
+ progress.current.interrupt(message);
119
+ else
120
+ console.log(message);
121
+ }
120
122
  };
121
123
  static json = (content, depth = 9) => console.dir((0, import_deep_cleaner.default)(content), { colors: true, depth });
122
124
  static mixed = (contentArray) => console.log(`${Logger.getPrefix()} ${contentArray.join(" ")}`);
@@ -215,6 +217,11 @@ const logError = (err = new Error("Undefined error"), msg, level = "error") => {
215
217
  var _a;
216
218
  Logger[level](msg || err.message || ((_a = err == null ? void 0 : err.data) == null ? void 0 : _a.message) || err.Message);
217
219
  (Array.isArray(err) ? err : [err]).map((error) => {
220
+ if (typeof error === "string") {
221
+ Logger.raw(`${Logger.infoText(error)}
222
+ `);
223
+ return;
224
+ }
218
225
  if ("stack" in error)
219
226
  Logger.raw(` ${Logger.infoText(error.stack)}
220
227
  `);
@@ -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 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 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 ('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,mB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,CAAC,SACJ,oBAAgB,oCAAO,IAAI,IAAI,mBAC3B,mCAAM,MAAM,YAAY,IACxB;AAAA,MACN,EACC,KAAK,IAAI,IACZ,QAAQ,QAAQ,6CAAiB,EAAE;AAAA,IACzC;AACA,UAAM,aAAa,QAAQ,MAAM,IAAI;AACrC,QAAI,gBAAgB,WAAW,SAAS;AACtC,cAAQ,KAAK;AAAA,GAAM,SAAS,WAAW,SAAS,uBAAuB;AAAA,EAC3E;AACF;AAEO,MAAM,WAAyB,CACpC,MAAM,IAAI,MAAM,iBAAiB,GACjC,KACA,QAAQ,YACL;AA1PL;AA2PE,SAAO,OAAO,OAAO,IAAI,aAAW,gCAAK,SAAL,mBAAW,YAAW,IAAI,OAAO;AACrE,GAAC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,UAAoB;AAC1D,QAAI,WAAW;AAAO,aAAO,IAAI,KAAK,OAAO,SAAS,MAAM,KAAK;AAAA,CAAK;AACtE,QAAI,UAAU;AACZ,aAAO,IAAI,KAAK,OAAO,aAAS,uBAAa,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;",
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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6CAAiB,EAAE;AAAA,IACzC;AACA,UAAM,aAAa,QAAQ,MAAM,IAAI;AACrC,QAAI,gBAAgB,WAAW,SAAS;AACtC,cAAQ,KAAK;AAAA,GAAM,SAAS,WAAW,SAAS,uBAAuB;AAAA,EAC3E;AACF;AAEO,MAAM,WAAyB,CACpC,MAAM,IAAI,MAAM,iBAAiB,GACjC,KACA,QAAQ,YACL;AA5PL;AA6PE,SAAO,OAAO,OAAO,IAAI,aAAW,gCAAK,SAAL,mBAAW,YAAW,IAAI,OAAO;AACrE,GAAC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,UAAoB;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,GAAG,OAAO,SAAS,KAAK;AAAA,CAAK;AACxC;AAAA,IACF;AACA,QAAI,WAAW;AAAO,aAAO,IAAI,KAAK,OAAO,SAAS,MAAM,KAAK;AAAA,CAAK;AACtE,QAAI,UAAU;AACZ,aAAO,IAAI,KAAK,OAAO,aAAS,uBAAa,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
6
  "names": ["dateFormat", "chalk", "deepCleaner"]
7
7
  }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var yaml_exports = {};
20
+ __export(yaml_exports, {
21
+ parseYaml: () => parseYaml,
22
+ parseYamlDocument: () => parseYamlDocument,
23
+ stringifyYaml: () => stringifyYaml,
24
+ validateWorkflowYaml: () => validateWorkflowYaml
25
+ });
26
+ module.exports = __toCommonJS(yaml_exports);
27
+ var import_core = require("@action-validator/core");
28
+ var import_yaml = require("yaml");
29
+ const parseYaml = import_yaml.parse;
30
+ const parseYamlDocument = import_yaml.parseDocument;
31
+ const stringifyYaml = import_yaml.stringify;
32
+ const validateWorkflowYaml = (yaml) => {
33
+ const { actionType, errors } = (0, import_core.validateWorkflow)(yaml);
34
+ if (actionType && errors.length === 0)
35
+ return true;
36
+ return errors;
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ parseYaml,
41
+ parseYamlDocument,
42
+ stringifyYaml,
43
+ validateWorkflowYaml
44
+ });
45
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/util/yaml.ts"],
4
+ "sourcesContent": ["import { validateWorkflow } from '@action-validator/core';\n\nimport { parse, parseDocument, stringify } from 'yaml';\n\nexport const parseYaml = parse;\nexport const parseYamlDocument = parseDocument;\nexport const stringifyYaml = stringify;\n\nexport const validateWorkflowYaml = (yaml: string) => {\n const { actionType, errors } = validateWorkflow(yaml);\n if (actionType && errors.length === 0) return true;\n return errors;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AAEjC,kBAAgD;AAEzC,MAAM,YAAY;AAClB,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AAEtB,MAAM,uBAAuB,CAAC,SAAiB;AACpD,QAAM,EAAE,YAAY,OAAO,QAAI,8BAAiB,IAAI;AACpD,MAAI,cAAc,OAAO,WAAW;AAAG,WAAO;AAC9C,SAAO;AACT;",
6
+ "names": []
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.0-beta.89";
24
+ const LIB_VERSION = "1.0.0-beta.90";
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.0-beta.89\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.90\";\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.0-beta.89",
3
+ "version": "1.0.0-beta.90",
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/node-cli",
6
6
  "homepage": "https://github.com/contensis/node-cli/tree/main/packages/contensis-cli#readme",
@@ -23,11 +23,13 @@
23
23
  "author": "Zengenti",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
+ "@action-validator/core": "^0.5.3",
26
27
  "app-root-path": "^3.1.0",
27
28
  "chalk": "^4.1.2",
28
29
  "commander": "^9.4.1",
29
30
  "csv": "^6.1.0",
30
31
  "dayjs": "^1.11.6",
32
+ "diff": "^5.1.0",
31
33
  "figlet": "^1.5.2",
32
34
  "flat": "^5.0.2",
33
35
  "giturl": "^2.0.0",
@@ -39,6 +39,7 @@ Example call:
39
39
  > dev init\n`
40
40
  )
41
41
  .action(async (projectHome: string, opts) => {
42
+ // TODO: add opts for overriding project name and git url
42
43
  await devCommand(['dev', 'init', projectHome], opts).DevelopmentInit(
43
44
  projectHome,
44
45
  { ...opts, dryRun: !opts.commit }
@@ -304,11 +304,11 @@ export const LogMessages = {
304
304
  `[${env}] Created role ${Logger.highlightText(name)}\n`,
305
305
  tip: () =>
306
306
  `Give access to your role with "set role assignments", allow your role to do things with "set role permissions"`,
307
- failedCreate: (env: string, name: string) =>
307
+ failedCreate: (env: string, name?: string) =>
308
308
  `[${env}] Unable to create role ${Logger.highlightText(name)}`,
309
309
  setPayload: () => `Updating role with details\n`,
310
310
  set: () => `Succesfully updated role\n`,
311
- failedSet: (env: string, name: string) =>
311
+ failedSet: (env: string, name?: string) =>
312
312
  `[${env}] Unable to update role ${Logger.highlightText(name)}`,
313
313
  removed: (env: string, id: string) =>
314
314
  `[${env}] Deleted role ${Logger.highlightText(id)}\n`,
@@ -447,11 +447,17 @@ Connect to Contensis instance: ${Logger.standardText(env)}
447
447
  !existing ? 'Create deployment API key' : 'Deployment API key found'
448
448
  }: ${Logger[!existing ? 'highlightText' : 'standardText'](name)}`,
449
449
  ciIntro: (git: GitHelper) =>
450
- `We will create API keys with permissions to use this project with Contensis, and add a job to your CI that will deploy a container build. We will ask you to add secrets/variables to your git repository to give your workflow permission to push a Block to Contensis.
451
-
452
- You could visit ${git.secretsUri} to check that you can see repository settings`,
450
+ `We will create API keys with permissions to use this project with Contensis, and add a job to your CI that will deploy a container build.
451
+
452
+ We will ask you to add secrets/variables to your git repository to give your workflow permission to push a Block to Contensis. ${Logger.infoText(
453
+ `You could visit ${git.secretsUri} to check that you can see repository settings, a page not found generally indicates you need to ask the repo owner for permission to add repository secrets, or ask the repo owner to add these secrets for you.`
454
+ )}`,
453
455
  ciDetails: (filename: string) =>
454
456
  `Add push-block job to CI file: ${Logger.highlightText(filename)}\n`,
457
+ ciMultipleChoices: () =>
458
+ `Multiple GitHub workflow files found\n${Logger.infoText(
459
+ `Tell us which GitHub workflow builds the container image after each push:`
460
+ )}`,
455
461
  confirm: () =>
456
462
  `Confirm these details are correct so we can make changes to your project`,
457
463
  accessTokenPrompt: () =>
@@ -480,7 +486,7 @@ You could visit ${git.secretsUri} to check that you can see repository settings`
480
486
  blockId
481
487
  )}`,
482
488
  addGitSecretsIntro: () =>
483
- `We have ceated an API key that allows you to deploy your app image to a Contensis Block but we need you to add these details to your GitLab repository.`,
489
+ `We have created an API key that allows you to deploy your app image to a Contensis Block but we need you to add these details to your GitLab repository.`,
484
490
  addGitSecretsHelp: (git: GitHelper, id?: string, secret?: string) =>
485
491
  `Add secrets or variables in your repository's settings page\n\nGo to ${Logger.highlightText(
486
492
  git.secretsUri
@@ -492,17 +498,21 @@ You could visit ${git.secretsUri} to check that you can see repository settings`
492
498
  git.type === 'github' ? `Secret name:` : `Key:`
493
499
  } ${Logger.highlightText(`CONTENSIS_CLIENT_ID`)}\n ${
494
500
  git.type === 'github' ? `Secret:` : `Value:`
495
- } ${Logger.highlightText(
501
+ } ${Logger.standardText(
496
502
  id
497
503
  )}\n\n ${`Add one more secret/variable to the repository`}\n\n ${
498
504
  git.type === 'github' ? `Secret name:` : `Key:`
499
505
  } ${Logger.highlightText(`CONTENSIS_SHARED_SECRET`)}\n ${
500
506
  git.type === 'github' ? `Secret:` : `Value:`
501
- } ${Logger.highlightText(secret)}`,
507
+ } ${Logger.standardText(secret)}`,
502
508
  success: () => `Contensis developer environment initialisation complete`,
503
509
  partialSuccess: () =>
504
510
  `Contensis developer environment initialisation completed with errors`,
505
511
  failed: () => `Contensis developer environment initialisation failed`,
512
+ dryRun: () =>
513
+ `Contensis developer environment initialisation dry run completed`,
514
+ noChanges: () =>
515
+ `No changes were made to your project - run the command again without the --dry-run flag to update your project with these changes`,
506
516
  startProjectTip: () =>
507
517
  `Start up your project in the normal way for development`,
508
518
  },
@@ -0,0 +1,150 @@
1
+ import { JSONPath, JSONPathOptions } from 'jsonpath-plus';
2
+ import { readFile } from '~/providers/file-provider';
3
+ import ContensisDev from '~/services/ContensisDevService';
4
+ import { diffFileContent } from '~/util/diff';
5
+ import { GitHelper } from '~/util/git';
6
+ import { logError } from '~/util/logger';
7
+ import { parseYamlDocument, validateWorkflowYaml } from '~/util/yaml';
8
+
9
+ type MappedWorkflowOutput = {
10
+ existingWorkflow: string;
11
+ newWorkflow: string;
12
+ diff: string;
13
+ };
14
+
15
+ export const mapCIWorkflowContent = (
16
+ cli: ContensisDev,
17
+ git: GitHelper
18
+ ): MappedWorkflowOutput | undefined => {
19
+ // get existing workflow file
20
+ const workflowFile = readFile(git.ciFilePath);
21
+ if (!workflowFile) return undefined;
22
+
23
+ const blockId = git.name;
24
+ if (git.type === 'github') {
25
+ const addGitHubActionJobStep = {
26
+ name: 'Push block to Contensis',
27
+ id: 'push-block',
28
+ uses: 'contensis/block-push@v1',
29
+ with: {
30
+ 'block-id': blockId,
31
+ // 'image-uri': '${{ steps.build.outputs.image-uri }}',
32
+ alias: cli.currentEnv,
33
+ 'project-id': cli.currentProject,
34
+ 'client-id': '${{ secrets.CONTENSIS_CLIENT_ID }}',
35
+ 'shared-secret': '${{ secrets.CONTENSIS_SHARED_SECRET }}',
36
+ },
37
+ };
38
+
39
+ // parse yaml to js
40
+ const workflowDoc = parseYamlDocument(workflowFile);
41
+ const workflow = workflowDoc.toJS();
42
+ const setWorkflowElement = (path: string | any[], value: any) => {
43
+ const findPath =
44
+ typeof path === 'string' && path.includes('.')
45
+ ? path
46
+ .split('.')
47
+ .map(p => (Number(p) || Number(p) !== 0 ? p : Number(p)))
48
+ : path;
49
+
50
+ if (workflowDoc.hasIn(findPath)) {
51
+ workflowDoc.setIn(findPath, value);
52
+ } else {
53
+ workflowDoc.addIn(findPath, value);
54
+ // }
55
+ }
56
+ };
57
+ const findExistingJobSteps = (
58
+ resultType: JSONPathOptions['resultType']
59
+ ) => {
60
+ // look for line in job
61
+ // jobs.x.steps[uses: contensis/block-push]
62
+ const path =
63
+ git.type === 'github'
64
+ ? '$.jobs..steps.*[?(@property === "uses" && @.match(/^contensis\\/block-push/i))]^'
65
+ : // TODO: add jsonpath for gitlab file
66
+ '';
67
+
68
+ const existingJobStep = JSONPath({
69
+ path,
70
+ json: workflow,
71
+ resultType: resultType,
72
+ });
73
+
74
+ return existingJobStep;
75
+ };
76
+
77
+ const existingJobStep = findExistingJobSteps('all');
78
+
79
+ // update job step
80
+ if (existingJobStep.length) {
81
+ //cli.log.json(existingJobStep);
82
+
83
+ // The [0] index means we're only looking at updating the first instance in the file
84
+ const step = existingJobStep[0];
85
+
86
+ // Path looks like this "$['jobs']['build']['steps'][3]"
87
+ // We want it to look like this "jobs.build.steps.3"
88
+ const stepPath = step.path
89
+ .replace('$[', '')
90
+ .replaceAll('][', '.')
91
+ .replace(']', '')
92
+ .replaceAll("'", '');
93
+
94
+ cli.log.info(
95
+ `Found existing Job step: ${stepPath}
96
+ - name: ${step.value.name}
97
+ id: ${step.value.id}\n`
98
+ );
99
+
100
+ setWorkflowElement(`${stepPath}.with.alias`, cli.currentEnv);
101
+ setWorkflowElement(`${stepPath}.with.project-id`, cli.currentProject);
102
+ setWorkflowElement(`${stepPath}.with.block-id`, blockId);
103
+ setWorkflowElement(
104
+ `${stepPath}.with.client-id`,
105
+ '${{ secrets.CONTENSIS_CLIENT_ID }}'
106
+ );
107
+ setWorkflowElement(
108
+ `${stepPath}.with.shared-secret`,
109
+ '${{ secrets.CONTENSIS_SHARED_SECRET }}'
110
+ );
111
+ } else {
112
+ // create job with push step
113
+ workflowDoc.addIn(['jobs'], {
114
+ key: 'deploy',
115
+ value: {
116
+ name: 'Push image to Contensis',
117
+ 'runs-on': 'ubuntu-latest',
118
+ steps: [addGitHubActionJobStep],
119
+ },
120
+ });
121
+ }
122
+
123
+ // Workflow validation provided by @action-validator/core package
124
+ const workflowIsValid = validateWorkflowYaml(workflowDoc.toString());
125
+
126
+ if (workflowIsValid === true) {
127
+ cli.log.debug(
128
+ `New file content to write to ${git.ciFilePath}\n\n${workflowDoc}`
129
+ );
130
+ } else if (Array.isArray(workflowIsValid)) {
131
+ // Errors
132
+ logError(
133
+ [
134
+ ...workflowIsValid.map(
135
+ res => new Error(`${res.code}: ${res.detail || res.title}`)
136
+ ),
137
+ workflowDoc.toString(),
138
+ ],
139
+ `GitHub workflow YAML did not pass validation check`
140
+ );
141
+ }
142
+ const newWorkflow = workflowDoc.toString({ lineWidth: 0 });
143
+
144
+ return {
145
+ existingWorkflow: workflowFile,
146
+ newWorkflow,
147
+ diff: diffFileContent(workflowFile, newWorkflow),
148
+ };
149
+ }
150
+ };
@@ -0,0 +1,33 @@
1
+ import { Role } from 'contensis-management-api/lib/models';
2
+
3
+ export const devKeyPermissions = { blocks: [] } as Partial<Role['permissions']>;
4
+
5
+ export const deployKeyPermissions = { blocks: ['push', 'release'] } as Partial<
6
+ Role['permissions']
7
+ >;
8
+
9
+ export const devKeyRole = (
10
+ keyName: string,
11
+ description: string
12
+ ): Partial<Role> => ({
13
+ name: keyName,
14
+ description,
15
+ assignments: {
16
+ apiKeys: [keyName],
17
+ },
18
+ permissions: devKeyPermissions,
19
+ enabled: true,
20
+ });
21
+
22
+ export const deployKeyRole = (
23
+ keyName: string,
24
+ description: string
25
+ ): Partial<Role> => ({
26
+ name: keyName,
27
+ description,
28
+ assignments: {
29
+ apiKeys: [keyName],
30
+ },
31
+ permissions: deployKeyPermissions,
32
+ enabled: true,
33
+ });
@@ -0,0 +1,44 @@
1
+ import ContensisCli from '~/services/ContensisCliService';
2
+
3
+ interface ISiteConfigYaml {
4
+ alias: string;
5
+ projectId: string;
6
+ accessToken: string;
7
+ clientId: string;
8
+ sharedSecret: string;
9
+ blocks: {
10
+ id: string;
11
+ baseUri: string;
12
+ }[];
13
+ }
14
+
15
+ export const mapSiteConfigYaml = async (cli: ContensisCli) => {
16
+ const credentials = await cli.GetCredentials(cli.env.lastUserId);
17
+
18
+ const blocks = [];
19
+ const blocksRaw = await cli.PrintBlocks();
20
+
21
+ for (const block of blocksRaw || []) {
22
+ const versions = await cli.PrintBlockVersions(
23
+ block.id,
24
+ 'default',
25
+ 'latest'
26
+ );
27
+ if (versions?.[0]) {
28
+ blocks.push({
29
+ id: versions[0].id,
30
+ baseUri: versions[0].previewUrl,
31
+ });
32
+ }
33
+ }
34
+
35
+ const siteConfig: ISiteConfigYaml = {
36
+ alias: cli.currentEnv,
37
+ projectId: cli.currentProject,
38
+ accessToken: '',
39
+ clientId: credentials?.current?.account || '',
40
+ sharedSecret: credentials?.current?.password || '',
41
+ blocks,
42
+ };
43
+ return siteConfig;
44
+ };
@@ -0,0 +1,5 @@
1
+ export type EnvContentsToAdd = {
2
+ ALIAS: string;
3
+ PROJECT: string;
4
+ ACCESS_TOKEN?: string;
5
+ }