github-action-readme-generator 1.10.10 → 1.11.0

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 (39) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/mjs/constants.d.ts +3 -3
  3. package/dist/mjs/helpers.js.map +1 -1
  4. package/dist/mjs/inputs.js.map +1 -1
  5. package/dist/mjs/logtask/index.js.map +1 -1
  6. package/dist/mjs/prettier.js.map +1 -1
  7. package/dist/mjs/readme-editor.js.map +1 -1
  8. package/dist/mjs/readme-generator.js.map +1 -1
  9. package/dist/mjs/sections/index.js.map +1 -1
  10. package/dist/mjs/sections/update-branding.js.map +1 -1
  11. package/dist/mjs/svg-editor.mjs.map +1 -1
  12. package/dist/types/Action.d.ts +154 -0
  13. package/dist/types/config.d.ts +47 -0
  14. package/dist/types/constants.d.ts +105 -0
  15. package/dist/types/errors/error-type.d.ts +7 -0
  16. package/dist/types/errors/is-error.d.ts +8 -0
  17. package/dist/types/helpers.d.ts +93 -0
  18. package/dist/types/index.d.ts +4 -1106
  19. package/dist/types/inputs.d.ts +153 -0
  20. package/dist/types/logtask/index.d.ts +95 -0
  21. package/dist/types/markdowner/index.d.ts +61 -0
  22. package/dist/types/prettier.d.ts +31 -0
  23. package/dist/types/readme-editor.d.ts +50 -0
  24. package/dist/types/readme-generator.d.ts +57 -0
  25. package/dist/types/save.d.ts +13 -0
  26. package/dist/types/sections/index.d.ts +11 -0
  27. package/dist/types/sections/update-badges.d.ts +16 -0
  28. package/dist/types/sections/update-branding.d.ts +55 -0
  29. package/dist/types/sections/update-contents.d.ts +9 -0
  30. package/dist/types/sections/update-description.d.ts +10 -0
  31. package/dist/types/sections/update-inputs.d.ts +10 -0
  32. package/dist/types/sections/update-outputs.d.ts +11 -0
  33. package/dist/types/sections/update-title.d.ts +10 -0
  34. package/dist/types/sections/update-usage.d.ts +3 -0
  35. package/dist/types/svg-editor.d.mts +47 -0
  36. package/dist/types/unicode-word-match.d.ts +1 -0
  37. package/dist/types/util.d.ts +2 -0
  38. package/dist/types/working-directory.d.ts +6 -0
  39. package/package.json +3 -4
