Skip to content

Commit

Permalink
Merge branch 'v.0.40'
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed Jul 7, 2022
2 parents 90476f0 + b13dc47 commit f3dbf1e
Show file tree
Hide file tree
Showing 96 changed files with 5,152 additions and 2,384 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Publii](https://getpublii.com/) is a desktop-based CMS for Windows, Mac and Linux that makes creating static websites fast
and hassle-free, even for beginners.

**Current version: 0.39.1 (build 15483)**
**Current version: 0.40 (build 15728)**

## Why Publii?
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an
Expand Down
3 changes: 2 additions & 1 deletion app/back-end/app-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
'app-site-plugin-activate',
'app-site-plugin-deactivate',
'app-site-get-plugin-config',
'app-site-save-plugin-config'
'app-site-save-plugin-config',
'app-close'
];

if (validChannels.includes(channel)) {
Expand Down
25 changes: 0 additions & 25 deletions app/back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,31 +648,6 @@ class App {
});
}

this.mainWindow.on('close', async function(e) {
let currentWindowURL = e.sender.webContents.getURL();

if (
currentWindowURL.indexOf('/posts/editor/blockeditor/') === -1 &&
currentWindowURL.indexOf('/posts/editor/markdown/') === -1 &&
currentWindowURL.indexOf('/posts/editor/tinymce/') === -1
) {
return;
}

let messageText = await e.sender.webContents.mainFrame.top.executeJavaScript('window.app.translate("core.sureYouWantQuit")');

const choice = dialog.showMessageBoxSync(this, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: messageText
});

if (choice === 1) {
e.preventDefault();
}
});

// Create context menu
const ContextMenuBuilder = require('./helpers/context-menu-builder.js');
let contextMenuBuilder = new ContextMenuBuilder(this.mainWindow.webContents);
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/builddata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.39.1","build":15487}
{"version":"0.40.0","build":15728}
7 changes: 7 additions & 0 deletions app/back-end/events/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const unzip = require("unzipper");

