UNPKG

http-alive

Version:
40 lines (39 loc) 1.24 kB
#!/usr/bin/env node "use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const cmd = process.argv[2]; if (cmd !== 'clean') { console.log('please use `httpalive clean` instead'); process.exit(1); } const pidFile = path.resolve(process.cwd(), '.httpalive.pid'); const exist = fs.existsSync(pidFile); if (!exist) { console.log('please make sure `.httpalive.pid` exists in your process.cwd() directory'); process.exit(1); } const data = fs.readFileSync(pidFile, 'utf-8'); const j = JSON.parse(data); Object.keys(j).map(k => { try { process.kill(j[k]); console.log(`kill pid ${j[k]} of ${k}`); } catch (e) { if (e.code === 'ESRCH') { console.log(`skip pid ${j[k]} of ${k}`); } else { console.error(e); } } });