Skip to content

Commit

Permalink
Fixed image issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rsefer committed Apr 30, 2024
1 parent 86767b0 commit 1d6ebd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import project from './lib/project.js';
import parseArgs from 'minimist';
const argv = parseArgs(process.argv.slice(2));
import chokidar from 'chokidar';
import { glob } from 'glob';
import { glob, globSync } from 'glob';

import bustCache from './lib/bustCache.js';
import { buildSass, buildSassTheme } from './lib/style.js';
Expand All @@ -22,28 +22,30 @@ let chokidarOpts = {
};

let sassGlobPath = project.package?.sdc?.sassGlobPath || project.path + '{/_src/style,/blocks}/**/*.scss';
let sassGlob = glob.sync(sassGlobPath, {
let sassGlob = globSync(sassGlobPath, {
ignore: [
project.path + '/_src/style/partials/_theme.scss'
]
});
let jsGlobPath = project.package?.sdc?.jsGlobPath || project.path + '/_src/scripts/**/*.js';
let jsGlob = glob.sync(jsGlobPath, {
let jsGlob = globSync(jsGlobPath, {
ignore: []
});
let blockGlobPath = project.package?.sdc?.blockGlobPath || project.path + '/blocks/*';
let blockGlob = glob.sync(blockGlobPath);
let blockGlob = globSync(blockGlobPath);

function bustFunctionsCache() {
bustCache(project.path + '/functions.php');
}

function frontrunImages() {
[project.path + '/_src/images/', project.path + '/_src/images/**/*/'].forEach((block) => {
glob(block, {}, function(err, directory) {
directory.forEach((dir) => {
buildImages(dir);
});
[
project.path + '/_src/images/',
project.path + '/_src/images/**/*/'
].forEach((block) => {
const imageDirectories = globSync(block);
imageDirectories.forEach((dir) => {
buildImages(dir);
});
});
}
Expand All @@ -55,7 +57,7 @@ for (const [name, files] of Object.entries(project.package.sdc.entries)) {
entries[name].push(project.path + file);
});
}
let sassBlocksGlob = glob.sync(project.path + '/blocks/*/*.scss');
let sassBlocksGlob = globSync(project.path + '/blocks/*/*.scss');
for (var filename of sassBlocksGlob) {
entries[`blocks/${path.basename(path.dirname(filename))}/style`] = [ filename ];
}
Expand Down
7 changes: 4 additions & 3 deletions lib/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import imageminSvgo from 'imagemin-svgo';

const buildImages = async (images) => {
let timerStart = Date.now();
const files = await imagemin([images + '*'], {
destination: project.path + '/dist/images/' + (images.replace(project.path + '/_src/images/', '')),
let dest = images.replace('_src/images', 'dist/images');
const files = await imagemin([images + '/*'], {
destination: dest,
plugins: [
imageminJpegtran(),
imageminPngquant(),
imageminSvgo()
]
});
log('success', `Built /dist/images/${images.replace(project.path + '/_src/images/', '')} in ${Date.now() - timerStart}ms`);
log('success', `Built ${dest.replace(project.path, '')} (${files.length} image${files.length == 1 ? '' : 's'}) in ${Date.now() - timerStart}ms`);
};

export default buildImages;

0 comments on commit 1d6ebd6

Please sign in to comment.