{"version":3,"sources":["jsdelivr-header.js","/npm/@olegjs/on-change@1.1.1/src/cli.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;ACJA,MAAM,OAAE,OAAM,QAAE,SAAY,QAAQ,UAC9B,UAAE,WAAc,QAAQ,kBACxB,WAAE,WAAU,aAAE,aAAY,cAAE,eAAkB,QAAQ,OAEtD,YACJ,YAAW,oBACX,oBAAmB,oBACnB,qBACE,QAAQ,cAEN,KAAO,QAAQ,SAClB,WAAW,aACX,MAAM,qCACN,QACC,qCACA,uDAED,OAAO,OAAQ,CACd,MAAO,IACP,cAAc,EACd,SAAU,oCACV,KAAM,WAEP,OAAO,QAAS,CACf,SAAU,yCACV,KAAM,YAEP,cAAc,GAAG,KAEd,IAAM,OAEN,gBAAkB,GACtB,WAAW,GAAQ,oBAAoB,aAAa,EAAM,MAAQ,KAE9D,SAAW,YAAY,aAAa,KAAK,KAAM,MAC/C,iBAAmB,oBAAoB,KAAK,MAC5C,aAAe,gBAAgB,kBAErC,GAAI,WAAa,aAAc,CAC7B,QAAQ,IACN,SAAS,QAAQ,KAAK,sBACtB,YAAY,OAAO,KAAK,EAAE,KAAK,aAGjC,MAAO,KAAY,GAAQ,KAAK,EAChC,UAAU,EAAS,EAAM,CAAE,SAAU,IAAK,MAAO,YACjD,cAAc,iBAAkB,GAAG,aAAa,KAAK,OACvD","file":"/npm/@olegjs/on-change@1.1.1/src/cli.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@olegjs/on-change@1.1.1/src/cli.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\nconst { yellow, magenta } = require('chalk')\nconst { spawnSync } = require('child_process')\nconst { existsSync, readFileSync, writeFileSync } = require('fs')\n\nconst {\n  getChecksum,\n  getChecksumFilePath,\n  hashFromFileContent,\n} = require('./checksum')\n\nconst argv = require('yargs')\n  .scriptName('on-change')\n  .usage('Usage: $0 --file [file] [command]')\n  .example(\n    '$0 --file package-lock.json npm ci',\n    'Reinstall dependencies on changed package-lock.json',\n  )\n  .option('file', {\n    alias: 'f',\n    demandOption: true,\n    describe: 'Path to file to check for changes',\n    type: 'string',\n  })\n  .option('color', {\n    describe: 'Force color or disable with --no-color',\n    type: 'boolean',\n  })\n  .demandCommand(1).argv\n\nconst UTF = 'utf8'\n\nconst getPastChecksum = path =>\n  existsSync(path) ? hashFromFileContent(readFileSync(path, UTF)) : null\n\nconst checksum = getChecksum(readFileSync(argv.file, UTF))\nconst checksumFilePath = getChecksumFilePath(argv.file)\nconst pastChecksum = getPastChecksum(checksumFilePath)\n\nif (checksum !== pastChecksum) {\n  console.log(\n    `File \"${magenta(argv.file)}\" has changed.`,\n    `Running \"${yellow(argv._.join(' '))}\"...`,\n  )\n\n  const [command, ...args] = argv._\n  spawnSync(command, args, { encoding: UTF, stdio: 'inherit' })\n  writeFileSync(checksumFilePath, `${checksum}  ${argv.file}`)\n}\n"]}