foundry-dsa41-game/node_modules/sass-build/dist/utils.js

284 lines
8.6 KiB
JavaScript

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
CWD: () => CWD,
exit: () => exit,
fileExists: () => fileExists,
getPostcss: () => getPostcss,
isArray: () => isArray,
isString: () => isString,
logger: () => logger,
objectTag: () => objectTag,
objectType: () => objectType,
padCwd: () => padCwd,
parsePath: () => parsePath,
replacePathVariables: () => replacePathVariables,
requireUserFile: () => requireUserFile,
trimCwd: () => trimCwd,
writeFile: () => writeFile
});
module.exports = __toCommonJS(utils_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_crypto = __toESM(require("crypto"));
var import_mime_types = __toESM(require("mime-types"));
var import_lodash = __toESM(require("lodash"));
var import_logger = require("./logger");
const toString = Object.prototype.toString;
const REGEX_REPLACER_TEMPLATE = /\[([\w]+)(?::([\w:\\.-]+))?\]/gi;
function requireUserFile(file) {
return require(import_path.default.resolve(CWD, file));
}
function exit(code, level, prefix, message, ...args) {
if (level !== void 0) {
logger[level](prefix, message, ...args);
}
process.exit(code);
}
function isString(value) {
return typeof value === "string";
}
function isArray(value) {
return Array.isArray(value);
}
function objectType(obj) {
if (obj === void 0) {
return "undefined";
}
if (obj === null) {
return "null";
}
if (Number.isNaN(obj)) {
return "NaN";
}
return obj.__proto__.constructor.name.toLowerCase();
}
function objectTag(obj) {
if (obj === void 0) {
return "[object Undefined]";
}
if (obj === null) {
return "[object Null]";
}
if (Number.isNaN(obj)) {
return "[object NaN]";
}
return toString.call(obj);
}
function fileExists(file) {
return import_fs.default.existsSync(file);
}
function writeFile(file, content) {
import_fs.default.mkdirSync(import_path.default.dirname(file), { recursive: true });
import_fs.default.writeFileSync(file, content, "utf-8");
}
const logger = new import_logger.Logger();
const CWD = process.cwd();
function trimCwd(cwd, filePath) {
if (import_path.default.isAbsolute(filePath) && !filePath.startsWith(cwd)) {
return filePath;
}
return import_path.default.relative(cwd, filePath);
}
function padCwd(cwd, filePath) {
if (import_path.default.isAbsolute(filePath) && !filePath.startsWith(cwd)) {
return filePath;
}
return import_path.default.resolve(cwd, filePath);
}
const stubPostcssProcessor = {
process: function(css) {
return { css };
}
};
function getPostcss(options) {
const pkgName = "postcss";
if (options === void 0 || options === false) {
return stubPostcssProcessor;
}
const postcss = require(pkgName);
if (options === "auto") {
if (import_fs.default.existsSync("postcss.config.js")) {
const plugins = requireUserFile("postcss.config.js").plugins;
return postcss(plugins);
}
}
if (isArray(options)) {
return postcss(options);
}
return postcss();
}
function replacer(value, allowEmpty) {
function fn(match, input) {
if (import_lodash.default.isFunction(value)) {
value = value();
}
if (import_lodash.default.isNil(value)) {
if (!allowEmpty) {
throw new Error(
`Variable ${match} not implemented in this context: ${input}`
);
}
return "";
}
return `${value}`;
}
return fn;
}
function getHash(content) {
const hash = import_crypto.default.createHash("sha256");
hash.update(content);
return hash.digest("hex");
}
const resultFilters = /* @__PURE__ */ new Map();
resultFilters.set("toLower", function(str) {
return str.toLowerCase();
});
resultFilters.set("toUpper", function(str) {
return str.toUpperCase();
});
function parsePath(filePath) {
filePath = import_path.default.posix.normalize(filePath);
const pathData = {};
const parsedPath = import_path.default.posix.parse(filePath);
pathData.fullPath = filePath;
pathData.path = parsedPath.dir;
pathData.base = parsedPath.base;
pathData.name = parsedPath.name;
pathData.ext = parsedPath.ext;
if (import_fs.default.existsSync(filePath)) {
pathData.exists = true;
const stats = import_fs.default.statSync(filePath);
pathData.size = stats.size;
pathData.created = stats.birthtime;
pathData.accessed = stats.atime;
pathData.modified = stats.mtime;
pathData.changed = stats.ctime;
if (stats.isFile() === true) {
pathData.mime = import_mime_types.default.lookup(pathData.ext);
pathData.contentHash = getHash(filePath);
}
} else {
pathData.exists = false;
}
return pathData;
}
function replacePathVariables(template, filePath) {
const replacements = /* @__PURE__ */ new Map();
let result = template;
let pathData = filePath;
if (filePath) {
if (isString(filePath)) {
pathData = parsePath(filePath);
}
replacements.set("fullPath", replacer(pathData.fullPath));
replacements.set("path", replacer(pathData.path, true));
replacements.set("base", replacer(pathData.base));
replacements.set("name", replacer(pathData.name));
replacements.set("ext", replacer(pathData.ext, true));
replacements.set("size", replacer(pathData.size, true));
replacements.set("created", replacer(pathData.created?.getTime(), true));
replacements.set("accessed", replacer(pathData.accessed?.getTime(), true));
replacements.set("changed", replacer(pathData.changed?.getTime(), true));
replacements.set("modified", replacer(pathData.modified?.getTime(), true));
replacements.set("mime", replacer(pathData.mime, true));
replacements.set("contentHash", replacer(pathData.contentHash, true));
}
if (import_lodash.default.isFunction(template)) {
result = template(filePath);
}
result = result.replace(REGEX_REPLACER_TEMPLATE, (match, key, filters) => {
const replacer2 = replacements.get(key);
let replaced;
filters = filters === void 0 ? [] : filters.split(":");
if (replacer2 !== void 0) {
replaced = replacer2(key, result);
filters.forEach((filter) => {
if (filter === ".." || filter === "") {
return;
}
if (resultFilters.has(filter)) {
const filterFn = resultFilters.get(filter);
replaced = filterFn(replaced);
return;
}
if (/[a-zA-z]|[^\d\-\\.]/.test(filter)) {
return;
}
const tuple = filter.split("..", 2);
if (tuple.length === 2) {
let startIndex = parseInt(tuple[0]);
let endIndex = parseInt(tuple[1]);
if (Number.isNaN(startIndex)) {
startIndex = 0;
}
if (Number.isNaN(endIndex)) {
endIndex = Infinity;
}
if (startIndex > 0) {
startIndex = startIndex - 1;
}
if (endIndex < 0 && startIndex < 0) {
endIndex = endIndex + 1;
if (endIndex === 0) {
endIndex = Infinity;
}
}
replaced = replaced.slice(startIndex, endIndex);
return;
}
const index = parseInt(tuple[0]);
if (index < 0) {
replaced = replaced.slice(index);
return;
}
replaced = replaced.slice(0, index);
return;
});
return replaced;
}
return match;
});
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CWD,
exit,
fileExists,
getPostcss,
isArray,
isString,
logger,
objectTag,
objectType,
padCwd,
parsePath,
replacePathVariables,
requireUserFile,
trimCwd,
writeFile
});