Skip to content

Commit

Permalink
fix(serve): image compression will run only in the files added/remove…
Browse files Browse the repository at this point in the history
…d and not all
  • Loading branch information
gerard2perez committed May 6, 2017
1 parent 9745311 commit 2f7c949
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CheckBundles from '../support/CheckBundles';
import WatchFileToCopy from '../support/WatchFileToCopy';
import CopyStatic from '../support/CopyStatic';
import deamon from '../deamon';
import imagecompressor from '../functions/imagecompressor';
import { imagecompressor, buildAllImages } from '../functions/imagecompressor';
import { postBuildEmber, preBuildEmber } from '../functions/emberBuilder';

let watching = [],
Expand All @@ -26,6 +26,7 @@ const deleted = function (file) {
livereload.reload(file);
},
compress = function (file) {
console.log(file);
imagecompressor([file], file.replace(path.basename(file), '').replace('assets', 'public')).then(() => {
livereload.reload(file);
});
Expand All @@ -45,7 +46,7 @@ const deleted = function (file) {
.on('change', compress)
.on('unlink', deleted)
.on('add', compress);
return imagecompressor();
return buildAllImages();
},
serveEmber = function (app, cfg, index) {
return Promise.promisify((...args) => {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default (new Command(__filename, 'Translate your localization files'))
}
let translation = fs.readJSONSync(ProyPath(configuration.server.localization.directory, `${from}.js`));
let newLang = {};
for (const key of Object.keys(translation)) {
let keys = Object.keys(translation);
for (const key of keys) {
newLang[key] = await translate(translation[key], from, to);
}
fs.writeFileSync(ProyPath(configuration.server.localization.directory, `${to}.js`), JSON.stringify(newLang, 4, 4));
Expand Down
7 changes: 4 additions & 3 deletions src/functions/imagecompressor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { sync as glob } from 'glob';
import spin from '../spinner';
import {join} from 'path';

function compressImages (files, dest) {
export function imagecompressor (files, dest) {
console.log(files);
const imagemin = require('imagemin'),
imageminMozjpeg = require('imagemin-mozjpeg'),
imageminPngquant = require('imagemin-pngquant');
Expand All @@ -17,13 +18,13 @@ function compressImages (files, dest) {
}).then((files) => files.length);
}

export default function buildImages () {
export function buildAllImages () {
const spinner = spin();
spinner.start(50, 'Compressing Images', undefined, process.stdout.columns);
let subforlders = glob(ProyPath('assets', 'img', '**', '/')); // .map((f) => path.join(f, '*.{jpg,png}'));
let all = [0];
for (const folder of subforlders) {
all.push(compressImages([join(folder, '*.{jpg,png}')], join('public', folder.replace(ProyPath('assets'), ''))));
all.push(imagecompressor([join(folder, '*.{jpg,png}')], join('public', folder.replace(ProyPath('assets'), ''))));
}
return Promise.all(all).then((res) => {
spinner.end(` ${__ok.green} (${res.reduce((a, b) => a + b)}) Images Compressed`);
Expand Down

0 comments on commit 2f7c949

Please sign in to comment.