110 lines
4.0 KiB
JavaScript
110 lines
4.0 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 base_sass_compiler_exports = {};
|
|
__export(base_sass_compiler_exports, {
|
|
BaseSassCompiler: () => BaseSassCompiler
|
|
});
|
|
module.exports = __toCommonJS(base_sass_compiler_exports);
|
|
var import_path = __toESM(require("path"));
|
|
var import_glob = __toESM(require("glob"));
|
|
var import_lodash = __toESM(require("lodash"));
|
|
var import_utils = require("../utils");
|
|
class BaseSassCompiler {
|
|
constructor(options) {
|
|
this.options = options;
|
|
this.compiler = this.options.compiler;
|
|
this.postcss = this.options.postcss;
|
|
}
|
|
before() {
|
|
const importers = this.options.sassOptions?.importers || [];
|
|
importers.forEach((importer) => {
|
|
if (import_lodash.default.isFunction(importer.before)) {
|
|
importer.before({ cwd: this.options.cwd });
|
|
}
|
|
});
|
|
}
|
|
build(file, outFile, sassOptions) {
|
|
const _cwd = this.options.cwd;
|
|
if (import_path.default.isAbsolute(file) === false) {
|
|
file = (0, import_utils.padCwd)(_cwd, file);
|
|
}
|
|
if (import_path.default.isAbsolute(outFile) === false) {
|
|
outFile = (0, import_utils.padCwd)(_cwd, outFile);
|
|
}
|
|
import_utils.logger.info(
|
|
"build",
|
|
"%s => %s",
|
|
(0, import_utils.trimCwd)(import_utils.CWD, file),
|
|
(0, import_utils.trimCwd)(import_utils.CWD, outFile)
|
|
);
|
|
import_utils.logger.subdue("warn");
|
|
const result = this.compile(file, sassOptions);
|
|
(0, import_utils.writeFile)(outFile, result);
|
|
import_utils.logger.awaken();
|
|
}
|
|
buildFiles(files, output, sassOptions) {
|
|
const _cwd = this.options.cwd;
|
|
if ((0, import_utils.isString)(files)) {
|
|
import_utils.logger.warn("buildFiles", "Prefer string[] for files option");
|
|
files = [files];
|
|
}
|
|
output = import_lodash.default.defaults({}, output, { path: "dist", filename: "[name].css" });
|
|
if (import_path.default.isAbsolute(output.path) === false) {
|
|
output.path = (0, import_utils.padCwd)(_cwd, output.path);
|
|
}
|
|
files.forEach((fileOrGlob) => {
|
|
if (import_path.default.isAbsolute(fileOrGlob) === false) {
|
|
fileOrGlob = (0, import_utils.padCwd)(_cwd, fileOrGlob);
|
|
}
|
|
fileOrGlob = fileOrGlob.split(import_path.default.sep).join(import_path.default.posix.sep);
|
|
import_glob.default.sync(fileOrGlob).forEach((file) => {
|
|
const outFile = import_path.default.resolve(
|
|
output.path,
|
|
(0, import_utils.replacePathVariables)(output.filename, file)
|
|
);
|
|
this.build(file, outFile, sassOptions);
|
|
});
|
|
});
|
|
}
|
|
buildString(source, outFile, options) {
|
|
import_utils.logger.info(
|
|
"buildString",
|
|
"%s => %s",
|
|
"data",
|
|
(0, import_utils.trimCwd)(import_utils.CWD, outFile)
|
|
);
|
|
import_utils.logger.subdue("warn");
|
|
const result = this.compileString(source, options);
|
|
import_utils.logger.awaken();
|
|
(0, import_utils.writeFile)(outFile, result);
|
|
}
|
|
get info() {
|
|
return this.compiler.info;
|
|
}
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
BaseSassCompiler
|
|
});
|