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iDAtEG,mCAwErB,QAAQ,IAAI,KAAK,kDAxEI,mBA2EvB,EAAI,QAAQ,YAAc,cAAc,EAAS,IAAK,cAAgB,gBAGtE,GAAG,cAAc,EAAa,KAAK,UAAU,EAAK,KAAM,MAAO,SAG/D,MAAM,EAAQ,GAAG,YAAY,KAAK,KAAK,UAhFhB,UAkFvB,EAAM,SAAQ,CAAC,EAAU,KACvB,MAAM,EAAiD,OAA9B,EAAS,MAAM,KAAK,MAG7C,SAAS,EAAU,IAAU,EAAM,OAAS,GAAI,EAAgB,GACjE,EAGH,OAAO,QAAU","file":"/npm/@4th-motion/git-hooks@1.0.4/init.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@4th-motion/git-hooks@1.0.4/init.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n/* eslint-disable no-console, consistent-return */\n\nconst fs = require('fs')\nconst path = require('path')\nconst chalk = require('chalk')\n\nconst PACKAGE_FILENAME = 'package.json'\nconst HOOKS_FOLDERNAME = 'hooks'\nconst GIT_FOLDERNAME = '.git'\nconst GIT_HOOKS_FOLDERNAME = '.git/hooks'\n\n// get package.json content\nconst getPackageContent = (packagePath) => {\n  try {\n    return fs.readFileSync(packagePath, 'utf-8')\n  } catch (error) {\n    if (error.code === 'ENOENT') {\n      console.error(chalk`{bold.red [ERROR]  } no package.json was found in {underline ${packagePath}}.`)\n      process.exit(0)\n    }\n  }\n}\n\nconst copyFile = (fileName, lastFile = false, showLog = true) => {\n  const src = path.join(__dirname, `${HOOKS_FOLDERNAME}/${fileName}`)\n  const dest = path.join(process.cwd(), `${GIT_HOOKS_FOLDERNAME}/${fileName}`)\n\n  if (src === dest) return\n\n  fs.copyFile(src, dest, (error) => {\n    if (error) {\n      console.error(chalk`{bold.red [ERROR]  } could not copy {bold ${fileName}}.`)\n    } else if (showLog) {\n      console.log(chalk`{bold.magenta [ADDED]  } git hook {bold ${fileName}}`)\n    }\n\n    fs.chmodSync(dest, '755')\n\n    if (lastFile) {\n      console.log(chalk`{bold.green [SUCCESS]} git hooks were successfully installed!`)\n    }\n  })\n}\n\nconst getKeyByValue = (object, value) => {\n  return object ? Object.keys(object).find((key) => object[key] === value) : null\n}\n\nconst installGitHooks = () => {\n  const hasGitFolder = fs.existsSync(path.join(process.cwd(), GIT_FOLDERNAME))\n  const hasGitHookFolder = fs.existsSync(path.join(process.cwd(), GIT_HOOKS_FOLDERNAME))\n\n  // check if it is a git repository\n  if (!hasGitFolder || !hasGitHookFolder) {\n    console.error(\n      chalk`{bold.red [ERROR]  } could not install git hooks, because this folder is not a github repository.`\n    )\n\n    // do not exit the process but stop here\n    // otherwise vercel build fails\n    return null\n  }\n\n  // check if hooks are available\n  if (!fs.existsSync(path.join(__dirname, HOOKS_FOLDERNAME))) {\n    console.error(chalk`{bold.red [ERROR]  } no git hooks found to install.`)\n  }\n\n  // add script `postinstall` to package.json\n  const packagePath = path.join(process.cwd(), PACKAGE_FILENAME)\n  const packageLocalPath = path.join(__dirname, PACKAGE_FILENAME)\n\n  const pkg = JSON.parse(getPackageContent(packagePath))\n  const pkgLocal = JSON.parse(getPackageContent(packageLocalPath))\n\n  if (pkg.scripts.postinstall) {\n    console.warn(chalk`{bold.yellow [WARNING]} {bold postinstall} in ${PACKAGE_FILENAME} was overwritten.`)\n  } else {\n    console.log(chalk`{bold.magenta [ADDED]  } {bold postinstall} in ${PACKAGE_FILENAME}.`)\n  }\n\n  pkg.scripts.postinstall = getKeyByValue(pkgLocal.bin, './init.js') || '4th-git-hooks'\n\n  // write to package.json\n  fs.writeFileSync(packagePath, JSON.stringify(pkg, null, '  '), 'utf-8')\n\n  // hooks to copy from ./hooks/\n  const files = fs.readdirSync(path.join(__dirname, HOOKS_FOLDERNAME))\n\n  files.forEach((fileName, index) => {\n    const isJavascriptFile = fileName.split('.').pop() === 'js'\n\n    // show log information not for js files\n    copyFile(fileName, index === files.length - 1, !isJavascriptFile)\n  })\n}\n\nmodule.exports = installGitHooks()\n"]}