Skip to content

Commit

Permalink
Fix the build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko committed Apr 4, 2024
1 parent 6de1680 commit de6334c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions build/build-modules-js/css-versioning.es6.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { createHash } = require('node:crypto');
const { readdir, readFile, writeFile } = require('fs/promises');
const { readdir, readFile, writeFile } = require('node:fs/promises');
const { existsSync, readFileSync } = require('node:fs');
const { dirname, extname, resolve } = require('node:path');
const { transform, composeVisitors } = require('lightningcss');
const { Timer } = require('./utils/timer.es6.js');

const RootPath = process.cwd();
const skipExternal = true;
const variable = 'v';

Expand Down Expand Up @@ -55,14 +56,19 @@ function urlVersioning(fromFile) {
* @returns {Promise<void>}
*/
const fixVersion = async (file) => {
const cssString = await readFile(file);
const options = {
code: cssString,
minify: file.endsWith('.min.css'),
visitor: composeVisitors([urlVersioning(file)]),
};

try {
const cssString = await readFile(file);
const { code } = transform({
code: cssString,
minify: false,
visitor: composeVisitors([urlVersioning(file)]),
const { code } = transform(options);
await writeFile(file, `@charset "UTF-8";${file.endsWith(".min.css") ? '' : '\n'}${code}`, {
encoding: "utf8",
mode: 0o644,
});
await writeFile(file, code, { encoding: 'utf8', mode: 0o644 });
} catch (error) {
throw new Error(error);
}
Expand All @@ -76,7 +82,7 @@ const fixVersion = async (file) => {
module.exports.cssVersioning = async () => {
const bench = new Timer('Versioning');

const cssFiles = (await readdir('media', { withFileTypes: true, recursive: true }))
const cssFiles = (await readdir(`${RootPath}/media`, { withFileTypes: true, recursive: true }))
.filter((file) => (!file.isDirectory() && extname(file.name) === '.css'))
.map((file) => `${file.path}/${file.name}`);

Expand Down

0 comments on commit de6334c

Please sign in to comment.