[
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# TypeScript v1 declaration files\ntypings/\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variables file\n.env\n\n# next.js build output\n.next\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2018 Alexander Kuznetsov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# script-progress\n\nA simple tool for heavy NPM/Yarn scripts that run for a long but roughly identical time. It's not intended to be precise but gives you some sense of execution time.\n\n### Installation\n\n```sh\nyarn add script-progress\n```\nor\n```sh\nnpm i script-progress\n```\n\n### Example Usage\n\nChange your build script in `package.json`:\n```diff\n- \"build\": \"react-scripts build\",\n+ \"build-js\": \"react-scripts build\",\n+ \"build\": \"script-progress yarn build-js\",\n```\nor just\n```diff\n- \"build\": \"react-scripts build\",\n+ \"build\": \"script-progress react-scripts build\",\n```\n\nThe script will show a progress bar on the second and subsequent runs.\n"
  },
  {
    "path": "index.js",
    "content": "#! /usr/bin/env node\nvar cp = require('child_process');\nvar fs = require('fs');\nvar md5 = require('blueimp-md5');\nvar progress = require('cli-progress');\nvar findCacheDir = require('find-cache-dir');\n\nfunction median(arr) {\n  arr = arr.slice(0);\n  var middle = (arr.length + 1) / 2,\n    sorted = arr.sort(function(a,b) { return a - b });\n  return (sorted.length % 2) ? sorted[middle - 1] : (sorted[middle - 1.5] + sorted[middle - 0.5]) / 2;\n};\n\nvar bar = new progress.Bar({\n  format: 'progress [{bar}] {percentage}%',\n  clearOnComplete: true\n}, progress.Presets.shades_classic);\nvar cacheThunk = findCacheDir({ name: 'script-progress', create: true, thunk: true });\n\nvar args = process.argv.slice(2);\nvar cmd = args.shift();\n\nif (!process.stdout.isTTY) {\n  var res = cp.spawnSync(cmd, args, { env: process.env, stdio: [process.stdin, process.stdout, process.stderr] });\n  process.exit(res.status);\n}\n\nvar cacheFileName = md5(args.join(' '));\n\nvar DEFAULT_CACHE = { intervals: [] };\nvar cacheFileContent = fs.readFileSync(cacheThunk(cacheFileName), { flag: 'a+' });\nvar cache;\ntry {\n  cache = JSON.parse(cacheFileContent.toString() || JSON.stringify(DEFAULT_CACHE));\n} catch (e) {}\n\nif (!cache || !Array.isArray(cache.intervals)) {\n  cache = DEFAULT_CACHE;\n}\n\nvar med = median(cache.intervals);\n\nvar eta = med ? Math.max.apply(Math, cache.intervals.filter(function(val) {\n  return val / med < 1.5;\n})) : 0;\n\nvar refreshInterval;\n\nif (eta) {\n  bar.start(eta, 0);\n\n  refreshInterval = setInterval(function() {\n    bar.update(getDiff());\n  }, 200);\n}\n\nvar time = process.hrtime();\n\nprocess.env.FORCE_COLOR = true;\nvar ls = cp.spawn(cmd, args, { env: process.env });\n\nfunction getDiff() {\n  var diff = process.hrtime(time);\n  return (diff[0] + diff[1] / 10E9);\n}\n\nfunction clear() {\n  bar.terminal.cursorTo(0, null);\n  bar.terminal.clearRight();\n}\n\nfunction redraw() {\n  bar.value = getDiff();\n  bar.lastDrawnString = '';\n  bar.render();  \n}\n\nls.stdout.on('data', function (data) {\n  if (eta) {\n    clear();\n    bar.terminal.cursorSave();\n  }\n  process.stdout.write(data.toString());\n  if (eta) redraw();\n});\n\nls.stderr.on('data', function (data) {\n  if (eta) {\n    clear();\n    bar.terminal.cursorSave();\n  }\n  process.stderr.write(data.toString());\n  if (eta) redraw();\n});\n\nls.on('close', (code) => {\n  var diff = getDiff();\n\n  if (code) {\n    process.exit(code);\n  }\n\n  if (!eta || diff / eta > 0.1) {\n    cache.intervals.push(diff);\n    if (cache.intervals.length > 5) {\n      cache.intervals.shift();\n    }\n  }\n  fs.writeFileSync(cacheThunk(cacheFileName), JSON.stringify(cache));\n\n  clearInterval(refreshInterval);\n  if (eta) {\n    bar.terminal.cursorSave();\n    bar.stop();\n  }\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"script-progress\",\n  \"version\": \"1.0.5\",\n  \"description\": \"Estimate script execution time\",\n  \"main\": \"index.js\",\n  \"license\": \"MIT\",\n  \"bin\": {\n    \"script-progress\": \"./index.js\"\n  },\n  \"dependencies\": {\n    \"blueimp-md5\": \"^2.10.0\",\n    \"cli-progress\": \"^2.0.0\",\n    \"find-cache-dir\": \"^2.0.0\"\n  }\n}\n"
  }
]