UNPKG

flow-typed

Version:

A repository of high quality flow type definitions

128 lines (113 loc) 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.url = exports.path = exports.os = exports.https = exports.fs = exports.child_process = void 0; var realFs = _interopRequireWildcard(require("fs")); var node_child_process = _interopRequireWildcard(require("child_process")); var node_https = _interopRequireWildcard(require("https")); var node_os = _interopRequireWildcard(require("os")); var node_path = _interopRequireWildcard(require("path")); var node_url = _interopRequireWildcard(require("url")); var _fsExtra = _interopRequireDefault(require("fs-extra")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const child_process = { exec: node_child_process.exec, execP: function (command, options) { return new Promise((res, rej) => { node_child_process.exec(command, options, (err, stdout, stderr) => { if (err) { rej(err); } else { res({ stdout: Buffer.from(stdout), stderr: Buffer.from(stderr) }); } }); }); }, execFileP: function (command, argsOrOptions, options) { let _args; let _opts; if (Array.isArray(argsOrOptions)) { _args = argsOrOptions; _opts = options ? options : {}; } else { _args = []; _opts = argsOrOptions ? argsOrOptions : {}; } return new Promise((res, rej) => { node_child_process.execFile(command, _args, _opts, (err, stdout, stderr) => { if (err) { rej(err); } else { res({ stdout: typeof stdout === 'string' ? Buffer.from(stdout) : stdout, stderr: typeof stderr === 'string' ? Buffer.from(stderr) : stderr }); } }); }); }, spawnP: function (command, args, options) { return new Promise((res, rej) => { const process = node_child_process.spawn(command, args, options); let stderr = ''; let stdout = ''; process.stdout.on('data', chunk => stdout += chunk); process.stderr.on('data', chunk => stderr += chunk); process.on('close', exitCode => { if (exitCode === 0) { res({ stderr, stdout, exitCode }); } else { rej({ stderr, stdout, exitCode }); } }); }); } }; exports.child_process = child_process; const fs = { appendFile: _fsExtra.default.appendFile, close: _fsExtra.default.close, copy: _fsExtra.default.copy, copyFile: _fsExtra.default.copyFile, createReadStream: _fsExtra.default.createReadStream, createWriteStream: _fsExtra.default.createWriteStream, exists: _fsExtra.default.exists, existsSync: realFs.existsSync, mkdir: _fsExtra.default.mkdir, open: _fsExtra.default.open, readdir: _fsExtra.default.readdir, readFile: _fsExtra.default.readFile, readFileSync: _fsExtra.default.readFileSync, readJson: _fsExtra.default.readJson, rename: _fsExtra.default.rename, rmdir: _fsExtra.default.rmdir, stat: _fsExtra.default.stat, statSync: _fsExtra.default.statSync, Stats: _fsExtra.default.Stats, unlink: _fsExtra.default.unlink, writeFile: _fsExtra.default.writeFile, writeJson: _fsExtra.default.writeJson }; exports.fs = fs; const https = node_https; exports.https = https; const os = node_os; exports.os = os; const path = node_path; exports.path = path; const url = node_url; exports.url = url;