/**
 * Minified by jsDelivr using Terser v5.37.0.
 * Original file: /npm/clang-format@1.8.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
"use strict";const fs=require("fs"),os=require("os"),path=require("path"),resolve=require("resolve").sync,spawn=require("child_process").spawn,glob=require("glob"),async=require("async"),VERSION=require("./package.json").version,LOCATION=__filename,GLOB_OPTION="--glob=";function errorFromExitCode(e){return new Error(`clang-format exited with exit code ${e}.`)}function clangFormat(e,r,n,o){let t=spawnClangFormat([`-style=${n}`,e.path],o,["ignore","pipe",process.stderr]);if(t)return t.stdout.setEncoding(r),t.stdout;throw new Error("Can't get output stream when --glob flag is set")}function spawnClangFormat(e,r,n){let o;try{o=getNativeBinary()}catch(e){return void setImmediate((()=>r(e)))}e.find((e=>"-version"===e||"--version"===e))&&(console.log(`clang-format NPM version ${VERSION} at ${LOCATION}`),e=["--version"]);const t=getGlobArg(e);if(!t){const t=spawn(o,e,{stdio:n});return t.on("close",(function(e){e?r(errorFromExitCode(e)):r()})),t}e=e.filter((e=>-1===e.indexOf("--glob="))),glob(t,(function(t,i){if(t)return void r(t);let a,s,l=[];for(a=0,s=i.length;a<s;a+=30)l.push(i.slice(a,a+30));async.series(l.map((function(r){return function(t){spawn(o,e.concat(r),{stdio:n}).on("close",(function(e){0!==e?t(errorFromExitCode(e)):t()}))}})),(function(e){e?r(e):(console.log("\n"),console.log(`ran clang-format on ${i.length} ${1===i.length?"file":"files"}`),r())}))}))}function main(){const e=process.argv.filter(((e,r)=>r>1&&"-"!=e[0])),r=e[e.length-1],n=r?path.dirname(r):process.cwd();let o,t,i;try{t=resolve("clang-format",{basedir:n}),o=require(t)}catch(e){}if(o){if(!o.spawnClangFormat)throw new Error(`Incompatible clang-format loaded from ${t}`);i=o.spawnClangFormat}else i=spawnClangFormat;try{i(process.argv.slice(2),(function(e){e instanceof Error?(console.error(e),process.exit(1)):process.exit(e)}),"inherit")}catch(e){process.stdout.write(e.message),process.exit(1)}}function getNativeBinary(){let e;const r=os.platform(),n=os.arch();if(e="win32"===r?`${__dirname}/bin/win32/clang-format.exe`:`${__dirname}/bin/${r}_${n}/clang-format`,fs.existsSync(e))return e;if("darwin"===r&&"arm64"===n&&(e=`${__dirname}/bin/darwin_x64/clang-format`,fs.existsSync(e)))return e;throw new Error(`This module doesn't bundle the clang-format executable for your platform. (${r}_${n})\nConsider installing it with your native package manager instead.\n`)}function getGlobArg(e){const r=e.find((e=>e.startsWith("--glob=")));return r?r.substring(7):null}module.exports=clangFormat,module.exports.version=VERSION,module.exports.location=LOCATION,module.exports.spawnClangFormat=spawnClangFormat,module.exports.getNativeBinary=getNativeBinary,require.main===module&&main();
//# sourceMappingURL=/sm/7a9ca32f5ceae561cc9185eaf8f1ec7223e79709a6eabf64b510c4ee2d6eab26.map