"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readStdin = exports.resolveFilePath = exports.getFilePath = exports.getPlatform = void 0;
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const slash_1 = __importDefault(require("slash"));
const getPlatform = () => {
    switch (os.type()) {
        case 'Darwin':
            return 'mac';
        case 'Linux':
            return 'linux';
        case 'Windows_NT':
            return 'win';
        default:
            return 'unknown';
    }
};
exports.getPlatform = getPlatform;
const getFilePath = (dirname, filename) => {
    const platform = (0, exports.getPlatform)();
    if (platform === 'linux' || platform === 'mac') {
        return `file://${path.join(dirname, filename)}`;
    }
    if (platform === 'win') {
        return `file:///${(0, slash_1.default)(path.join(dirname, filename))}`;
    }
    return null;
};
exports.getFilePath = getFilePath;
const resolveFilePath = (filePath) => {
    if (filePath.length === 0) {
        return filePath;
    }
    if (filePath[0] === '~') {
        return path.join(process.env.HOME, filePath.slice(1));
    }
    return filePath;
};
exports.resolveFilePath = resolveFilePath;
const readStdin = () => {
    return new Promise((resolve) => {
        let content = '';
        process.stdin.resume();
        process.stdin.on('data', (buf) => {
            content += buf.toString('utf8');
        });
        process.stdin.on('end', () => resolve(content));
    });
};
exports.readStdin = readStdin;
