UNPKG

git-cliff

Version:

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

1 lines 6.2 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,WAAY,EAAA,CAAA;AAC7B,EAAA,MAAM,OAAOC,OAAQ,EAAA,CAAA;AAErB,EAAA,IAAIC,IAAK,GAAA,QAAA,CAAA;AACT,EAAA,IAAI,SAAY,GAAA,EAAA,CAAA;AAEhB,EAAI,IAAA,QAAA,KAAa,OAAW,IAAA,QAAA,KAAa,QAAU,EAAA;AACjD,IAAKA,IAAA,GAAA,SAAA,CAAA;AACL,IAAY,SAAA,GAAA,MAAA,CAAA;AAAA,GACd;AAEA,EAAI,IAAA;AAEF,IAAA,OAAO,SAAY;AAAA,MACjB,CAAa,UAAA,EAAAA,IAAE,CAAI,CAAA,EAAA,IAAI,iBAAiB,SAAS,CAAA,CAAA;AAAA,KACnD,CAAA;AAAA,WACO,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAA0D,uDAAA,EAAAA,IAAE,CAAI,CAAA,EAAA,IAAI,KAAK,CAAC,CAAA,CAAA,CAAA;AAAA,KAC5E,CAAA;AAAA,GACF;AACF,CAAA;AAtBsB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA,CAAA;;;ACDf,SAAS,oBAAoB,OAA4B,EAAA;AAC9D,EAAA,MAAM,OAAiB,EAAC,CAAA;AAExB,EAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,OAAO,CAAG,EAAA;AAClD,IAAA,MAAM,gBAAgB,GAAI,CAAA,OAAA,CAAQ,UAAY,EAAA,KAAK,EAAE,WAAY,EAAA,CAAA;AAEjE,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AACxB,MAAA,KAAA,MAAW,YAAY,KAAO,EAAA;AAC5B,QAAA,IAAA,CAAK,IAAK,CAAA,CAAA,EAAA,EAAK,aAAa,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA;AAAA,OAC1C;AAAA,KACF,MAAA,IAAW,UAAU,IAAM,EAAA;AACzB,MAAK,IAAA,CAAA,IAAA,CAAK,CAAK,EAAA,EAAA,aAAa,CAAE,CAAA,CAAA,CAAA;AAAA,KACrB,MAAA,IAAA,KAAA,KAAU,KAAS,IAAA,KAAA,KAAU,IAAM,EAAA;AAC5C,MAAA,SAAA;AAAA,KACK,MAAA;AACL,MAAA,IAAA,CAAK,IAAK,CAAA,CAAA,EAAA,EAAK,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAAA,KACvC;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AApBgB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA,CAAA;;;ACyChB,eAAsB,WAAA,CAAY,eAAmC,YAAgE,EAAA;AACnI,EAAM,MAAA,OAAA,GAAU,MAAM,UAAW,EAAA,CAAA;AACjC,EAAA,MAAM,OAAO,KAAM,CAAA,OAAA,CAAQ,aAAa,CACpC,GAAA,aAAA,GACA,oBAAoB,aAAa,CAAA,CAAA;AAErC,EAAA,OAAOC,WAAM,CAAAC,iBAAA,CAAc,OAAO,CAAA,EAAG,IAAM,EAAA;AAAA,IACzC,KAAO,EAAA,SAAA;AAAA,IACP,GAAG,YAAA;AAAA,GACJ,CAAA,CAAA;AACH,CAAA;AAVsB,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 ExecaReturnValue, } 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(options: Options, execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\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(args: string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\nexport async function runGitCliff(argsOrOptions: Options | string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>> {\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"]}