From 36be3f718aa61c9413306599af9c158b0629cb7f Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Mon, 3 Apr 2017 18:21:30 +0200 Subject: [PATCH 1/2] fix: /site/ get remove & created when assets file are inside root folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if assets files inside index_files are not in sub folder, comparedir compare /index_files/ & /site/ which will be différentes (ex: html files published ...) then everything inside /site/ will be erased and created again with content of /index_files/ --- package.json | 1 + src/cli/cms/templates/assets.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e393597..50780a24 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "express-secure-handlebars": "^2.1.0", "express-session": "^1.13.0", "extend": "^3.0.0", + "fs-compare": "0.0.4", "fs-extra": "^2.0.0", "handlebars": "^4.0.3", "handlebars-helper-slugify": "^0.3.2", diff --git a/src/cli/cms/templates/assets.js b/src/cli/cms/templates/assets.js index c54262a0..e8ed259f 100644 --- a/src/cli/cms/templates/assets.js +++ b/src/cli/cms/templates/assets.js @@ -1,4 +1,5 @@ import fse from 'fs-extra' +import fsCompare from 'fs-compare' import dircompare from 'dir-compare' import mkdirp from 'mkdirp' import path from 'path' @@ -47,7 +48,25 @@ export function copy() { var basePath = original.replace(publicFolder, '') var move = path.join(dest, basePath) - if(entry.type2 === 'missing' || entry.state === 'distinct') { + if(move === dest){ + fse.readdir(original, function (res, items) { + Array.prototype.forEach.call(items, (item) => { + var lstat = fse.lstatSync(path.join(original, item)) + var originalItem = path.join(original, item) + var destItem = path.join(dest, item) + if (!lstat.isDirectory()) { + try { + fsCompare(modifiedTime, originalItem, destItem, function (err, diff) { + if(diff > 0) fse.copySync(originalItem, destItem) + }) + } catch (e) { + fse.copySync(originalItem, destItem) + } + } + }) + }) + } + else if(entry.type2 === 'missing' || entry.state === 'distinct') { fse.removeSync(move) fse.copySync(original, move) } @@ -59,6 +78,15 @@ export function copy() { return publicFolders } +function modifiedTime(fileName, cb) { + fse.stat(fileName, function (err, stat) { + if (err) { + return cb(err); + } + return cb(null, stat.mtime); + }); +} + export function getFolders() { const templateExtension = '.' + config.files.templates.extension const assetsExtension = config.files.templates.assets From 275bfd5c1d1b7a7f16025f111576651c0e8bf336 Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Mon, 3 Apr 2017 18:24:07 +0200 Subject: [PATCH 2/2] fix: /site/ get remove & created when assets file are inside root folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if assets files inside index_files are not in sub folder, comparedir compare /index_files/ & /site/ which will be différentes (ex: html files published ...) then everything inside /site/ will be erased and created again with content of /index_files/ --- package.json | 1 + src/cli/cms/templates/assets.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e393597..50780a24 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "express-secure-handlebars": "^2.1.0", "express-session": "^1.13.0", "extend": "^3.0.0", + "fs-compare": "0.0.4", "fs-extra": "^2.0.0", "handlebars": "^4.0.3", "handlebars-helper-slugify": "^0.3.2", diff --git a/src/cli/cms/templates/assets.js b/src/cli/cms/templates/assets.js index c54262a0..e8ed259f 100644 --- a/src/cli/cms/templates/assets.js +++ b/src/cli/cms/templates/assets.js @@ -1,4 +1,5 @@ import fse from 'fs-extra' +import fsCompare from 'fs-compare' import dircompare from 'dir-compare' import mkdirp from 'mkdirp' import path from 'path' @@ -47,7 +48,25 @@ export function copy() { var basePath = original.replace(publicFolder, '') var move = path.join(dest, basePath) - if(entry.type2 === 'missing' || entry.state === 'distinct') { + if(move === dest){ + fse.readdir(original, function (res, items) { + Array.prototype.forEach.call(items, (item) => { + var lstat = fse.lstatSync(path.join(original, item)) + var originalItem = path.join(original, item) + var destItem = path.join(dest, item) + if (!lstat.isDirectory()) { + try { + fsCompare(modifiedTime, originalItem, destItem, function (err, diff) { + if(diff > 0) fse.copySync(originalItem, destItem) + }) + } catch (e) { + fse.copySync(originalItem, destItem) + } + } + }) + }) + } + else if(entry.type2 === 'missing' || entry.state === 'distinct') { fse.removeSync(move) fse.copySync(original, move) } @@ -59,6 +78,15 @@ export function copy() { return publicFolders } +function modifiedTime(fileName, cb) { + fse.stat(fileName, function (err, stat) { + if (err) { + return cb(err); + } + return cb(null, stat.mtime); + }); +} + export function getFolders() { const templateExtension = '.' + config.files.templates.extension const assetsExtension = config.files.templates.assets