@@ -1 +1 @@
1
- {"version":3,"file":"update-branding.js","sourceRoot":"","sources":["../../../src/sections/update-branding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAsB,MAAM,iBAAiB,CAAC;AAEhG,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAgB1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAe,EACf,IAA+B,EAC/B,OAA6B;IAE7B,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAgC;IAC/D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,4BAA4B,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,sCAAsC,IAAI,yCAAyC,CACpF,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CACb,sCAAsC,IAAI,kDAAkD,CAC7F,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,QAAgB,KAAK;IACrE,kCAAkC;IAClC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC5B,GAAG,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AAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAErE,GAAG,CAAC,KAAK,EAAE,CAAC;IACZ,wDAAwD;IACxD,MAAM,UAAU,GAAG,KAAK,CAAC;IACzB,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACtD,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,OAAO,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAC9B,GAAG,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;IACnD,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,GAAG,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC;IAC5B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { FeatherIconNames } from 'feather-icons';\n\nimport type { BrandColors } from '../constants.js';\nimport { GITHUB_ACTIONS_OMITTED_ICONS, isValidIcon, type ReadmeSection } from '../constants.js';\nimport type Inputs from '../inputs.js';\nimport LogTask from '../logtask/index.js';\nimport SVGEditor from '../svg-editor.mjs';\n\n/**\n * Wiith thanks to\n * https://github.com/haya14busa/github-action-brandings/blob/master/main.js\n * for the urls to the branding images.\n */\n\ntype Maybe<T> = T | undefined;\n\nexport interface IBranding {\n alt: string;\n img: string;\n url?: string;\n}\n\n/**\n * Generates a svg branding image.\n * example:\n * ```ts\n * generateSvgImage('/path/to/file.svg', 'home', 'red')\n * ```\n *\n * @param svgPath - The path to where the svg file will be saved\n * @param icon - The icon name from the feather-icons list\n * @param bgcolor - The background color of the circle behind the icon\n */\nexport function generateSvgImage(\n svgPath: string,\n icon: Partial<FeatherIconNames>,\n bgcolor: Partial<BrandColors>,\n): void {\n const svgEditor = new SVGEditor();\n svgEditor.generateSvgImage(svgPath, icon, bgcolor);\n}\n\n/**\n * This function returns a valid icon name based on the provided branding.\n * If the branding is undefined or not a valid icon name, an error is thrown.\n * It checks if the branding icon is present in the GITHUB_ACTIONS_BRANDING_ICONS set,\n * and if so, returns the corresponding feather icon key array.\n * If the branding icon is present in the GITHUB_ACTIONS_OMITTED_ICONS set,\n * an error is thrown specifying that the icon is part of the omitted icons list.\n * If the branding icon is not a valid icon from the feather-icons list, an error is thrown.\n * @param brand - The branding object\n * @returns The corresponding feather icon key array\n * @throws Error if the branding icon is undefined, not a valid icon name, or part of the omitted icons list\n */\nexport function getValidIconName(icon?: Partial<FeatherIconNames>): FeatherIconNames {\n if (!icon) {\n throw new Error(`No valid branding icon name found: action.yml branding is undefined`);\n }\n\n if (isValidIcon(icon)) {\n return icon;\n }\n\n if (GITHUB_ACTIONS_OMITTED_ICONS.has(icon)) {\n throw new Error(\n `No valid branding icon name found: ${icon} is part of the list of omitted icons. `,\n );\n }\n\n throw new Error(\n `No valid branding icon name found: ${icon} is not a valid icon from the feather-icons list`,\n );\n}\n\n/**\n * This function generates an HTML image markup with branding information.\n * It takes inputs and an optional width parameter.\n * If the branding_svg_path is provided, it generates an action.yml branding image for the specified icon and color.\n * Otherwise, it returns an error message.\n *\n * @param inputs - The inputs instance with data for the function.\n * @param width - The width of the image (default is '15%').\n * @returns The HTML image markup with branding information or an error message.\n */\nexport function generateImgMarkup(inputs: Inputs, width: string = '15%'): string {\n // Create a log task for debugging\n const log = new LogTask('generateImgMarkup');\n if (!inputs.action.branding) {\n log.info('No branding section');\n return '';\n }\n // Get the branding information from the inputs\n const { icon, color } = inputs.action.branding;\n const iconName = getValidIconName(icon);\n const svgPath = inputs.config.get('branding_svg_path') as Maybe<string>;\n const result = `<img src=\"${svgPath}\" width=\"${width}\" align=\"center\" alt=\"branding<icon:${iconName} color:${color}>\" />`;\n\n if (svgPath) {\n log.info(`Generating action.yml branding image for ${iconName}`);\n const svg = inputs.config.get('image_generated') as Maybe<string>;\n const hash = `${iconName}${color}`;\n if (svg && hash.localeCompare(svg) !== 0) {\n generateSvgImage(svgPath, iconName, color);\n inputs.config.set('image_generated', hash);\n }\n return result;\n }\n log.error(`No branding_svg_path provided or it is empty string, can't create the file!`);\n return `<!-- ERROR: no branding path found = ${result} -->`;\n}\n\n/**\n * This is a TypeScript function named \"updateBranding\" that takes in a sectionToken string and an object of inputs.\n * It exports the function as the default export.\n * The function logs the brand details from the inputs, starts a log task, generates image markup,\n * updates a section in the readme editor using the sectionToken and content, and logs success or failure messages.\n *\n * @param sectionToken - The sectionToken string that is used to identify the section in the readme editor.\n * @param inputs - The inputs object that contains data for the function.\n */\nexport default function updateBranding(\n sectionToken: ReadmeSection,\n inputs: Inputs,\n): Record<string, string> {\n const log = new LogTask(sectionToken);\n\n log.info(`Brand details: ${JSON.stringify(inputs.action.branding)}`);\n\n log.start();\n /** create <img /> markup with an image width of 15% */\n const imageWidth = '15%';\n const content = generateImgMarkup(inputs, imageWidth);\n inputs.readmeEditor.updateSection(sectionToken, content);\n if (content && content !== '') {\n log.success('branding svg successfully created');\n } else {\n log.fail('branding svg failed to be created');\n }\n\n const ret: Record<string, string> = {};\n ret[sectionToken] = content;\n return ret;\n}\n"]}
1
+ {"version":3,"file":"update-branding.js","sourceRoot":"","sources":["../../../src/sections/update-branding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAsB,MAAM,iBAAiB,CAAC;AAEhG,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAgB1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAe,EACf,IAA+B,EAC/B,OAA6B;IAE7B,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAgC;IA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 'feather-icons';\n\nimport type { BrandColors } from '../constants.js';\nimport { GITHUB_ACTIONS_OMITTED_ICONS, isValidIcon, type ReadmeSection } from '../constants.js';\nimport type Inputs from '../inputs.js';\nimport LogTask from '../logtask/index.js';\nimport SVGEditor from '../svg-editor.mjs';\n\n/**\n * Wiith thanks to\n * https://github.com/haya14busa/github-action-brandings/blob/master/main.js\n * for the urls to the branding images.\n */\n\ntype Maybe<T> = T | undefined;\n\nexport interface IBranding {\n alt: string;\n img: string;\n url?: string;\n}\n\n/**\n * Generates a svg branding image.\n * example:\n * ```ts\n * generateSvgImage('/path/to/file.svg', 'home', 'red')\n * ```\n *\n * @param svgPath - The path to where the svg file will be saved\n * @param icon - The icon name from the feather-icons list\n * @param bgcolor - The background color of the circle behind the icon\n */\nexport function generateSvgImage(\n svgPath: string,\n icon: Partial<FeatherIconNames>,\n bgcolor: Partial<BrandColors>,\n): void {\n const svgEditor = new SVGEditor();\n svgEditor.generateSvgImage(svgPath, icon, bgcolor);\n}\n\n/**\n * This function returns a valid icon name based on the provided branding.\n * If the branding is undefined or not a valid icon name, an error is thrown.\n * It checks if the branding icon is present in the GITHUB_ACTIONS_BRANDING_ICONS set,\n * and if so, returns the corresponding feather icon key array.\n * If the branding icon is present in the GITHUB_ACTIONS_OMITTED_ICONS set,\n * an error is thrown specifying that the icon is part of the omitted icons list.\n * If the branding icon is not a valid icon from the feather-icons list, an error is thrown.\n * @param brand - The branding object\n * @returns The corresponding feather icon key array\n * @throws Error if the branding icon is undefined, not a valid icon name, or part of the omitted icons list\n */\nexport function getValidIconName(icon?: Partial<FeatherIconNames>): FeatherIconNames {\n if (!icon) {\n throw new Error(`No valid branding icon name found: action.yml branding is undefined`);\n }\n\n if (isValidIcon(icon)) {\n return icon;\n }\n\n if (GITHUB_ACTIONS_OMITTED_ICONS.has(icon)) {\n throw new Error(\n `No valid branding icon name found: ${icon} is part of the list of omitted icons. `,\n );\n }\n\n throw new Error(\n `No valid branding icon name found: ${icon} is not a valid icon from the feather-icons list`,\n );\n}\n\n/**\n * This function generates an HTML image markup with branding information.\n * It takes inputs and an optional width parameter.\n * If the branding_svg_path is provided, it generates an action.yml branding image for the specified icon and color.\n * Otherwise, it returns an error message.\n *\n * @param inputs - The inputs instance with data for the function.\n * @param width - The width of the image (default is '15%').\n * @returns The HTML image markup with branding information or an error message.\n */\nexport function generateImgMarkup(inputs: Inputs, width: string = '15%'): string {\n // Create a log task for debugging\n const log = new LogTask('generateImgMarkup');\n if (!inputs.action.branding) {\n log.info('No branding section');\n return '';\n }\n // Get the branding information from the inputs\n const { icon, color } = inputs.action.branding;\n const iconName = getValidIconName(icon);\n const svgPath = inputs.config.get('branding_svg_path') as Maybe<string>;\n const result = `<img src=\"${svgPath}\" width=\"${width}\" align=\"center\" alt=\"branding<icon:${iconName} color:${color}>\" />`;\n\n if (svgPath) {\n log.info(`Generating action.yml branding image for ${iconName}`);\n const svg = inputs.config.get('image_generated') as Maybe<string>;\n const hash = `${iconName}${color}`;\n if (svg && hash.localeCompare(svg) !== 0) {\n generateSvgImage(svgPath, iconName, color);\n inputs.config.set('image_generated', hash);\n }\n return result;\n }\n log.error(`No branding_svg_path provided or it is empty string, can't create the file!`);\n return `<!-- ERROR: no branding path found = ${result} -->`;\n}\n\n/**\n * This is a TypeScript function named \"updateBranding\" that takes in a sectionToken string and an object of inputs.\n * It exports the function as the default export.\n * The function logs the brand details from the inputs, starts a log task, generates image markup,\n * updates a section in the readme editor using the sectionToken and content, and logs success or failure messages.\n *\n * @param sectionToken - The sectionToken string that is used to identify the section in the readme editor.\n * @param inputs - The inputs object that contains data for the function.\n */\nexport default function updateBranding(\n sectionToken: ReadmeSection,\n inputs: Inputs,\n): Record<string, string> {\n const log = new LogTask(sectionToken);\n\n log.info(`Brand details: ${JSON.stringify(inputs.action.branding)}`);\n\n log.start();\n /** create <img /> markup with an image width of 15% */\n const imageWidth = '15%';\n const content = generateImgMarkup(inputs, imageWidth);\n inputs.readmeEditor.updateSection(sectionToken, content);\n if (content && content !== '') {\n log.success('branding svg successfully created');\n } else {\n log.fail('branding svg failed to be created');\n }\n\n const ret: Record<string, string> = {};\n ret[sectionToken] = content;\n return ret;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"svg-editor.mjs","sourceRoot":"","sources":["../../src/svg-editor.mts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAoC,MAAM,QAAQ,CAAC,CAAC,oBAAoB;AAGhG,OAAO,EACL,gCAAgC,EAChC,mBAAmB,EACnB,kBAAkB,EAClB,8BAA8B,EAC9B,6BAA6B,EAC7B,YAAY,EACZ,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,SAAS;IACpB,GAAG,CAAU;IAEb,MAAM,CAAa;IAEnB,MAAM,CAAa;IAEnB,QAAQ,CAAe;IAE/B;;OAEG;IACH;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;YAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YACjC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACtC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACjB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAc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,CAAC;QAExB,wDAAwD;QACxD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACrC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAEtF,gEAAgE;QAChE,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QACtC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEzC,oDAAoD;QACpD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,6DAA6D;QAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAE9D,2BAA2B;QAC3B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEpC,qEAAqE;QACrE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhC,6DAA6D;QAC7D,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAErC,8BAA8B;QAC9B,OAAO,CAAC,wDAAwD,EAAE,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,IAAI,CACxF,IAAI,CACL,CAAC;IACJ,CAAC;CACF","sourcesContent":["/**\n * This TypeScript code imports necessary modules and defines a class named 'SVGEditor' for generating SVG images.\n * The class has methods for initializing the SVG window, generating SVG content, and writing SVG files.\n * It utilizes various packages such as 'fs', 'path', '@svgdotjs/svg.js', 'feather-icons', and 'svgdom' for SVG manipulation and file operations.\n * The class also defines interfaces for badges and brand colors.\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { Container } from '@svgdotjs/svg.js';\nimport { registerWindow, SVG } from '@svgdotjs/svg.js';\nimport type { FeatherIconNames } from 'feather-icons';\nimport * as feather from 'feather-icons';\nimport { createSVGWindow, type SVGDocument, type SVGWindow } from 'svgdom'; /// main-module.js';\n\nimport type { BrandColors } from './constants.js';\nimport {\n brandingSquareEdgeLengthInPixels,\n DEFAULT_BRAND_COLOR,\n DEFAULT_BRAND_ICON,\n GITHUB_ACTIONS_BRANDING_COLORS,\n GITHUB_ACTIONS_BRANDING_ICONS,\n isValidColor,\n isValidIcon,\n} from './constants.js';\nimport LogTask from './logtask/index.js';\n\n/**\n * Utility class for generating SVG images.\n */\n\nexport default class SVGEditor {\n private log: LogTask;\n\n private window?: SVGWindow;\n\n private canvas?: Container;\n\n private document?: SVGDocument;\n\n /**\n * Initializes a new SVGEditor instance.\n */\n constructor() {\n this.log = new LogTask('SVGEditor');\n }\n\n /**\n * Initializes the SVG window, document, and canvas if not already set up.\n */\n initSVG(): void {\n if (!this.window) {\n this.window = createSVGWindow();\n const { document } = this.window;\n registerWindow(this.window, document);\n if (!this.canvas) {\n this.canvas = SVG(document.documentElement) as Container;\n }\n }\n }\n\n /**\n * Generates a branded SVG image.\n * @param {string | undefined} svgPath - Path to write the generated SVG file to.\n * @param {Partial<FeatherIconNames>} icon - Name of the icon to use.\n * @param {Partial<BrandColors>} bgcolor - Background color for the image.\n * @returns {Promise<void>} A promise that resolves when the image is generated.\n */\n generateSvgImage(\n svgPath: string | undefined,\n icon: Partial<FeatherIconNames> = DEFAULT_BRAND_ICON,\n bgcolor: Partial<BrandColors> = DEFAULT_BRAND_COLOR\n ): void {\n if (!svgPath || svgPath.length === 0) {\n this.log.debug('No svgPath provided');\n return;\n }\n\n if (!isValidIcon(icon)) {\n this.log.error(`Valid Branding Icon Names: ${GITHUB_ACTIONS_BRANDING_ICONS}`);\n this.log.fail(`Invalid icon name: ${icon}`);\n return;\n }\n if (!isValidColor(bgcolor)) {\n this.log.error(`Valid Branding Colors: ${GITHUB_ACTIONS_BRANDING_COLORS}`);\n this.log.fail('Invalid branding color');\n return;\n }\n this.log.info(`SVG to generate ${icon} at ${svgPath} with color ${bgcolor}.`);\n // Initialize SVG\n this.initSVG();\n // Generate SVG content\n const svgContent = this.generateSVGContent(icon, bgcolor);\n\n // Write SVG file\n this.writeSVGFile(svgPath, svgContent);\n\n this.log.debug('SVG image generated successfully');\n }\n\n /**\n * Writes the SVG xml to disk.\n * @param {string} svgPath - File path to save the SVG to.\n * @param {string} svgContent - The XML for the SVG file.\n */\n writeSVGFile(svgPath: string, svgContent: string): void {\n fs.mkdirSync(path.dirname(svgPath), { recursive: true });\n this.log.debug(`Writing SVG file to ${svgPath}`);\n fs.writeFile(svgPath, svgContent, 'utf8', () => {\n return this.log.debug(`SVG image generated: ${svgPath}`);\n });\n }\n\n /**\n * Generates the SVG content for the branding image.\n * @param {FeatherIconNames} icon - Name of the icon to use.\n * @param {BrandColors} color - Background color for the image.\n * @param {number} outerViewBox - Size of the canvas for the image.\n * @returns {string} The generated SVG content.\n */\n generateSVGContent(\n icon: FeatherIconNames,\n color: BrandColors,\n outerViewBox: number = 100\n ): string {\n const { canvas, log } = this;\n // Validate canvas\n if (!canvas) {\n log.fail('Canvas not initialized');\n return '';\n }\n\n const svgData = feather.icons[icon];\n log.debug(`SVG data to ingest: ${svgData.toSvg()}`);\n\n canvas.clear();\n\n // Create a canvas that is `outerViewBox` x `outerViewBox`\n canvas\n .size(brandingSquareEdgeLengthInPixels, brandingSquareEdgeLengthInPixels)\n .viewbox(`0 0 ${outerViewBox} ${outerViewBox}`)\n .fill('none');\n\n // Create a 'color' circle that touches the edges of the canvas\n const circleSize = outerViewBox / 2;\n canvas\n .circle('50%')\n .fill(color)\n .radius(circleSize)\n .cx(circleSize)\n .cy(circleSize)\n .stroke({ width: 0 });\n\n // Create an svg box that is half the size of the parent\n const iconsvgOuter = canvas.nested();\n iconsvgOuter.attr('overflow', 'visible').height('50%').width('50%').x('25%').y('25%');\n\n // create a nested svg and add the feather-icon paths to the svg\n const iconsvg = iconsvgOuter.nested();\n iconsvg.id('icon').svg(svgData.contents);\n\n // Append all of the attributes from the fether-icon\n for (const attr of Object.keys(svgData.attrs)) {\n iconsvg.attr(attr, svgData.attrs[attr]);\n }\n\n // invert the stroke color if it matches the background color\n iconsvg.stroke(color.startsWith('white') ? 'white' : 'black');\n\n // remove the edge clipping\n iconsvg.attr('overflow', 'visible');\n\n // Make the viewbox of the svg match the exact dimensions of the icon\n iconsvg.viewbox(iconsvg.bbox());\n\n // Make the svg icon center itself vertically and horozonally\n iconsvg.height('auto').width('auto');\n\n // return the xml file content\n return ['<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>', canvas.svg(), '\\n'].join(\n '\\n'\n );\n }\n}\n"]}
1
+ {"version":3,"file":"svg-editor.mjs","sourceRoot":"","sources":["../../src/svg-editor.mts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAoC,MAAM,QAAQ,CAAC,CAAC,oBAAoB;AAGhG,OAAO,EACL,gCAAgC,EAChC,mBAAmB,EACnB,kBAAkB,EAClB,8BAA8B,EAC9B,6BAA6B,EAC7B,YAAY,EACZ,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC;;GAEG;AAEH,MAAM,CAAC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AAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAE9D,2BAA2B;QAC3B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEpC,qEAAqE;QACrE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhC,6DAA6D;QAC7D,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAErC,8BAA8B;QAC9B,OAAO,CAAC,wDAAwD,EAAE,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,IAAI,CACxF,IAAI,CACL,CAAC;IACJ,CAAC;CACF","sourcesContent":["/**\n * This TypeScript code imports necessary modules and defines a class named 'SVGEditor' for generating SVG images.\n * The class has methods for initializing the SVG window, generating SVG content, and writing SVG files.\n * It utilizes various packages such as 'fs', 'path', '@svgdotjs/svg.js', 'feather-icons', and 'svgdom' for SVG manipulation and file operations.\n * The class also defines interfaces for badges and brand colors.\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { Container } from '@svgdotjs/svg.js';\nimport { registerWindow, SVG } from '@svgdotjs/svg.js';\nimport type { FeatherIconNames } from 'feather-icons';\nimport * as feather from 'feather-icons';\nimport { createSVGWindow, type SVGDocument, type SVGWindow } from 'svgdom'; /// main-module.js';\n\nimport type { BrandColors } from './constants.js';\nimport {\n brandingSquareEdgeLengthInPixels,\n DEFAULT_BRAND_COLOR,\n DEFAULT_BRAND_ICON,\n GITHUB_ACTIONS_BRANDING_COLORS,\n GITHUB_ACTIONS_BRANDING_ICONS,\n isValidColor,\n isValidIcon,\n} from './constants.js';\nimport LogTask from './logtask/index.js';\n\n/**\n * Utility class for generating SVG images.\n */\n\nexport default class SVGEditor {\n private log: LogTask;\n\n private window?: SVGWindow;\n\n private canvas?: Container;\n\n private document?: SVGDocument;\n\n /**\n * Initializes a new SVGEditor instance.\n */\n constructor() {\n this.log = new LogTask('SVGEditor');\n }\n\n /**\n * Initializes the SVG window, document, and canvas if not already set up.\n */\n initSVG(): void {\n if (!this.window) {\n this.window = createSVGWindow();\n const { document } = this.window;\n registerWindow(this.window, document);\n if (!this.canvas) {\n this.canvas = SVG(document.documentElement) as Container;\n }\n }\n }\n\n /**\n * Generates a branded SVG image.\n * @param {string | undefined} svgPath - Path to write the generated SVG file to.\n * @param {Partial<FeatherIconNames>} icon - Name of the icon to use.\n * @param {Partial<BrandColors>} bgcolor - Background color for the image.\n * @returns {Promise<void>} A promise that resolves when the image is generated.\n */\n generateSvgImage(\n svgPath: string | undefined,\n icon: Partial<FeatherIconNames> = DEFAULT_BRAND_ICON,\n bgcolor: Partial<BrandColors> = DEFAULT_BRAND_COLOR\n ): void {\n if (!svgPath || svgPath.length === 0) {\n this.log.debug('No svgPath provided');\n return;\n }\n\n if (!isValidIcon(icon)) {\n this.log.error(`Valid Branding Icon Names: ${GITHUB_ACTIONS_BRANDING_ICONS}`);\n this.log.fail(`Invalid icon name: ${icon}`);\n return;\n }\n if (!isValidColor(bgcolor)) {\n this.log.error(`Valid Branding Colors: ${GITHUB_ACTIONS_BRANDING_COLORS}`);\n this.log.fail('Invalid branding color');\n return;\n }\n this.log.info(`SVG to generate ${icon} at ${svgPath} with color ${bgcolor}.`);\n // Initialize SVG\n this.initSVG();\n // Generate SVG content\n const svgContent = this.generateSVGContent(icon, bgcolor);\n\n // Write SVG file\n this.writeSVGFile(svgPath, svgContent);\n\n this.log.debug('SVG image generated successfully');\n }\n\n /**\n * Writes the SVG xml to disk.\n * @param {string} svgPath - File path to save the SVG to.\n * @param {string} svgContent - The XML for the SVG file.\n */\n writeSVGFile(svgPath: string, svgContent: string): void {\n fs.mkdirSync(path.dirname(svgPath), { recursive: true });\n this.log.debug(`Writing SVG file to ${svgPath}`);\n fs.writeFile(svgPath, svgContent, 'utf8', () => {\n return this.log.debug(`SVG image generated: ${svgPath}`);\n });\n }\n\n /**\n * Generates the SVG content for the branding image.\n * @param {FeatherIconNames} icon - Name of the icon to use.\n * @param {BrandColors} color - Background color for the image.\n * @param {number} outerViewBox - Size of the canvas for the image.\n * @returns {string} The generated SVG content.\n */\n generateSVGContent(\n icon: FeatherIconNames,\n color: BrandColors,\n outerViewBox: number = 100\n ): string {\n const { canvas, log } = this;\n // Validate canvas\n if (!canvas) {\n log.fail('Canvas not initialized');\n return '';\n }\n\n const svgData = feather.icons[icon];\n log.debug(`SVG data to ingest: ${svgData.toSvg()}`);\n\n canvas.clear();\n\n // Create a canvas that is `outerViewBox` x `outerViewBox`\n canvas\n .size(brandingSquareEdgeLengthInPixels, brandingSquareEdgeLengthInPixels)\n .viewbox(`0 0 ${outerViewBox} ${outerViewBox}`)\n .fill('none');\n\n // Create a 'color' circle that touches the edges of the canvas\n const circleSize = outerViewBox / 2;\n canvas\n .circle('50%')\n .fill(color)\n .radius(circleSize)\n .cx(circleSize)\n .cy(circleSize)\n .stroke({ width: 0 });\n\n // Create an svg box that is half the size of the parent\n const iconsvgOuter = canvas.nested();\n iconsvgOuter.attr('overflow', 'visible').height('50%').width('50%').x('25%').y('25%');\n\n // create a nested svg and add the feather-icon paths to the svg\n const iconsvg = iconsvgOuter.nested();\n iconsvg.id('icon').svg(svgData.contents);\n\n // Append all of the attributes from the fether-icon\n for (const attr of Object.keys(svgData.attrs)) {\n iconsvg.attr(attr, svgData.attrs[attr]);\n }\n\n // invert the stroke color if it matches the background color\n iconsvg.stroke(color.startsWith('white') ? 'white' : 'black');\n\n // remove the edge clipping\n iconsvg.attr('overflow', 'visible');\n\n // Make the viewbox of the svg match the exact dimensions of the icon\n iconsvg.viewbox(iconsvg.bbox());\n\n // Make the svg icon center itself vertically and horozonally\n iconsvg.height('auto').width('auto');\n\n // return the xml file content\n return ['<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>', canvas.svg(), '\\n'].join(\n '\\n'\n );\n }\n}\n"]}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * This class represents the metadata of a GitHub action defined in the action.yml file.
3
+ * It provides properties and methods for accessing and manipulating the metadata.
4
+ * [Further reading on the metadata can be found here](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs)
5
+ */
6
+ import { type Branding } from './constants.js';
7
+ import LogTask from './logtask/index.js';
8
+ /**
9
+ * Represents an input for the action.
10
+ */
11
+ export type Input = {
12
+ /** Description of the input */
13
+ description: string;
14
+ /** Whether the input is required */
15
+ required?: boolean;
16
+ /** Default value for the input */
17
+ default?: string;
18
+ /** Optional If the input parameter is used, this string is this.logged as a warning message. You can use this warning to notify users that the input is deprecated and mention any alternatives. */
19
+ deprecationMessage?: string;
20
+ };
21
+ /**
22
+ * Represents an output for the action.
23
+ */
24
+ export interface Output {
25
+ /** Description of the output */
26
+ description?: string;
27
+ value?: string;
28
+ }
29
+ type CompositeAction = 'composite';
30
+ type ContainerAction = 'docker';
31
+ type JavascriptAction = `Node${string}` | `node${string}`;
32
+ /**
33
+ * Defines the runs property for container actions.
34
+ */
35
+ type RunsContainer = {
36
+ using: ContainerAction;
37
+ image: string;
38
+ args?: string[];
39
+ 'pre-entrypoint'?: string;
40
+ 'post-entrypoint'?: string;
41
+ entrypoint?: string;
42
+ };
43
+ /**
44
+ * Defines the runs property for JavaScript actions.
45
+ */
46
+ type RunsJavascript = {
47
+ /** The runner used to execute the action */
48
+ using: JavascriptAction;
49
+ /** The entrypoint file for the action */
50
+ main: string;
51
+ pre?: string;
52
+ 'pre-if'?: string;
53
+ 'post-if'?: string;
54
+ post?: string;
55
+ };
56
+ /**
57
+ * Defines the steps property for composite actions.
58
+ */
59
+ type Steps = {
60
+ shell?: string;
61
+ if?: string;
62
+ run?: string;
63
+ name?: string;
64
+ id?: string;
65
+ 'working-directory'?: string;
66
+ env: {
67
+ [key: string]: string;
68
+ };
69
+ };
70
+ /**
71
+ * Defines the runs property for composite actions.
72
+ */
73
+ type RunsComposite = {
74
+ /** The runner used to execute the action */
75
+ using: CompositeAction;
76
+ steps: Steps;
77
+ };
78
+ export type ActionType = RunsContainer | RunsJavascript | RunsComposite;
79
+ /**
80
+ * Defines how the action is run.
81
+ */
82
+ export type ActionYaml = {
83
+ name: string;
84
+ author?: string;
85
+ /** Description of the action */
86
+ description: string;
87
+ /** Branding information */
88
+ branding?: Branding;
89
+ /** Input definitions */
90
+ inputs?: {
91
+ [key: string]: Input;
92
+ };
93
+ /** Output definitions */
94
+ outputs?: {
95
+ [key: string]: Output;
96
+ };
97
+ /** How the action is run */
98
+ runs: ActionType;
99
+ /** Path to the action */
100
+ path: string;
101
+ };
102
+ /**
103
+ * Parses and represents metadata from action.yml.
104
+ */
105
+ export default class Action implements ActionYaml {
106
+ static validate(obj: unknown): obj is ActionType;
107
+ log: LogTask;
108
+ /** Name of the action */
109
+ name: string;
110
+ author?: string;
111
+ /** Description of the action */
112
+ description: string;
113
+ /** Branding information */
114
+ branding?: Branding;
115
+ /** Input definitions */
116
+ inputs?: {
117
+ [key: string]: Input;
118
+ };
119
+ /** Output definitions */
120
+ outputs?: {
121
+ [key: string]: Output;
122
+ };
123
+ /** How the action is run */
124
+ runs: ActionType;
125
+ /** Path to the action */
126
+ path: string;
127
+ /** the original file content */
128
+ rawYamlString: string;
129
+ /**
130
+ * Creates a new instance of the Action class by loading and parsing action.yml.
131
+ *
132
+ * @param actionPath The path to the action.yml file.
133
+ */
134
+ constructor(actionPath: string, log?: LogTask);
135
+ loadActionFrom(actionPath: string): ActionYaml;
136
+ /**
137
+ * Gets the value of an input.
138
+ }
139
+
140
+ /**
141
+ * Gets the default value for an input.
142
+ *
143
+ * @param inputName The name of the input.
144
+ * @returns The default value if defined,or undefined
145
+ */
146
+ inputDefault(inputName: string): string | boolean | undefined;
147
+ /**
148
+ * Stringifies the action back to YAML.
149
+ *
150
+ * @returns The YAML string for debugging.
151
+ */
152
+ stringify(): string;
153
+ }
154
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * This TypeScript code imports the necessary modules and defines two interfaces: `Versioning` and `Paths`.
3
+ * It also defines a class named `GHActionDocsConfig` that represents the configuration for generating GitHub Actions documentation.
4
+ * The class has properties that correspond to the configuration options and a method `loadInputs` to load the configuration from the provided `Inputs` object.
5
+ * The class also has a method `save` to save the configuration to a file.
6
+ */
7
+ import type Inputs from './inputs.js';
8
+ /**
9
+ * Represents the versioning configuration for GitHub Actions documentation.
10
+ */
11
+ export interface Versioning {
12
+ enabled?: boolean;
13
+ prefix?: string;
14
+ override?: string;
15
+ branch?: string;
16
+ badge?: string;
17
+ }
18
+ /**
19
+ * Represents the paths configuration for GitHub Actions documentation.
20
+ */
21
+ export interface Paths {
22
+ action: string;
23
+ readme: string;
24
+ }
25
+ /**
26
+ * Represents the configuration for generating GitHub Actions documentation.
27
+ */
28
+ export declare class GHActionDocsConfig {
29
+ owner?: string;
30
+ repo?: string;
31
+ title_prefix?: string;
32
+ title?: string;
33
+ paths?: Paths;
34
+ branding_svg_path?: string;
35
+ versioning?: Versioning;
36
+ prettier?: boolean;
37
+ /**
38
+ * Loads the configuration from the provided `Inputs` object.
39
+ * @param {Inputs} inputs - The `Inputs` object containing the configuration values.
40
+ */
41
+ loadInputs(inputs: Inputs): void;
42
+ /**
43
+ * Saves the configuration to a file. If the file exists, it will be overwritten.
44
+ * @param {string} configPath - The path to the configuration file.
45
+ */
46
+ save(configPath: string): Promise<void>;
47
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Represents the Feather icon names.
3
+ */
4
+ import type { FeatherIconNames } from 'feather-icons';
5
+ /**
6
+ * Represents the sections of the README.
7
+ */
8
+ export declare const README_SECTIONS: readonly ['title', 'branding', 'description', 'usage', 'inputs', 'outputs', 'contents', 'badges'];
9
+ /**
10
+ * Represents a single section of the README.
11
+ */
12
+ export type ReadmeSection = (typeof README_SECTIONS)[number];
13
+ /**
14
+ * Represents the file name for the configuration file.
15
+ */
16
+ export declare const configFileName = ".ghadocs.json";
17
+ /**
18
+ * Enumerates the keys for the configuration options.
19
+ */
20
+ /**
21
+ * Valid version source options for determining action version.
22
+ */
23
+ export declare const VERSION_SOURCES: readonly ['git-tag', 'git-branch', 'git-sha', 'package-json', 'explicit'];
24
+ /**
25
+ * Type for version source options.
26
+ */
27
+ export type VersionSource = (typeof VERSION_SOURCES)[number];
28
+ /**
29
+ * Checks if the given value is a valid version source.
30
+ */
31
+ export declare function isValidVersionSource(value: string): value is VersionSource;
32
+ export declare enum ConfigKeys {
33
+ Owner = "owner",
34
+ Repo = "repo",
35
+ TitlePrefix = "title_prefix",
36
+ Prettier = "prettier",
37
+ Save = "save",
38
+ pathsAction = "paths:action",
39
+ pathsReadme = "paths:readme",
40
+ BrandingSvgPath = "branding_svg_path",
41
+ BrandingAsTitlePrefix = "branding_as_title_prefix",
42
+ VersioningEnabled = "versioning:enabled",
43
+ VersioningOverride = "versioning:override",
44
+ VersioningPrefix = "versioning:prefix",
45
+ VersioningBranch = "versioning:branch",
46
+ VersioningSource = "versioning:source",
47
+ IncludeGithubVersionBadge = "versioning:badge",
48
+ DebugNconf = "debug:nconf",
49
+ DebugReadme = "debug:readme",
50
+ DebugConfig = "debug:config",
51
+ DebugAction = "debug:action",
52
+ DebugGithub = "debug:github"
53
+ }
54
+ /**
55
+ * Represents the edge length (in pixels) for the branding square.
56
+ */
57
+ export declare const brandingSquareEdgeLengthInPixels = 50;
58
+ /**
59
+ * Represents the default brand color.
60
+ */
61
+ export declare const DEFAULT_BRAND_COLOR = "blue";
62
+ /**
63
+ * Represents the default brand icon.
64
+ */
65
+ export declare const DEFAULT_BRAND_ICON = "activity";
66
+ /**
67
+ * Represents the markup for center alignment.
68
+ */
69
+ export declare const ALIGNMENT_MARKUP = "<div align=\"center\">";
70
+ /**
71
+ * Represents the set of icons that are omitted in GitHub Actions branding.
72
+ */
73
+ export declare const GITHUB_ACTIONS_OMITTED_ICONS: Set<string>;
74
+ /**
75
+ * Represents the set of icons available for GitHub Actions branding.
76
+ */
77
+ export declare const GITHUB_ACTIONS_BRANDING_ICONS: Set<string>;
78
+ /**
79
+ * Represents the available colors for GitHub Actions branding.
80
+ */
81
+ export declare const GITHUB_ACTIONS_BRANDING_COLORS: readonly ['white', 'yellow', 'blue', 'green', 'orange', 'red', 'purple', 'gray-dark'];
82
+ /**
83
+ * Represents the available brand colors.
84
+ */
85
+ export type BrandColors = (typeof GITHUB_ACTIONS_BRANDING_COLORS)[number];
86
+ /**
87
+ * Checks if the given icon is valid for GitHub Actions branding.
88
+ * @param {Partial<FeatherIconNames>} icon - The icon to validate.
89
+ * @returns A boolean indicating if the icon is valid.
90
+ */
91
+ export declare function isValidIcon(icon: Partial<FeatherIconNames>): icon is FeatherIconNames;
92
+ /**
93
+ * Checks if the given color is valid for GitHub Actions branding.
94
+ * @param {Partial<BrandColors>} color - The color to validate.
95
+ * @returns A boolean indicating if the color is valid.
96
+ */
97
+ export declare function isValidColor(color: Partial<BrandColors>): color is BrandColors;
98
+ /**
99
+ * Represents the branding information for the action.
100
+ */
101
+ export interface Branding {
102
+ /** Color for the action branding */
103
+ color: Partial<BrandColors>;
104
+ icon: Partial<FeatherIconNames>;
105
+ }
@@ -0,0 +1,7 @@
1
+ export declare enum ErrorType {
2
+ FILE = "file",
3
+ SCHEMA = "schema",
4
+ VALIDATION = "validation",
5
+ INPUTS = "inputs",
6
+ URL = "url"
7
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type guard to check if an `unknown` value is an `Error` object.
3
+ *
4
+ * @param value - The value to check.
5
+ *
6
+ * @returns `true` if the value is an `Error` object, otherwise `false`.
7
+ */
8
+ export declare const isError: (value: unknown) => value is Error;
@@ -0,0 +1,93 @@
1
+ import { context } from '@actions/github';
2
+ import type Inputs from './inputs.js';
3
+ import LogTask from './logtask/index.js';
4
+ import { type Nullable } from './util.js';
5
+ type Context = typeof context;
6
+ /**
7
+ * Returns the input value if it is not empty, otherwise returns undefined.
8
+ * @param value - The input value to check.
9
+ * @returns The input value if it is not empty, otherwise undefined.
10
+ */
11
+ export declare function undefinedOnEmpty(value: string | undefined): string | undefined;
12
+ /**
13
+ * Returns the basename of the given path.
14
+ * @param pathStr - The path to extract the basename from.
15
+ * @returns The basename of the path.
16
+ */
17
+ export declare function basename(pathStr: string): string | undefined;
18
+ /**
19
+ * Removes the "refs/heads/" or "refs/tags/" prefix from the given path.
20
+ *
21
+ * @param pathStr - The path to remove the prefix from
22
+ * @returns The path without the prefix, or null if path is empty
23
+ */
24
+ export declare function stripRefs(pathStr: string): string | null;
25
+ /**
26
+ * Converts the given text to title case.
27
+ * @param text - The text to convert.
28
+ * @returns The text converted to title case.
29
+ * @throws {TypeError} If the input is not a string.
30
+ */
31
+ export declare function titlecase(text: string): string | undefined;
32
+ /**
33
+ * Parses the given text and converts it to title case, replacing underscores and dashes with spaces.
34
+ * @param text - The text to parse and convert.
35
+ * @returns The parsed text converted to title case.
36
+ */
37
+ export declare function prefixParser(text: string | undefined): string | undefined;
38
+ /**
39
+ * Wraps the given text into multiple lines with a maximum width of 80 characters.
40
+ * @param text - The text to wrap.
41
+ * @param content - The array to store the wrapped lines.
42
+ * @param prepend - The string to prepend to each wrapped line.
43
+ * @returns The array of wrapped lines.
44
+ */
45
+ export declare function wrapText(text: string | undefined, content: string[], prepend?: string): string[];
46
+ /**
47
+ * Represents a repository with owner and repo properties.
48
+ */
49
+ export interface Repo {
50
+ owner: string;
51
+ repo: string;
52
+ }
53
+ export declare function readFile(filename: string): string;
54
+ export declare function repoObjFromRepoName(repository: Nullable<string>, log: LogTask, from?: string): Nullable<Repo>;
55
+ export declare const remoteGitUrlPattern: RegExp;
56
+ /**
57
+ * Finds the repository information from the input, context, environment variables, or git configuration.
58
+ * @param inputRepo - The input repository string.
59
+ * @param context - The GitHub context object.
60
+ * @param baseDir - Optional base directory to look for .git/config (defaults to CWD).
61
+ * @returns The repository information (owner and repo) or null if not found.
62
+ */
63
+ export declare function repositoryFinder(inputRepo: Nullable<string>, context: Nullable<Context>, baseDir?: string): Repo | null;
64
+ /**
65
+ * Returns the default branch of the git repository.
66
+ * @returns The default branch.
67
+ */
68
+ /**
69
+ * Gets the default branch for the Git repository.
70
+ *
71
+ * @returns The name of the default branch.
72
+ */
73
+ export declare function getDefaultGitBranch(): string;
74
+ /**
75
+ * Formats the given value as a column header.
76
+ * @param value - The value to format.
77
+ * @returns The formatted column header.
78
+ */
79
+ export declare function columnHeader(value: string): string;
80
+ /**
81
+ * Formats the given value as a row header in HTML.
82
+ *
83
+ * Removes formatting from the string and converts it to bold code style.
84
+ *
85
+ * @param value - The string to format as a header
86
+ * @returns The formatted row header string wrapped in bold and code tags
87
+ */
88
+ export declare function rowHeader(value: string): string;
89
+ export declare function getCurrentVersionString(inputs: Inputs): string;
90
+ export declare function indexOfRegex(str: string, providedRegex: RegExp): number;
91
+ export declare function lastIndexOfRegex(str: string, providedRegex: RegExp): number;
92
+ export declare function isObject(value: unknown): value is object;
93
+ export {};