class AppEvents {
constructor(appInstance) {
/*
* Close app
*/
ipcMain.on('app-close', function(event, config) {
appInstance.app.quit();
});

/*
* Save licence acceptance
*/
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/events/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DeployEvents {

if (data.result && data.result[0] && data.result[0].message) {
errorTitle = {
translation: 'core.rendering.renderingProcessFiled'
translation: 'core.rendering.renderingProcessFailed'
};
errorDesc = data.result[0].message + "\n\n" + data.result[0].desc;
}
Expand Down
17 changes: 4 additions & 13 deletions app/back-end/events/file-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const path = require('path');
const ipcMain = require('electron').ipcMain;
const isBinaryFile = require('isbinaryfile');
const isBinaryFileSync = require('isbinaryfile').isBinaryFileSync;

/*
* Events for the IPC communication regarding file manager
Expand Down Expand Up @@ -99,23 +99,14 @@ class FileManagerEvents {
* @param sender
*/
checkIfIsBinaryFile(output, iterator, sender) {
let self = this;

if(!output.length || iterator >= output.length) {
sender.send('app-file-manager-listed', output);
return;
}

isBinaryFile(output[iterator].fullPath, function(err, result) {
if(err) {
output[iterator].isBinary = false;
} else {
output[iterator].isBinary = result;
}

iterator++;
self.checkIfIsBinaryFile(output, iterator, sender);
});
output[iterator].isBinary = isBinaryFileSync(output[iterator].fullPath)
iterator++;
this.checkIfIsBinaryFile(output, iterator, sender);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/back-end/events/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PreviewEvents {

if (data && data.result && data.result[0] && data.result[0].message) {
errorTitle = {
translation: 'core.rendering.renderingProcessFiled'
translation: 'core.rendering.renderingProcessFailed'
};
errorDesc = data.result[0].message + "\n\n" + data.result[0].desc;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ class PreviewEvents {

if (data.result && data.result[0] && data.result[0].message) {
errorTitle = {
translation: 'core.rendering.renderingProcessFiled'
translation: 'core.rendering.renderingProcessFailed'
};
errorDesc = data.result[0].message + "\n\n" + data.result[0].desc;
}
Expand Down
85 changes: 49 additions & 36 deletions app/back-end/modules/deploy/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('fs-extra');
const path = require('path');
const md5 = require('md5');
const normalizePath = require('normalize-path');
const isBinaryFileSync = require('isbinaryfile').isBinaryFileSync;
const slug = require('./../../helpers/slug');
const FTP = require('./ftp.js');
const SFTP = require('./sftp.js');
Expand Down Expand Up @@ -128,7 +129,7 @@ class Deployment {
fileList.push({
path: filePath,
type: 'file',
md5: fs.readFileSync(path.join(this.inputDir, filePath))
md5: md5(fs.readFileSync(path.join(this.inputDir, filePath)))
});
}

Expand Down Expand Up @@ -158,7 +159,7 @@ class Deployment {
// Put file
let fileMD5 = false;

if(this.fileIsAnImage(filePath)) {
if (isBinaryFileSync(path.join(this.inputDir, filePath))) {
let stats = fs.statSync(path.join(this.inputDir, filePath));
fileMD5 = md5(stats.size);
} else {
Expand All @@ -180,6 +181,47 @@ class Deployment {
);
}

/**
* Check if local list is equal to the server expected copy
*
* @param fileContent
*/
checkLocalListWithRemoteList (fileContent) {
try {
if (typeof fileContent === 'Buffer') {
fileContent = fileContent.toString();
}

let content = JSON.parse(fileContent);

if (content.revision) {
let filesToCheck = fs.readFileSync(path.join(this.configDir, 'files-remote.json'));
let checkSum = md5(filesToCheck);
let isExpectedCopy = checkSum === content.revision;
this.compareFilesList(isExpectedCopy);
return;
}

fs.writeFileSync(path.join(this.configDir, 'files-remote.json'), fileContent);
this.compareFilesList(true);
} catch (e) {
this.compareFilesList(false);
}
}

/**
* Save files.publii.json as files-remote.json and store checksum in the file
*/
replaceSyncInfoFiles () {
let inputListPath = path.join(this.inputDir, 'files.publii.json');
let remoteListPath = path.join(this.configDir, 'files-remote.json');
let contentToSave = fs.readFileSync(inputListPath);
let checkSum = md5(contentToSave);
let newContent = `{ "revision": "${checkSum}" }`;
fs.writeFileSync(remoteListPath, contentToSave);
fs.writeFileSync(inputListPath, newContent);
}

/**
* Compares remote and local files lists
*
Expand All @@ -202,12 +244,6 @@ class Deployment {

if (this.siteConfig.deployment.protocol === 'gitlab-pages') {
remoteFiles = remoteFiles.map(file => {
file.path = file.path.substr(7);

if (file.path.indexOf('/') > -1) {
file.path = '/' + file.path;
}

return file;
});
}
Expand Down Expand Up @@ -326,21 +362,21 @@ class Deployment {
return 0;
});

this.filesToUpload = this.filesToUpload.sort(function(fileA, fileB) {
if(fileA.type === 'directory') {
this.filesToUpload = this.filesToUpload.sort((fileA, fileB) => {
if (fileA.type === 'directory') {
return 1;
}

if(fileB.type === 'directory') {
if (fileB.type === 'directory') {
return -1;
}

// Images will be uploaded at the end
if(self.fileIsAnImage(fileA.path)) {
if (isBinaryFileSync(path.join(this.inputDir, fileA.path))) {
return -1;
}

if(self.fileIsAnImage(fileB.path)) {
if (isBinaryFileSync(path.join(this.inputDir, fileB.path))) {
return 1;
}

Expand Down Expand Up @@ -447,29 +483,6 @@ class Deployment {
}
}

/**
* Detects images by filename
*
* @param filename
* @returns {boolean}
*/
fileIsAnImage(filename) {
if(
filename.substr(-4).toLowerCase() === '.jpg' ||
filename.substr(-5).toLowerCase() === '.jpeg' ||
filename.substr(-4).toLowerCase() === '.png' ||
filename.substr(-4).toLowerCase() === '.svg' ||
filename.substr(-4).toLowerCase() === '.gif' ||
filename.substr(-4).toLowerCase() === '.bmp' ||
filename.substr(-5).toLowerCase() === '.webp' ||
filename.substr(-4).toLowerCase() === '.ico'
) {
return true;
}

return false;
}

/**
* Function used to get recursive list of the files and directories
* in the specific dir
Expand Down
18 changes: 11 additions & 7 deletions app/back-end/modules/deploy/ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ class FTP {

this.connection.get(
normalizePath(path.join(this.deployment.outputDir, 'files.publii.json')),
function(err, stream) {
let fileStream;

function(err, fileStream) {
console.log(`[${ new Date().toUTCString() }] <- files.publii.json`);

process.send({
Expand All @@ -171,11 +169,15 @@ class FTP {
});

if (!err) {
fileStream = fs.createWriteStream(path.join(self.deployment.configDir, 'files-remote.json'));
stream.pipe(fileStream);
let fileStreamChunks = [];

fileStream.on('data', (chunk) => {
fileStreamChunks.push(chunk.toString());
});

stream.on('end', function() {
self.deployment.compareFilesList(true);
fileStream.on('end', () => {
let completeFile = fileStreamChunks.join('');
self.deployment.checkLocalListWithRemoteList(completeFile);
});
} else {
console.log(`[${ new Date().toUTCString() }] (!) ERROR WHILE DOWNLOADING files-remote.json`);
Expand All @@ -198,6 +200,8 @@ class FTP {
}
});

this.deployment.replaceSyncInfoFiles();

this.connection.put(
normalizePath(path.join(this.deployment.inputDir, 'files.publii.json')),
normalizePath(path.join(this.deployment.outputDir, 'files.publii.json')),
Expand Down
Loading

0 comments on commit f3dbf1e

Please sign in to comment.