"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.start_browserSync = exports.postcss_transform = void 0;
const browser_sync_1 = __importDefault(require("browser-sync"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const postcss_1 = __importDefault(require("postcss"));
const config_1 = require("./config");
const postcssConfig = require('../postcss.config');
const postcssTransformer = (0, postcss_1.default)(postcssConfig.plugins);
function postcss_transform(dir) {
    return (req, res) => {
        let fileSrc = path_1.default.join(dir, req.path);
        let fileDst = req.originalUrl;
        let options = { from: fileSrc, to: fileDst, ...postcssConfig.options };
        postcssTransformer.process(fs_1.default.readFileSync(fileSrc), options).then((result) => { res.contentType('css'); res.send(result.css); }).catch((err) => { console.log(err); });
    };
}
exports.postcss_transform = postcss_transform;
function start_browserSync(port) {
    // https://ponyfoo.com/articles/a-browsersync-primer#inside-a-node-application
    (0, browser_sync_1.default)({
        files: ['src/**/*.{html,js,css}'],
        online: false,
        open: false,
        port: config_1.config.PORT,
        proxy: 'localhost:' + port,
        ui: false,
    });
}
exports.start_browserSync = start_browserSync;
//# sourceMappingURL=debug_utils.js.map