Skip to content

Commit

Permalink
Add default destination path for sass.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrypt committed Jan 8, 2025
1 parent 4f71a9b commit 52c1b2b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions .scripts/assets-build-tool/sass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as sass from "sass";

let action = process.argv[2];
const config = JSON5.parse(Buffer.from(process.argv[3], "base64").toString("utf-8"));
const dest = config.dest ?? config.basePath + "wwwroot/Styles/";

if (config.dryRun) {
action = "dry-run";
Expand All @@ -21,17 +22,17 @@ glob(config.source).then((files) => {
return;
}

const destExists = fs.existsSync(config.dest);
const destExists = fs.existsSync(dest);

if (destExists) {
const stats = fs.lstatSync(config.dest);
const stats = fs.lstatSync(dest);
if (!stats.isDirectory()) {
console.log(chalk.red("Destination is not a directory"));
console.log("Files:", files);
console.log("Destination:", config.dest);
console.log("Destination:", dest);
return;
}
console.log(chalk.yellow(`Destination ${config.dest} already exists, files may be overwritten`));
console.log(chalk.yellow(`Destination ${dest} already exists, files may be overwritten`));
}

let baseFolder;
Expand All @@ -50,7 +51,7 @@ glob(config.source).then((files) => {
relativePath = path.basename(file);
}

const target = path.join(config.dest, relativePath);
const target = path.join(dest, relativePath);

if (action === "dry-run") {
console.log(`Dry run (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(target));
Expand All @@ -63,7 +64,7 @@ glob(config.source).then((files) => {
const cssResult = await sass.compileAsync(file);

if (cssResult) {
const normalTarget = path.join(config.dest, path.parse(target).name + ".css");
const normalTarget = path.join(dest, path.parse(target).name + ".css");
fs.outputFile(normalTarget, cssResult.css);
console.log(`Tranpiled (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(normalTarget));

Expand All @@ -75,13 +76,13 @@ glob(config.source).then((files) => {
});

if (code) {
const minifiedTarget = path.join(config.dest, path.parse(target).name + ".min.css");
const minifiedTarget = path.join(dest, path.parse(target).name + ".min.css");
fs.outputFile(minifiedTarget, code);
console.log(`Minified (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(minifiedTarget));
}

if (map) {
const mappedTarget = path.join(config.dest, path.parse(target).name + ".css.map");
const mappedTarget = path.join(dest, path.parse(target).name + ".css.map");
fs.outputFile(mappedTarget, map);
console.log(`Mapped (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(mappedTarget));
}
Expand Down

0 comments on commit 52c1b2b

Please sign in to comment.