UNPKG

git-cliff

Version:

A highly customizable Changelog Generator that follows Conventional Commit specifications ⛰️

1 lines 6.13 kB
{"version":3,"sources":["../../src/getExePath.ts","../../src/optionsToStringArgs.ts","../../src/index.ts"],"names":["getPlatform","getArch","os","execa","fileURLToPath"],"mappings":";;;;;;;;AAUA,eAAsB,UAAA,GAAa;AACjC,EAAA,MAAM,WAAWA,WAAA,EAAY;AAC7B,EAAA,MAAM,OAAOC,OAAA,EAAQ;AAErB,EAAA,IAAIC,IAAA,GAAK,QAAA;AACT,EAAA,IAAI,SAAA,GAAY,EAAA;AAEhB,EAAA,IAAI,QAAA,KAAa,OAAA,IAAW,QAAA,KAAa,QAAA,EAAU;AACjD,IAAAA,IAAA,GAAK,SAAA;AACL,IAAA,SAAA,GAAY,MAAA;AAAA,EACd;AAEA,EAAA,IAAI;AAEF,IAAA,OAAO,SAAY;AAAA,MACjB,CAAA,UAAA,EAAaA,IAAE,CAAA,CAAA,EAAI,IAAI,iBAAiB,SAAS,CAAA;AAAA,KACnD;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,uDAAA,EAA0DA,IAAE,CAAA,CAAA,EAAI,IAAI,KAAK,CAAC,CAAA,CAAA;AAAA,KAC5E;AAAA,EACF;AACF;AAtBsB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA;;;ACDf,SAAS,oBAAoB,OAAA,EAA4B;AAC9D,EAAA,MAAM,OAAiB,EAAC;AAExB,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AAClD,IAAA,MAAM,gBAAgB,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY,KAAK,EAAE,WAAA,EAAY;AAEjE,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,KAAA,MAAW,YAAY,KAAA,EAAO;AAC5B,QAAA,IAAA,CAAK,IAAA,CAAK,CAAA,EAAA,EAAK,aAAa,CAAA,CAAA,EAAI,QAAQ,CAAA;AAAA,MAC1C;AAAA,IACF,CAAA,MAAA,IAAW,UAAU,IAAA,EAAM;AACzB,MAAA,IAAA,CAAK,IAAA,CAAK,CAAA,EAAA,EAAK,aAAa,CAAA,CAAE,CAAA;AAAA,IAChC,CAAA,MAAA,IAAW,KAAA,KAAU,KAAA,IAAS,KAAA,KAAU,IAAA,EAAM;AAC5C,MAAA;AAAA,IACF,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,IAAA,CAAK,CAAA,EAAA,EAAK,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA;AAAA,IACvC;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT;AApBgB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA;;;AC+ChB,eAAsB,WAAA,CACpB,eACA,YAAA,EACsC;AACtC,EAAA,MAAM,OAAA,GAAU,MAAM,UAAA,EAAW;AACjC,EAAA,MAAM,OAAO,KAAA,CAAM,OAAA,CAAQ,aAAa,CAAA,GACpC,aAAA,GACA,oBAAoB,aAAa,CAAA;AAErC,EAAA,OAAOC,WAAA,CAAMC,iBAAA,CAAc,OAAO,CAAA,EAAG,IAAA,EAAM;AAAA,IACzC,KAAA,EAAO,SAAA;AAAA,IACP,GAAG;AAAA,GACJ,CAAA;AACH;AAbsB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"index.cjs","sourcesContent":["import { arch as getArch, platform as getPlatform } from \"os\";\n\n/**\n * Returns the executable path for git-cliff located inside node_modules\n * The naming convention is git-cliff-${os}-${arch}\n * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension\n * @see https://nodejs.org/api/os.html#osarch\n * @see https://nodejs.org/api/os.html#osplatform\n * @example \"x/xx/node_modules/git-cliff-darwin-arm64\"\n */\nexport async function getExePath() {\n const platform = getPlatform();\n const arch = getArch();\n\n let os = platform as string;\n let extension = \"\";\n\n if (platform === \"win32\" || platform === \"cygwin\") {\n os = \"windows\";\n extension = \".exe\";\n }\n\n try {\n // Since the bin will be located inside `node_modules`, we can simply call import.meta.resolve\n return import.meta.resolve(\n `git-cliff-${os}-${arch}/bin/git-cliff${extension}`,\n );\n } catch (e) {\n throw new Error(\n `Couldn't find git-cliff binary inside node_modules for ${os}-${arch} (${e})`,\n );\n }\n}\n","import type { Options } from \"./options.js\";\n\n/**\n * Transforms a JavaScript object of options into an array\n * of strings that can be passed to {@link execa} for calling `git-cliff`\n *\n * @param options The options to transform\n * @returns The options as an array of strings\n */\nexport function optionsToStringArgs(options: Options): string[] {\n const args: string[] = [];\n\n for (const [key, value] of Object.entries(options)) {\n const hyphenCaseKey = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n if (Array.isArray(value)) {\n for (const arrValue of value) {\n args.push(`--${hyphenCaseKey}`, arrValue);\n }\n } else if (value === true) {\n args.push(`--${hyphenCaseKey}`);\n } else if (value === false || value === null) {\n continue;\n } else {\n args.push(`--${hyphenCaseKey}`, value);\n }\n }\n\n return args;\n}\n","import { execa, type Options as ExecaOptions, type ResultPromise } from \"execa\";\nimport { fileURLToPath } from \"node:url\";\nimport { getExePath } from \"./getExePath.js\";\nimport type { Options } from \"./options.js\";\nimport { optionsToStringArgs } from \"./optionsToStringArgs.js\";\n\nexport type { Options } from \"./options.js\";\n\n/**\n * Runs `git-cliff` with the provided options as a JavaScript object.\n *\n * @param options - The options to pass to `git-cliff`.\n * These get transformed into an array strings.\n * - Values that are `true` will be passed as flags (`--flag`).\n * - Values that are `false` or `null` will be ignored.\n * - All other values will be passed as options (`--option value`).\n *\n * @param execaOptions - Options to pass to {@link execa}.\n */\nexport async function runGitCliff(\n options: Options,\n execaOptions?: ExecaOptions\n): Promise<ResultPromise<ExecaOptions>>;\n/**\n * Runs the `git-cliff` with the provided arguments.\n *\n * @param args - The arguments to pass to `git-cliff`.\n * These should be in an array of string format.\n * Every option and their value should be its own entry in the array.\n *\n * @param execaOptions - Options to pass to {@link execa}.\n *\n * @returns A promise that resolves when the `git-cliff` has finished running.\n *\n * @example\n * Options with values\n * ```typescript\n * await runGitCliff([\"--tag\", \"1.0.0\", \"--config\", \"github\"]);\n * ```\n *\n * @example\n * Boolean flags\n * ```typescript\n * await runGitCliff([\"--unreleased\", \"--topo-order\"]);\n * ```\n *\n * @example\n * Combining options and flags\n * ```typescript\n * await runGitCliff([\"--tag\", \"1.0.0\", \"--config\", \"github\", \"--topo-order\"]);\n * ```\n */\nexport async function runGitCliff(\n args: string[],\n execaOptions?: ExecaOptions\n): Promise<ResultPromise<ExecaOptions>>;\nexport async function runGitCliff(\n argsOrOptions: Options | string[],\n execaOptions?: ExecaOptions\n): Promise<ResultPromise<ExecaOptions>> {\n const exePath = await getExePath();\n const args = Array.isArray(argsOrOptions)\n ? argsOrOptions\n : optionsToStringArgs(argsOrOptions);\n\n return execa(fileURLToPath(exePath), args, {\n stdio: \"inherit\",\n ...execaOptions,\n });\n}\n"]}