@twstyled/util
Version:
Utilities, config and class helpers for twstyled -- the full-featured Tailwind CSS + CSS in JS Compiler
46 lines (45 loc) • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTwConfigCache = exports.getTwConfigHash = exports.getTwConfig = exports.getTwConfigPath = void 0;
const import_fresh_1 = __importDefault(require("import-fresh"));
const core_1 = require("@xwind/core");
const util_1 = require("./util");
function getTwConfigPath(relativePath = './tailwind.config.js') {
return util_1.resolvePath(relativePath, `No config file found at ${relativePath}`);
}
exports.getTwConfigPath = getTwConfigPath;
function getTwConfig(twConfigPath) {
return core_1.resolveConfig(import_fresh_1.default(twConfigPath));
}
exports.getTwConfig = getTwConfig;
function getTwConfigHash(twConfigPath) {
const file = util_1.getFile(twConfigPath, `No config file found at ${twConfigPath}`);
return util_1.getHash(file);
}
exports.getTwConfigHash = getTwConfigHash;
////////////////
//CACHE VALUES//
////////////////
let $twConfigHash;
let $twConfig;
function getTwConfigCache(twConfigPath) {
const twConfigHash = getTwConfigHash(twConfigPath);
if ($twConfigHash !== twConfigHash) {
$twConfigHash = getTwConfigHash(twConfigPath);
$twConfig = getTwConfig(twConfigPath);
return {
hash: $twConfigHash,
isNewTwConfig: true,
twConfig: $twConfig
};
}
return {
hash: $twConfigHash,
isNewTwConfig: false,
twConfig: $twConfig
};
}
exports.getTwConfigCache = getTwConfigCache;